Skip to content
Snippets Groups Projects
Commit 6ebc4c7e authored by antoinemeyer5's avatar antoinemeyer5
Browse files

remise en place des bonnes trajectoires aleatoires et dans la bonne direction

parent 4886f8fb
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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;
......
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