Skip to content

Commit

Permalink
todos_funcioando
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielclemnt committed Jan 19, 2024
1 parent fea7c0e commit f00e2ef
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 21 deletions.
15 changes: 9 additions & 6 deletions src/entities/coach/coach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,25 @@ void Coach::runCoach() {
players.value(playerId).value()->dribble(true);


if(ballPosition.x() == 0 && ballPosition.y() == 0){
if(ballPosition.x() == 0.0f && ballPosition.y() == 0.0f){

_ak_control->inicial();
_ak_control->inicial(getPlayer(BLUE, 0).value());

}

if(ballPosition.x()< 0 && ballPosition.x() < 1.7)

players.value(playerId).value()-> goTo(ballPosition);
if(ballPosition.x() < 0.0f && ballPosition.x() > -1.7f){

_ak_control->attackd(getPlayer(BLUE, 1).value(),getPlayer(BLUE, 2).value());
}

if(ballPosition.x() > 0.0f){

const QVector2D pontoMeia(-0.9f, 0.0f);
players.value(playerId).value()->goTo(pontoMeia);

}


}


}
Expand Down
64 changes: 52 additions & 12 deletions src/entities/player/ak_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,55 +108,95 @@ void ak_control::attack2(Player *Player3){

}

void ak_control ::inicial(){
void ak_control ::inicial(Player *player0){

if(_aPlayer != nullptr){
QVector2D ballPosition = _worldMap->ballPosition();

if(_aPlayer->getPosition().distanceToPoint(ballPosition)<(ROBOT_RADIUS + BALL_RADIUS) * 8){
_aPlayer->goTo(ballPosition);
_aPlayer->rotateTo(ballPosition);
_aPlayer->goTo(ballPosition);
_aPlayer->kick(4,false);
}

if(_aPlayer->getPosition().distanceToPoint(ballPosition) <= (ROBOT_RADIUS + BALL_RADIUS)){
_aPlayer->kick(6.0f, false);
QVector2D ballPosition = _worldMap->ballPosition();
QVector2D playerBLUE0Position = player0 -> getPosition();

QVector2D targetDirection = playerBLUE0Position - ballPosition; //calcula a direção da bola até o alvo
_aPlayer->rotateTo(playerBLUE0Position);

float playerOrientation = _aPlayer->getOrientation();

float targetDirectionAngle = atan2(targetDirection.y(), targetDirection.x());

if(_aPlayer->getPosition().distanceToPoint(ballPosition) <= (ROBOT_RADIUS + BALL_RADIUS) && abs(playerOrientation - targetDirectionAngle) < 0.02){
// Chuta a bola
_aPlayer->kick(4,false);
}
}

}

}

void ak_control::attack3(Player *Player3){
void ak_control::attackd(Player *Player1, Player *Player2){

if(_aPlayer != nullptr){
QVector2D ballPosition = _worldMap->ballPosition();
_aPlayer->dribble(true);

if(ballPosition.x() > 0.0f && ballPosition.y() <= 0.0){
if(ballPosition.x() < 0.0f && ballPosition.x() >= -1.7f && ballPosition.y() <= 3.0f && ballPosition.y() >= 0.0f){

_aPlayer->rotateTo(ballPosition);

if(_aPlayer->getPosition().distanceToPoint(ballPosition)<(ROBOT_RADIUS + BALL_RADIUS) *6){
if(_aPlayer->getPosition().distanceToPoint(ballPosition)<(ROBOT_RADIUS + BALL_RADIUS) *20){
_aPlayer->goTo(ballPosition);
_aPlayer->rotateTo(ballPosition);
}

if(_aPlayer->getPosition().distanceToPoint(ballPosition)<= (ROBOT_RADIUS + BALL_RADIUS)){
QVector2D ballPosition = _worldMap->ballPosition();
const QVector2D golposition(4.4f,-0.4f);

QVector2D targetDirection = golposition - ballPosition; //calcula a direção da bola até o alvo
_aPlayer->rotateTo(golposition);
QVector2D playerBLUE1Position = Player1 -> getPosition();

QVector2D targetDirection = playerBLUE1Position - ballPosition; //calcula a direção da bola até o alvo
_aPlayer->rotateTo(playerBLUE1Position );

float playerOrientation = _aPlayer->getOrientation();

float targetDirectionAngle = atan2(targetDirection.y(), targetDirection.x());

if(_aPlayer->getPosition().distanceToPoint(ballPosition) <= (ROBOT_RADIUS + BALL_RADIUS) && abs(playerOrientation - targetDirectionAngle) < 0.02){
// Chuta a bola
_aPlayer->kick(6,false);
_aPlayer->kick(5,false);
}
}
}

if(ballPosition.x() < 0.0f && ballPosition.x() >= -1.7f && ballPosition.y() < 0.0f && ballPosition.y() >= -3.0f){


if(_aPlayer->getPosition().distanceToPoint(ballPosition)<(ROBOT_RADIUS + BALL_RADIUS) *20){
_aPlayer->goTo(ballPosition);
_aPlayer->rotateTo(ballPosition);
}

if(_aPlayer->getPosition().distanceToPoint(ballPosition)<= (ROBOT_RADIUS + BALL_RADIUS)){

QVector2D playerBLUE2Position = Player2 -> getPosition();

QVector2D targetDirection = playerBLUE2Position - ballPosition; //calcula a direção da bola até o alvo
_aPlayer->rotateTo(playerBLUE2Position );

float playerOrientation = _aPlayer->getOrientation();

float targetDirectionAngle = atan2(targetDirection.y(), targetDirection.x());

if(_aPlayer->getPosition().distanceToPoint(ballPosition) <= (ROBOT_RADIUS + BALL_RADIUS) && abs(playerOrientation - targetDirectionAngle) < 0.02){
// Chuta a bola
_aPlayer->kick(5,false);
}
}
}
}

}
Expand Down
6 changes: 3 additions & 3 deletions src/entities/player/ak_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class ak_control
void attack1(Player *player3);
void attack2(Player *player3);
void attack3(Player *player3);
void attackd();
void attacka();
void inicial();
void attackd(Player *player1, Player *player2);
//void attacka(Player *player2);
void inicial(Player *player0);


//talvez implemente desvio
Expand Down

0 comments on commit f00e2ef

Please sign in to comment.