From d2994d2f08f65cc38916560073b94ba6fe618aa5 Mon Sep 17 00:00:00 2001 From: belkhiritaha <belkhiri.taha53@gmail.com> Date: Thu, 30 Jun 2022 17:34:50 +0200 Subject: [PATCH] modifications du systeme de hit de balle --- .../.vscode/settings.json | 5 ++ .../jeu_appren_par_renfo/src/ball.c | 9 ++- .../jeu_appren_par_renfo/src/ennemy.c | 52 ++++++++------- .../jeu_appren_par_renfo/src/ennemy.h | 6 ++ .../jeu_appren_par_renfo/src/gest_event.c | 7 +- .../jeu_appren_par_renfo/src/player.c | 66 +++++++------------ .../jeu_appren_par_renfo/src/player.h | 9 ++- .../jeu_appren_par_renfo/src/render.c | 4 +- 8 files changed, 86 insertions(+), 72 deletions(-) create mode 100644 travail_de_groupe/jeu_appren_par_renfo/.vscode/settings.json diff --git a/travail_de_groupe/jeu_appren_par_renfo/.vscode/settings.json b/travail_de_groupe/jeu_appren_par_renfo/.vscode/settings.json new file mode 100644 index 0000000..a7361b1 --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "qlearn.h": "c" + } +} \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/ball.c b/travail_de_groupe/jeu_appren_par_renfo/src/ball.c index 9c3acb0..b9fd1f5 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/ball.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ball.c @@ -13,6 +13,8 @@ void initBall() ball.isHit = 0; ball.angle = -pi; ball.speed = 0; + landingPointEnnemyIsFind = 0; + landingPointPlayerIsFind = 0; } //ball_t ball; int trajectoireAntoine[NUMBERPOINT_TRAJEC][2]; @@ -134,7 +136,12 @@ void updateBall() if (ball.isHit) { // landingPoint est déjà / BLOCK_SIZE de base - ball.z = lagrangeInterpolation(ball.x / BLOCK_SIZE, lastHitPoint[0] / BLOCK_SIZE, lastHitPoint[1] / BLOCK_SIZE, 15, 2 * player.h / BLOCK_SIZE, landingPoint[0], 0); + if (ball.isTravelingTo == AI){ + ball.z = lagrangeInterpolation(ball.x / BLOCK_SIZE, lastHitPointPlayerX / BLOCK_SIZE, lastHitPointPlayerY / BLOCK_SIZE, 15, 2 * player.h / BLOCK_SIZE, landingPointPlayerX, 0); + } + else if (ball.isTravelingTo == PLAYER){ + ball.z = lagrangeInterpolation(ball.x / BLOCK_SIZE, lastHitPointEnnemyX / BLOCK_SIZE, lastHitPointEnnemyY / BLOCK_SIZE, 15, 2 * ennemy.h / BLOCK_SIZE, landingPointEnnemyX, 0); + } } if (ball.z < 0) { 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 1a1d3f9..eea4427 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c @@ -1,5 +1,13 @@ #include "player.h" +int landingPointEnnemyX; +int landingPointEnnemyY; + +int lastHitPointEnnemyX; +int lastHitPointEnnemyY = 0; + +int landingPointEnnemyIsFind = 0; + int angleF; int angleH; int ennemyZone; @@ -22,12 +30,12 @@ void manageEnnemyMovement() { if (ball.isTravelingTo == AI) { - angleF = defineAngleF(lastHitPoint[0], lastHitPoint[1], landingPoint[0], landingPoint[1]); + angleF = defineAngleF(lastHitPointPlayerX, lastHitPointPlayerY, landingPointPlayerX, landingPointPlayerY); angleF = converterIntoAngleF(angleF); - angleH = defineAngleH(lastHitPoint[0], landingPoint[0]); + angleH = defineAngleH(lastHitPointPlayerX, landingPointPlayerX); angleH = converterIntoAngleH(angleH); ennemyZone = convertIntoZone(ennemy.x, ennemy.y); - canonZone = convertIntoZone(lastHitPoint[0], lastHitPoint[1]); + canonZone = convertIntoZone(lastHitPointPlayerX, lastHitPointPlayerY); action = takeAction(ennemy.x, ennemy.y, Q, canonZone, angleH, angleF, 1); while (ennemyHasMoved == 0) { @@ -90,38 +98,38 @@ void manageEnnemyMovement() } } -int * generateLandingPointEnnemy(){ - int *landingPoint = malloc(sizeof(int) * 2); +int generatelandingPointEnnemy(){ int randomPointX = rand() % ((MAP_WIDTH/2)); - landingPoint[0] = randomPointX ; - landingPoint[1] = 0; - landingPointIsFind = 1; + landingPointEnnemyIsFind = 1; + landingPointPlayerIsFind = 0; - return landingPoint; + return randomPointX; } + void ennemyHitBall(){ if (sqrt(pow(ennemy.x - ball.x, 2) + pow(ennemy.y - ball.y, 2)) / BLOCK_SIZE < HIT_RANGE) { if (ball.isTravelingTo == AI) { - if(landingPointIsFind == 0){ - freeIntList(landingPoint); - landingPoint = generateLandingPointEnnemy(); - } - ball.isTravelingTo = PLAYER; - ball.angle = ennemy.angle; - ball.speed = HIT_FORCE; - ball.isHit = 1; - lastHitPoint[0] = ball.x; - lastHitPoint[1] = player.h; - - printf("ennemy new lastHitPoint : %d %d\n", lastHitPoint[0]/BLOCK_SIZE, lastHitPoint[1]/BLOCK_SIZE); + //cherche et trouve point de chute, UNE SEULE FOIS! + if(landingPointEnnemyIsFind == 0){ + landingPointEnnemyX = generatelandingPointEnnemy(); + ball.isTravelingTo = PLAYER; + ball.angle = ennemy.angle; + ball.speed = HIT_FORCE; + ball.isHit = 1; + lastHitPointEnnemyX = ball.x; + lastHitPointEnnemyY = player.h; + + printf("ennemy new lastHitPointEnnemy : %d %d\n", lastHitPointEnnemyX/BLOCK_SIZE, lastHitPointEnnemyY/BLOCK_SIZE); + + printf("ennemy new landingPointEnnemy : %d %d\n", landingPointEnnemyX/BLOCK_SIZE, landingPointEnnemyY/BLOCK_SIZE); + } - printf("ennemy new landingPoint : %d %d\n", landingPoint[0]/BLOCK_SIZE, landingPoint[1]/BLOCK_SIZE); } } } diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.h b/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.h index 660453b..a4f58a2 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.h @@ -8,7 +8,13 @@ #include "qlearn.h" +extern int landingPointEnnemyX; +extern int landingPointEnnemyY; +extern int lastHitPointEnnemyX; +extern int lastHitPointEnnemyY; + +extern int landingPointEnnemyIsFind; void initEnnemy(); void manageEnnemy(); diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c b/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c index 7e2656a..a63f419 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c @@ -68,11 +68,11 @@ void gestGame() } if (event.motion.yrel > 0) { - player.viewAngle -= 1; + player.viewAngle -= 0.01 * RD; } if (event.motion.yrel < 0) { - player.viewAngle += 1; + player.viewAngle += 0.01 * RD; } player.deltax = cos(player.angle); player.deltay = sin(player.angle); @@ -118,7 +118,8 @@ void gestGame() case SDLK_b: initBall(); - landingPointIsFind = 0; + landingPointPlayerIsFind = 0; + landingPointEnnemyIsFind = 0; break; default: 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 b6d289b..f0e6e19 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.c @@ -3,9 +3,13 @@ player_t player; player_t ennemy; -int *landingPoint; -int *lastHitPoint; -int landingPointIsFind = 0; +int landingPointPlayerX; +int landingPointPlayerY = 0; + +int lastHitPointPlayerX; +int lastHitPointPlayerY; + +int landingPointPlayerIsFind = 0; void initPlayer() { @@ -30,33 +34,15 @@ void initPlayer() player.viewAngle = 0; } -int *generateLandingPoint(int rxWall) +int generatelandingPointPlayer(int rxWall) { - int *landingPoint = malloc(sizeof(int) * 2); int randomPointX = MAP_WIDTH/2 + 1 + rand()%(rxWall/BLOCK_SIZE - (MAP_WIDTH/2)); - landingPoint[0] = randomPointX ; - landingPoint[1] = 0; - landingPointIsFind = 1; - - return landingPoint; -} - -int *allocLastHitPoint() -{ - int *lastHitPoint = (int *)malloc(sizeof(int) * 2); - lastHitPoint[0] = 0; - lastHitPoint[1] = 0; - return lastHitPoint; -} + landingPointPlayerIsFind = 1; + landingPointEnnemyIsFind = 0; -void freeIntList(int *list) -{ - if (list != NULL) - { - free(list); - } + return randomPointX; } void hitBall() @@ -74,28 +60,26 @@ void hitBall() // printf("hit\n"); if (rxWall > MAP_WIDTH/2) { - - freeIntList(lastHitPoint); - lastHitPoint = allocLastHitPoint(); //cherche et trouve point de chute, UNE SEULE FOIS! - if(landingPointIsFind == 0){ - freeIntList(landingPoint); - landingPoint = generateLandingPoint(rxWall); - } + if(landingPointPlayerIsFind == 0){ - lastHitPoint[0] = ball.x; - lastHitPoint[1] = player.h; + landingPointPlayerX = generatelandingPointPlayer(rxWall); - ball.angle = player.angle; - ball.speed = HIT_FORCE; - ball.z = player.h; - ball.isHit = 1; - ball.isTravelingTo = AI; + printf("player new lastHitPointPlayer : %d %d\n", lastHitPointPlayerX/BLOCK_SIZE, lastHitPointPlayerY/BLOCK_SIZE); - printf("ennemy new lastHitPoint : %d %d\n", lastHitPoint[0]/BLOCK_SIZE, lastHitPoint[1]/BLOCK_SIZE); + printf("player new landingPointPlayer : %d %d\n", landingPointPlayerX/BLOCK_SIZE, landingPointPlayerY/BLOCK_SIZE); + + lastHitPointPlayerX = ball.x; + lastHitPointPlayerY = player.h; + + ball.angle = player.angle; + ball.speed = HIT_FORCE; + ball.z = player.h; + ball.isHit = 1; + ball.isTravelingTo = AI; + } - printf("ennemy new landingPoint : %d %d\n", landingPoint[0]/BLOCK_SIZE, landingPoint[1]/BLOCK_SIZE); } // printf("valid hit\n"); } diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/player.h b/travail_de_groupe/jeu_appren_par_renfo/src/player.h index ca036f8..50c18b7 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.h @@ -37,9 +37,12 @@ typedef struct player extern player_t player; extern player_t ennemy; -extern int *landingPoint; -extern int *lastHitPoint; -extern int landingPointIsFind; +extern int landingPointPlayerX; +extern int landingPointPlayerY; + +extern int lastHitPointPlayerX; +extern int lastHitPointPlayerY; +extern int landingPointPlayerIsFind; void initPlayer(); void managePlayer(); 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 02a5f7c..bcb8be4 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.c @@ -894,10 +894,10 @@ void drawMap2D(int map[][MAP_WIDTH]) SDL_RenderFillRect(renderer, &rect); // draw landing point - if (landingPointIsFind == 1) + if (landingPointPlayerIsFind == 1) { SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); - rect.x = landingPoint[0] * CELL_SIZE; + rect.x = landingPointPlayerX * CELL_SIZE; rect.y = CELL_SIZE; rect.h = (MAP_HEIGHT - 2) * CELL_SIZE; rect.w = 3; -- GitLab