From 4886f8fb217d8de54ebfd019f6493e2fd58f6f21 Mon Sep 17 00:00:00 2001 From: Taha Belkhiri <belkhiri.taha53@gmail.com> Date: Wed, 29 Jun 2022 15:07:17 +0200 Subject: [PATCH] la bonne version --- .../jeu_appren_par_renfo/src/player.c | 56 ++++++------------- 1 file changed, 18 insertions(+), 38 deletions(-) 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 b3e67a5..9db7c0d 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.c @@ -5,7 +5,6 @@ player_t ennemy; int *landingPoint; int *lastHitPoint; -int landingPointIsFind = 0; void initPlayer() { @@ -30,22 +29,15 @@ void initPlayer() player.viewAngle = 0; } -int *generateLandingPoint(int rxWall) +int *generateLandingPoint() { int *landingPoint = malloc(sizeof(int) * 2); - srand(time(NULL)); - //printf("wall x :%d=>%d\n", rxWall, rxWall/BLOCK_SIZE); - - int randomPointX = MAP_WIDTH/2 + 1 + rand()%(rxWall/BLOCK_SIZE - (MAP_WIDTH/2)); - int randomPointY = -1; - - //printf("entre %d et %d\n", MAP_WIDTH/2, MAP_WIDTH/2+rxWall/BLOCK_SIZE - (MAP_WIDTH/2)); - //printf("randomPointX: %d => %d\n", randomPointX, randomPointX*BLOCK_SIZE); - - landingPoint[0] = randomPointX ; + int randomLength = rand() % (int)((MAP_WIDTH / 2) * BLOCK_SIZE) + (MAP_WIDTH / 2) * BLOCK_SIZE; + int randomPointX = randomLength * cos(player.angle) + player.x; + int randomPointY = randomLength * sin(player.angle) + player.y; + landingPoint[0] = randomPointX / BLOCK_SIZE; landingPoint[1] = randomPointY / BLOCK_SIZE; - landingPointIsFind = 1; - + // printf("landing point: %d %d\n", landingPoint[0], landingPoint[1]); return landingPoint; } @@ -67,8 +59,6 @@ void freeIntList(int *list) void hitBall() { -<<<<<<< HEAD -======= // printf("map edges: %d %d\n", BLOCK_SIZE * MAP_WIDTH/2, BLOCK_SIZE *MAP_HEIGHT/2); // printf("ray1: %d %d\n", ray1[0], ray1[1]); int fermetureAngle = 2; @@ -82,7 +72,6 @@ void hitBall() //printf("angle min: %d\n", angleMin); //printf("angle max: %d\n", angleMax); //printf("distance to ball: %f\n", sqrt(pow(ball.x - player.x, 2) + pow(ball.y - player.y, 2))/BLOCK_SIZE); ->>>>>>> 0383eb7e8ec1fcd92d8fd2c6846d5e9ab2d08f17 if (sqrt(pow(player.x - ball.x, 2) + pow(player.y - ball.y, 2)) / BLOCK_SIZE < HIT_RANGE) { int rxWall, ryWall; @@ -93,47 +82,39 @@ void hitBall() if (player.isHitting) { castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet); - //printf("rayWall: %d %d\n", rxWall/BLOCK_SIZE, ryWall/BLOCK_SIZE); - //printf("distanceWall: %f\n", distanceWall); - -<<<<<<< HEAD - //printf("rayNet: %d %d\n", rxNet/BLOCK_SIZE, ryNet/BLOCK_SIZE); - //printf("distanceNet: %f\n", distanceNet); - if (rxWall > MAP_WIDTH/2) - { + printf("rayWall: %d %d\n", rxWall/BLOCK_SIZE, ryWall/BLOCK_SIZE); + printf("distanceWall: %f\n", distanceWall); - if (player.isHitting) -======= printf("rayNet: %d %d\n", rxNet/BLOCK_SIZE, ryNet/BLOCK_SIZE); printf("distanceNet: %f\n", distanceNet); // printf("hit\n"); if (rxWall > MAP_WIDTH/2) ->>>>>>> 0383eb7e8ec1fcd92d8fd2c6846d5e9ab2d08f17 { - + freeIntList(landingPoint); freeIntList(lastHitPoint); - lastHitPoint = allocLastHitPoint(); - - //cherche et trouve point de chute, UNE SEULE FOIS! - if(landingPointIsFind == 0){ - freeIntList(landingPoint); - landingPoint = generateLandingPoint(rxWall); - printf("landing point: x=%d; y=%d\n", landingPoint[0], landingPoint[1]); - } + + + lastHitPoint = allocLastHitPoint(); + landingPoint = generateLandingPoint(); lastHitPoint[0] = ball.x; lastHitPoint[1] = player.h; + /*ball.x = player.x; + ball.y = player.y; + ball.z = player.h;*/ ball.angle = player.angle; ball.speed = 2 * HIT_FORCE; ball.z = player.h; ball.isHit = 1; } + // printf("valid hit\n"); } else { // printf("unvalid hit\n"); } } + //} } void updateBall() @@ -142,7 +123,6 @@ void updateBall() ball.y = ball.y + ball.speed * sin(ball.angle); 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.z > 0) -- GitLab