From 3a18f0ffbc80569e5e1f6d7b00cabd3d5ba3b06e Mon Sep 17 00:00:00 2001 From: antoinemeyer5 <antoine.meyer54@gmail.com> Date: Thu, 30 Jun 2022 09:34:48 +0200 Subject: [PATCH] fix collisions --- .../jeu_appren_par_renfo/src/player.c | 24 +++++++++---------- .../jeu_appren_par_renfo/src/player.h | 2 +- 2 files changed, 13 insertions(+), 13 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 86e7cc1..6cc8467 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.c @@ -35,10 +35,10 @@ int *generateLandingPoint(int rxWall) int *landingPoint = malloc(sizeof(int) * 2); srand(time(NULL)); - int randomPointX = MAP_WIDTH/2 + 1 + rand()%(rxWall/BLOCK_SIZE - (MAP_WIDTH/2)); + int randomPointX = MAP_WIDTH / 2 + 1 + rand() % (rxWall / BLOCK_SIZE - (MAP_WIDTH / 2)); int randomPointY = -1; - landingPoint[0] = randomPointX ; + landingPoint[0] = randomPointX; landingPoint[1] = randomPointY / BLOCK_SIZE; landingPointIsFind = 1; @@ -72,16 +72,17 @@ void hitBall() float distanceNet; if (player.isHitting) { - castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet); + castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet); // printf("hit\n"); - if (rxWall > MAP_WIDTH/2) + if (rxWall > MAP_WIDTH / 2) { - + freeIntList(lastHitPoint); lastHitPoint = allocLastHitPoint(); - //cherche et trouve point de chute, UNE SEULE FOIS! - if(landingPointIsFind == 0){ + // 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]); @@ -144,9 +145,10 @@ void manageMovement() // d : keys[3] : droite float x_increment = (Keys[0] - Keys[2]) * player.deltax + (Keys[3] - Keys[1]) * sin(player.angle); float y_increment = (Keys[0] - Keys[2]) * player.deltay + (Keys[1] - Keys[3]) * cos(player.angle); - float newpos_x = (player.x + x_increment) / BLOCK_SIZE; - float newpos_y = (player.y + y_increment) / BLOCK_SIZE; - if (newpos_x >= 0 && newpos_x < MAP_WIDTH && newpos_y >= 0 && newpos_y < MAP_HEIGHT) + float newpos_x = (player.x + x_increment * MOVEMENT_SPEED) / BLOCK_SIZE; + float newpos_y = (player.y + y_increment * MOVEMENT_SPEED) / BLOCK_SIZE; + int widthColli = player.w / (3 * BLOCK_SIZE); + if (newpos_x > widthColli && newpos_x < MAP_WIDTH - widthColli && newpos_y > widthColli && newpos_y < MAP_HEIGHT - widthColli) { if (map[(int)newpos_y][(int)newpos_x] != 1) { @@ -154,8 +156,6 @@ void manageMovement() player.y += y_increment * MOVEMENT_SPEED; } } - printf("newpos_x:%f, newpos_y:%f - ", newpos_x, newpos_y); - printf("pX:%f, pY:%f\n", player.x, player.y); } void managePlayer() 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 ebe9a2d..f656785 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.h @@ -11,7 +11,7 @@ #define ENTITIES_RIGHT 3 #define HIT_RANGE 2 -#define HIT_FORCE 20 +#define HIT_FORCE 10 #define MOVEMENT_SPEED 20 typedef struct player{ -- GitLab