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 d3cdffc1087ff1d1a652a1ba5f2ed485386cdbc1..5c73891b50def542e68ea0d99a4605d9871effb2 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 = 2 * BLOCK_SIZE; + ball.y = 5 * 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/player.c b/travail_de_groupe/jeu_appren_par_renfo/src/player.c index 9db7c0d83c5beed6025d981a6304ae7d879917ee..4122ff22f59a621d5df8965bf95c52451154525b 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,18 @@ 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)); + + int randomPointX = MAP_WIDTH/2 + 1 + rand()%(rxWall/BLOCK_SIZE - (MAP_WIDTH/2)); + int randomPointY = -1; + + landingPoint[0] = randomPointX ; landingPoint[1] = randomPointY / BLOCK_SIZE; - // printf("landing point: %d %d\n", landingPoint[0], landingPoint[1]); + landingPointIsFind = 1; + return landingPoint; } @@ -59,19 +63,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("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); if (sqrt(pow(player.x - ball.x, 2) + pow(player.y - ball.y, 2)) / BLOCK_SIZE < HIT_RANGE) { int rxWall, ryWall; @@ -82,26 +73,23 @@ 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); - - printf("rayNet: %d %d\n", rxNet/BLOCK_SIZE, ryNet/BLOCK_SIZE); - printf("distanceNet: %f\n", distanceNet); // printf("hit\n"); if (rxWall > MAP_WIDTH/2) { - freeIntList(landingPoint); - freeIntList(lastHitPoint); + 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;