diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c b/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c index c38f48a6b008cce2899fd92384eb96ea1791fd65..d398e3f26629d1459a2821082869f5b2b451c5df 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c @@ -6,6 +6,8 @@ int ennemyZone; int canonZone; int action; +int ennemyHasMoved = 0; + void initEnnemy() { ennemy.h = 2 * BLOCK_SIZE; @@ -18,7 +20,8 @@ void initEnnemy() void manageEnnemyMovement() { - if (ball.isTravelingTo == AI){ + if (ball.isTravelingTo == AI) + { angleF = defineAngleF(lastHitPoint[0], lastHitPoint[1], landingPoint[0], landingPoint[1]); angleF = converterIntoAngleF(angleF); angleH = defineAngleH(lastHitPoint[0], landingPoint[0]); @@ -26,30 +29,68 @@ void manageEnnemyMovement() ennemyZone = convertIntoZone(ennemy.x, ennemy.y); canonZone = convertIntoZone(lastHitPoint[0], lastHitPoint[1]); action = takeAction(ennemy.x, ennemy.y, Q, canonZone, angleH, angleF, 1); - switch (action) + while (ennemyHasMoved == 0) { + switch (action) + { case BACK: - ennemy.x += MOVEMENT_SPEED; + if (ennemy.x + BLOCK_SIZE < (MAP_WIDTH-1) * BLOCK_SIZE) + { + ennemy.x += BLOCK_SIZE; + ennemyHasMoved = 1; + } + else + { + action = takeAction(ennemy.x, ennemy.y, Q, canonZone, angleH, angleF, 1); + } break; case FOWARD: - ennemy.x -= MOVEMENT_SPEED; + if (ennemy.x - BLOCK_SIZE > (MAP_WIDTH/2 + 1) * BLOCK_SIZE) + { + ennemy.x -= BLOCK_SIZE; + ennemyHasMoved = 1; + } + else + { + action = takeAction(ennemy.x, ennemy.y, Q, canonZone, angleH, angleF, 1); + } break; case UP: - ennemy.y -= MOVEMENT_SPEED; + if (ennemy.y - BLOCK_SIZE > 1) + { + ennemy.y -= BLOCK_SIZE; + ennemyHasMoved = 1; + } + else + { + action = takeAction(ennemy.x, ennemy.y, Q, canonZone, angleH, angleF, 1); + } break; case DOWN: - ennemy.y += MOVEMENT_SPEED; + if (ennemy.y + BLOCK_SIZE < (MAP_HEIGHT-1) * BLOCK_SIZE) + { + ennemy.y += BLOCK_SIZE; + ennemyHasMoved = 1; + } + else + { + action = takeAction(ennemy.x, ennemy.y, Q, canonZone, angleH, angleF, 1); + } break; - + default: + ennemyHasMoved = 1; break; + } } + ennemyHasMoved = 0; } } -void manageEnnemy(){ +void manageEnnemy() +{ manageEnnemyMovement(); } \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/player.c b/travail_de_groupe/jeu_appren_par_renfo/src/player.c index c18a07fa48419fd67bdf5cad0a6354267062bad4..b46f504deefb981fee874ec537284018f3e55333 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.c @@ -83,7 +83,6 @@ void hitBall() { freeIntList(landingPoint); landingPoint = generateLandingPoint(rxWall); - printf("landing point: x=%d; y=%d\n", landingPoint[0], landingPoint[1]); } lastHitPoint[0] = ball.x; diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/render.c b/travail_de_groupe/jeu_appren_par_renfo/src/render.c index 02e079b78af567065ebabd7ad487b8261ff451de..0f71a7a840f624857b66013e7401da3cc2bcf13f 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.c @@ -760,7 +760,6 @@ void drawEnnemy() } } - int isAngleInRange(float angle, float min, float max) { return ((angle >= min && angle <= max)) || ((angle >= max && angle <= min)); @@ -884,22 +883,23 @@ void drawMap2D(int map[][MAP_WIDTH]) // draw player SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); - rect.x = (player.x * CELL_SIZE) / BLOCK_SIZE - CELL_SIZE/2; - rect.y = (player.y * CELL_SIZE) / BLOCK_SIZE - CELL_SIZE/2; + rect.x = (player.x * CELL_SIZE) / BLOCK_SIZE - CELL_SIZE / 2; + rect.y = (player.y * CELL_SIZE) / BLOCK_SIZE - CELL_SIZE / 2; SDL_RenderFillRect(renderer, &rect); // draw ennemi SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); - rect.x = (ennemy.x * CELL_SIZE) / BLOCK_SIZE - CELL_SIZE/2; - rect.y = (ennemy.y * CELL_SIZE) / BLOCK_SIZE - CELL_SIZE/2; + rect.x = (ennemy.x * CELL_SIZE) / BLOCK_SIZE - CELL_SIZE / 2; + rect.y = (ennemy.y * CELL_SIZE) / BLOCK_SIZE - CELL_SIZE / 2; SDL_RenderFillRect(renderer, &rect); - //draw landing point - if(landingPointIsFind == 1){ + // draw landing point + if (landingPointIsFind == 1) + { SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); rect.x = landingPoint[0] * CELL_SIZE; rect.y = CELL_SIZE; - rect.h = (MAP_HEIGHT-2) * CELL_SIZE; + rect.h = (MAP_HEIGHT - 2) * CELL_SIZE; rect.w = 3; SDL_RenderFillRect(renderer, &rect); // reset taille cellule @@ -909,8 +909,8 @@ void drawMap2D(int map[][MAP_WIDTH]) // draw ball SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); - rect.x = (ball.x * CELL_SIZE) / BLOCK_SIZE - CELL_SIZE/2; - rect.y = (ball.y * CELL_SIZE) / BLOCK_SIZE - CELL_SIZE/2; + rect.x = (ball.x * CELL_SIZE) / BLOCK_SIZE - CELL_SIZE / 2; + rect.y = (ball.y * CELL_SIZE) / BLOCK_SIZE - CELL_SIZE / 2; SDL_RenderFillRect(renderer, &rect); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);