Skip to content
Snippets Groups Projects
Commit 3a18f0ff authored by antoinemeyer5's avatar antoinemeyer5
Browse files

fix collisions

parent 242365cb
No related branches found
No related tags found
No related merge requests found
......@@ -35,10 +35,10 @@ 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;
......@@ -72,16 +72,17 @@ void hitBall()
float distanceNet;
if (player.isHitting)
{
castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet);
castSingleRay(player.angle, &distanceWall, &distanceNet, &rxWall, &ryWall, &rxNet, &ryNet);
// printf("hit\n");
if (rxWall > MAP_WIDTH/2)
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]);
......@@ -144,9 +145,10 @@ void manageMovement()
// d : keys[3] : droite
float x_increment = (Keys[0] - Keys[2]) * player.deltax + (Keys[3] - Keys[1]) * sin(player.angle);
float y_increment = (Keys[0] - Keys[2]) * player.deltay + (Keys[1] - Keys[3]) * cos(player.angle);
float newpos_x = (player.x + x_increment) / BLOCK_SIZE;
float newpos_y = (player.y + y_increment) / BLOCK_SIZE;
if (newpos_x >= 0 && newpos_x < MAP_WIDTH && newpos_y >= 0 && newpos_y < MAP_HEIGHT)
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 (map[(int)newpos_y][(int)newpos_x] != 1)
{
......@@ -154,8 +156,6 @@ void manageMovement()
player.y += y_increment * MOVEMENT_SPEED;
}
}
printf("newpos_x:%f, newpos_y:%f - ", newpos_x, newpos_y);
printf("pX:%f, pY:%f\n", player.x, player.y);
}
void managePlayer()
......
......@@ -11,7 +11,7 @@
#define ENTITIES_RIGHT 3
#define HIT_RANGE 2
#define HIT_FORCE 20
#define HIT_FORCE 10
#define MOVEMENT_SPEED 20
typedef struct player{
......
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