bool Goomba::isTherePlayer() { if(horizontalMove()){ if(startToEnd){ if(positionY< player->getPositionY() && positionY+RANGEM>=player->getPositionY() && ((positionX< player->getPositionX() && positionX+RANGEm>=player->getPositionX()) || (positionX> player->getPositionX() && positionX-RANGEm<=player->getPositionX()))) return true; } else{ if(positionY>player->getPositionY() && positionY-RANGEM<=player->getPositionY() && ((positionX< player->getPositionX() && positionX+RANGEm>=player->getPositionX()) || (positionX> player->getPositionX() && positionX-RANGEm<=player->getPositionX()))) return true; } } else if(startToEnd){ if(positionX< player->getPositionX() && positionX+RANGEM>=player->getPositionX() && ((positionY< player->getPositionY() && positionY+RANGEm>=player->getPositionY()) || (positionY> player->getPositionY() && positionY-RANGEm<=player->getPositionY()))) return true; } else{ if(positionX>player->getPositionX() && positionX-RANGEM<=player->getPositionX() && ((positionY< player->getPositionY() && positionY+RANGEm>=player->getPositionY()) || (positionY> player->getPositionY() && positionY-RANGEm<=player->getPositionY()))) return true;} return false; }
Goomba::Goomba(GLfloat xStart, GLfloat yStart, GLfloat xEnd, GLfloat yEnd, GLuint modelList,Player* player,Maze* maze) { this->xStart=xStart; this->yStart=yStart; this->xEnd=xEnd; this->yEnd=yEnd; this->modelList=modelList; this->player=player; this->maze = maze; positionX=xStart; positionY=yStart; positionZ=zDeath=0; timeStopToSee=0; setSize(1.5,1.5,1.5); hitByFireball=false; startToEnd=true; followPlayer=false; returnToRoute=false; stopToSee=false; if(horizontalMove()) angleRotation=180; else angleRotation=90; }
bool Goomba::farToRoute(){ if(horizontalMove()){ if(positionX<xStart+MAX_DISTANCE_ROUTE && positionX>xStart-MAX_DISTANCE_ROUTE) return false; }else{ if(positionY<yStart+MAX_DISTANCE_ROUTE && positionY>yStart-MAX_DISTANCE_ROUTE) return false; } return true; }
void Goomba::reset() { positionX=xStart; positionY=yStart; positionZ=zDeath=0; startToEnd=true; followPlayer=false; hitByFireball=false; if(horizontalMove()) angleRotation=180; else angleRotation=90; }
void DArrowRectangle::move(int x, int y) { switch (m_arrowDirection) { case ArrowLeft: case ArrowRight: verticalMove(x, y); break; case ArrowTop: case ArrowBottom: horizontalMove(x, y); break; default: QWidget::move(x, y); break; } }
void Goomba:: move() { if(isTherePlayer()){ if(!stopToSee && !followPlayer){ MediaPlayerManager::playGoombaWhat(); stopToSee=true; } followPlayer=true; }else{ if(followPlayer){ returnToRoute=true; } followPlayer=false; } if(farToRoute()){ followPlayer=false; returnToRoute=true; } if(followPlayer && !returnToRoute && !hitByFireball &&!stopToSee){ if(!collideWall( positionX+((player->getPositionX()-positionX)/30),positionY+(player->getPositionY()-positionY)/30)) { setAngleRotation(player->getPositionX(),player->getPositionY()); positionX+=(player->getPositionX()-positionX)/30; positionY+=(player->getPositionY()-positionY)/30; } }else if(returnToRoute && !hitByFireball &&!stopToSee){ if(horizontalMove()){ if(positionX<xStart){ angleRotation=90; positionX+=SPEED; if(positionX>xStart) positionX=xStart; }else{ positionX-=SPEED; angleRotation=270; if(positionX<xStart) positionX=xStart; } if(positionX==xStart) returnToRoute=false; }else{ if(positionY<yStart){ positionY+=SPEED; angleRotation=180; if(positionY>yStart) positionY=yStart; }else{ positionY-=SPEED; angleRotation=0; if(positionY<yStart) positionY=yStart; } if(positionY==yStart) returnToRoute=false; } }else if(!hitByFireball && !stopToSee){ if(horizontalMove()){ if(startToEnd){ if(!collideWall( positionX,positionY+SPEED)){ positionY+=SPEED; angleRotation=180; }else{ startToEnd=false; angleRotation=0; } } else{ if(!collideWall( positionX,positionY-SPEED)){ positionY-=SPEED; angleRotation=0; }else{ startToEnd=true; angleRotation=180; } } if(positionY<=yStart && (positionX<=xStart+1 || positionX>=xStart-1)){ startToEnd=true; angleRotation=180; }else if(positionY>=yEnd && (positionX<=xStart+1 || positionX>=xStart-1)){ startToEnd=false; angleRotation=0; } }else{ if(startToEnd){ if(!collideWall( positionX+SPEED,positionY)){ positionX+=SPEED; angleRotation=90; }else{ startToEnd=false; angleRotation=270; } }else{ if(!collideWall( positionX-SPEED,positionY)){ positionX-=SPEED; angleRotation=270; }else{ startToEnd=true; angleRotation=90; } } if(positionX<=xStart && (positionY<=yStart+1 || positionY>=yStart-1)){ startToEnd=true; angleRotation=90; }else if(positionX>=xEnd && (positionY<=yStart+1 || positionY>=yStart-1)){ startToEnd=false; angleRotation=270; } } } }