Skip to content
Snippets Groups Projects
Commit 4886f8fb authored by Taha Belkhiri's avatar Taha Belkhiri
Browse files

la bonne version

parent 6aa942db
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,6 @@ player_t ennemy; ...@@ -5,7 +5,6 @@ player_t ennemy;
int *landingPoint; int *landingPoint;
int *lastHitPoint; int *lastHitPoint;
int landingPointIsFind = 0;
void initPlayer() void initPlayer()
{ {
...@@ -30,22 +29,15 @@ void initPlayer() ...@@ -30,22 +29,15 @@ void initPlayer()
player.viewAngle = 0; player.viewAngle = 0;
} }
int *generateLandingPoint(int rxWall) int *generateLandingPoint()
{ {
int *landingPoint = malloc(sizeof(int) * 2); int *landingPoint = malloc(sizeof(int) * 2);
srand(time(NULL)); int randomLength = rand() % (int)((MAP_WIDTH / 2) * BLOCK_SIZE) + (MAP_WIDTH / 2) * BLOCK_SIZE;
//printf("wall x :%d=>%d\n", rxWall, rxWall/BLOCK_SIZE); int randomPointX = randomLength * cos(player.angle) + player.x;
int randomPointY = randomLength * sin(player.angle) + player.y;
int randomPointX = MAP_WIDTH/2 + 1 + rand()%(rxWall/BLOCK_SIZE - (MAP_WIDTH/2)); landingPoint[0] = randomPointX / BLOCK_SIZE;
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; landingPoint[1] = randomPointY / BLOCK_SIZE;
landingPointIsFind = 1; // printf("landing point: %d %d\n", landingPoint[0], landingPoint[1]);
return landingPoint; return landingPoint;
} }
...@@ -67,8 +59,6 @@ void freeIntList(int *list) ...@@ -67,8 +59,6 @@ void freeIntList(int *list)
void hitBall() void hitBall()
{ {
<<<<<<< HEAD
=======
// printf("map edges: %d %d\n", BLOCK_SIZE * MAP_WIDTH/2, BLOCK_SIZE *MAP_HEIGHT/2); // 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]); // printf("ray1: %d %d\n", ray1[0], ray1[1]);
int fermetureAngle = 2; int fermetureAngle = 2;
...@@ -82,7 +72,6 @@ void hitBall() ...@@ -82,7 +72,6 @@ void hitBall()
//printf("angle min: %d\n", angleMin); //printf("angle min: %d\n", angleMin);
//printf("angle max: %d\n", angleMax); //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); //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) if (sqrt(pow(player.x - ball.x, 2) + pow(player.y - ball.y, 2)) / BLOCK_SIZE < HIT_RANGE)
{ {
int rxWall, ryWall; int rxWall, ryWall;
...@@ -93,47 +82,39 @@ void hitBall() ...@@ -93,47 +82,39 @@ void hitBall()
if (player.isHitting) if (player.isHitting)
{ {
castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet); castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet);
//printf("rayWall: %d %d\n", rxWall/BLOCK_SIZE, ryWall/BLOCK_SIZE); printf("rayWall: %d %d\n", rxWall/BLOCK_SIZE, ryWall/BLOCK_SIZE);
//printf("distanceWall: %f\n", distanceWall); 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)
{
if (player.isHitting)
=======
printf("rayNet: %d %d\n", rxNet/BLOCK_SIZE, ryNet/BLOCK_SIZE); printf("rayNet: %d %d\n", rxNet/BLOCK_SIZE, ryNet/BLOCK_SIZE);
printf("distanceNet: %f\n", distanceNet); printf("distanceNet: %f\n", distanceNet);
// printf("hit\n"); // printf("hit\n");
if (rxWall > MAP_WIDTH/2) if (rxWall > MAP_WIDTH/2)
>>>>>>> 0383eb7e8ec1fcd92d8fd2c6846d5e9ab2d08f17
{ {
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[0] = ball.x;
lastHitPoint[1] = player.h; lastHitPoint[1] = player.h;
/*ball.x = player.x;
ball.y = player.y;
ball.z = player.h;*/
ball.angle = player.angle; ball.angle = player.angle;
ball.speed = 2 * HIT_FORCE; ball.speed = 2 * HIT_FORCE;
ball.z = player.h; ball.z = player.h;
ball.isHit = 1; ball.isHit = 1;
} }
// printf("valid hit\n");
} }
else else
{ {
// printf("unvalid hit\n"); // printf("unvalid hit\n");
} }
} }
//}
} }
void updateBall() void updateBall()
...@@ -142,7 +123,6 @@ void updateBall() ...@@ -142,7 +123,6 @@ void updateBall()
ball.y = ball.y + ball.speed * sin(ball.angle); ball.y = ball.y + ball.speed * sin(ball.angle);
if (ball.isHit) if (ball.isHit)
{ {
// landingPoint est déjà / BLOCK_SIZE de base // 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); 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) if (ball.z > 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment