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 5c73891b50def542e68ea0d99a4605d9871effb2..d3cdffc1087ff1d1a652a1ba5f2ed485386cdbc1 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/ball.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/ball.c @@ -6,7 +6,7 @@ int trajectoireAntoine[NUMBERPOINT_TRAJEC][2]; void initBall() { ball.x = 5 * BLOCK_SIZE; - ball.y = 5 * BLOCK_SIZE; + ball.y = 2 * BLOCK_SIZE; ball.z = player.h/BLOCK_SIZE; ball.h = 0.5 * BLOCK_SIZE; ball.w = 0.5 * BLOCK_SIZE; diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/main.c b/travail_de_groupe/jeu_appren_par_renfo/src/main.c index 6a04d466e4b3c6e5a6b49b1e49a3eb6b9e2b4268..f8f4d3c992e87b253f43c34e9e9159ad9ba52258 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/main.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/main.c @@ -3,11 +3,10 @@ int running; int game_state; - int main(){ - float ***** Q = allocateAndInitiateQ(); - writeQ(Q); + //float ***** Q = allocateAndInitiateQ(); + //writeQ(Q); running = 1; game_state = GAME; readMapFromFile("map.txt"); 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 9175fd3b31244c6844d16b0dbeb097cc4f83e22b..70a6d0bea9aebfceb1ae841537a90ca0c31ff0ee 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/player.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/player.c @@ -5,6 +5,7 @@ player_t ennemy; int *landingPoint; int *lastHitPoint; +int landingPointIsFind = 0; void initPlayer() { @@ -29,15 +30,22 @@ void initPlayer() player.viewAngle = 0; } -int *generateLandingPoint() +int *generateLandingPoint(int rxWall) { int *landingPoint = malloc(sizeof(int) * 2); - 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; + 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 ; landingPoint[1] = randomPointY / BLOCK_SIZE; - // printf("landing point: %d %d\n", landingPoint[0], landingPoint[1]); + landingPointIsFind = 1; + return landingPoint; } @@ -59,17 +67,6 @@ void freeIntList(int *list) void hitBall() { - // 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; - //int angleMin = RD * atan2((MAP_WIDTH+fermetureAngle / 2) * BLOCK_SIZE - player.x, player.y); - //int angleMax = 90 + RD * atan2((MAP_WIDTH+fermetureAngle / 2) * BLOCK_SIZE - player.x, MAP_HEIGHT * BLOCK_SIZE - player.y); - - - - int currAngle = (int)((player.angle) * RD + 90) % 360; - // printf("player angle: %d\n",(int) ((player.angle) * RD +90) %360); - // printf("distance to ball: %f\n", sqrt(pow(ball.x - player.x, 2) + pow(ball.y - player.y, 2))/BLOCK_SIZE); if (sqrt(pow(player.x - ball.x, 2) + pow(player.y - ball.y, 2)) / BLOCK_SIZE < HIT_RANGE) { int rxWall, ryWall; @@ -78,41 +75,40 @@ void hitBall() int rxNet, ryNet; float distanceNet; 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); + //printf("rayWall: %d %d\n", rxWall/BLOCK_SIZE, ryWall/BLOCK_SIZE); + //printf("distanceWall: %f\n", distanceWall); - printf("rayNet: %d %d\n", rxNet/BLOCK_SIZE, ryNet/BLOCK_SIZE); - printf("distanceNet: %f\n", distanceNet); + //printf("rayNet: %d %d\n", rxNet/BLOCK_SIZE, ryNet/BLOCK_SIZE); + //printf("distanceNet: %f\n", distanceNet); if (rxWall > MAP_WIDTH/2) { - // printf("hit\n"); + if (player.isHitting) { - freeIntList(landingPoint); - freeIntList(lastHitPoint); - - + freeIntList(lastHitPoint); lastHitPoint = allocLastHitPoint(); - landingPoint = generateLandingPoint(); + + //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[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() @@ -121,6 +117,7 @@ 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)