From f00e2efca93ef9d1925c838fa0f91f8b5901fab3 Mon Sep 17 00:00:00 2001 From: Gabriel Clemente Date: Fri, 19 Jan 2024 20:55:22 -0300 Subject: [PATCH] todos_funcioando --- src/entities/coach/coach.cpp | 15 ++++--- src/entities/player/ak_control.cpp | 64 ++++++++++++++++++++++++------ src/entities/player/ak_control.h | 6 +-- 3 files changed, 64 insertions(+), 21 deletions(-) diff --git a/src/entities/coach/coach.cpp b/src/entities/coach/coach.cpp index 55db1a5..3d303fc 100644 --- a/src/entities/coach/coach.cpp +++ b/src/entities/coach/coach.cpp @@ -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); + } - + } } diff --git a/src/entities/player/ak_control.cpp b/src/entities/player/ak_control.cpp index e6d6068..a1f4e2a 100644 --- a/src/entities/player/ak_control.cpp +++ b/src/entities/player/ak_control.cpp @@ -108,43 +108,58 @@ 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(); @@ -152,11 +167,36 @@ void ak_control::attack3(Player *Player3){ 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); + } + } + } } } diff --git a/src/entities/player/ak_control.h b/src/entities/player/ak_control.h index d37078c..00a7fdb 100644 --- a/src/entities/player/ak_control.h +++ b/src/entities/player/ak_control.h @@ -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