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 11d96b4ba15876b34ef0fffcf1a22469b89d07ca..21981dac9e00bf87b480e46e9ede141c49a8ab0b 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/ball.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ball.c @@ -5,8 +5,8 @@ int trajectoireAntoine[NUMBERPOINT_TRAJEC][2]; void initBall() { - ball.x = (rand()%(MAP_WIDTH/2)) * BLOCK_SIZE + BLOCK_SIZE; - ball.y = (rand()% (MAP_HEIGHT - 2)) * BLOCK_SIZE + BLOCK_SIZE; + ball.x = player.x + player.w / 2; + ball.y = player.y; ball.z = player.h / BLOCK_SIZE; ball.h = 0.5 * BLOCK_SIZE; ball.w = 0.5 * BLOCK_SIZE; @@ -137,11 +137,4 @@ void updateBall() 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 ((int)ball.z == 0) - { - ball.x = 0; - ball.y = 0; - ball.z = 0; - ball.speed = 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 c38f48a6b008cce2899fd92384eb96ea1791fd65..cf27b50839785757aa2e89de24853bf8adb54aee 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ennemy.c @@ -29,19 +29,19 @@ void manageEnnemyMovement() switch (action) { case BACK: - ennemy.x += MOVEMENT_SPEED; + ennemy.x += BLOCK_SIZE; break; case FOWARD: - ennemy.x -= MOVEMENT_SPEED; + ennemy.x -= BLOCK_SIZE; break; case UP: - ennemy.y -= MOVEMENT_SPEED; + ennemy.y -= BLOCK_SIZE; break; case DOWN: - ennemy.y += MOVEMENT_SPEED; + ennemy.y += BLOCK_SIZE; break; default: @@ -50,6 +50,31 @@ void manageEnnemyMovement() } } +void generateLandingPointEnnemy(){ + landingPoint[0] = rand() % ((MAP_WIDTH/2)); + landingPoint[1] = rand() % (MAP_HEIGHT); +} + +void ennemyHitBall(){ + if (sqrt(pow(ennemy.x - ball.x, 2) + pow(ennemy.y - ball.y, 2)) / BLOCK_SIZE < HIT_RANGE) + { + if (ball.isTravelingTo == AI) + { + + ball.isTravelingTo = PLAYER; + ball.angle = ennemy.angle; + ball.speed = HIT_FORCE; + ball.isHit = 1; + lastHitPoint[0] = ball.x; + lastHitPoint[1] = player.h; + + printf("new lastHitPoint : %d %d\n", lastHitPoint[0], lastHitPoint[1]); + generateLandingPointEnnemy(); + } + } +} + void manageEnnemy(){ manageEnnemyMovement(); + ennemyHitBall(); } \ 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..a8b8640f91b3a9b44c09e6e5fe9b84f498854e27 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.c @@ -33,11 +33,12 @@ void initPlayer() 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; @@ -71,16 +72,16 @@ void hitBall() float distanceNet; if (player.isHitting) { - castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet); - if (rxWall > MAP_WIDTH / 2) + castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet); + // printf("hit\n"); + 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]); @@ -90,16 +91,21 @@ void hitBall() lastHitPoint[1] = player.h; ball.angle = player.angle; - ball.speed = 2 * HIT_FORCE; + ball.speed = HIT_FORCE; ball.z = player.h; ball.isHit = 1; ball.isTravelingTo = AI; } + // printf("valid hit\n"); + } + else + { + // printf("unvalid hit\n"); } } + //} } - void manageMovement() { // z : keys[2] : avance @@ -110,8 +116,7 @@ void manageMovement() float y_increment = (Keys[0] - Keys[2]) * player.deltay + (Keys[1] - Keys[3]) * cos(player.angle); 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 (newpos_x >= 0 && newpos_x < MAP_WIDTH && newpos_y >= 0 && newpos_y < MAP_HEIGHT) { if (map[(int)newpos_y][(int)newpos_x] != 1) { @@ -125,4 +130,5 @@ void managePlayer() { manageMovement(); hitBall(); + updateBall(); } \ No newline at end of file