2020-06-26 19:08:51 +02:00
|
|
|
#include "collide.h"
|
2020-06-27 14:47:58 +02:00
|
|
|
#include "define.h"
|
2020-06-26 19:08:51 +02:00
|
|
|
|
2020-06-29 22:31:30 +02:00
|
|
|
void collide(int x, int y, char level[], char gravity, int *hor, int *vert, char block) //detect if a block is colliding when changing gravity
|
2020-06-26 19:08:51 +02:00
|
|
|
{
|
2020-06-29 22:31:30 +02:00
|
|
|
if((level[(int)(x/16)+(int)((y-1)/16*25)] == block ||
|
|
|
|
level[(int)((x+PLAYER_HEIGHT-1)/16)+(int)((y-1)/16*25)] == block) && gravity) //return true if player is touching a block on the bottom of him
|
2020-06-26 19:08:51 +02:00
|
|
|
{
|
2020-06-29 22:31:30 +02:00
|
|
|
*vert=1;
|
2020-06-26 19:08:51 +02:00
|
|
|
}
|
2020-06-29 22:31:30 +02:00
|
|
|
else if((level[(int)(x/16)+(int)((y+PLAYER_HEIGHT)/16*25)] == block ||
|
|
|
|
level[(int)((x+PLAYER_HEIGHT-1)/16)+(int)((y+PLAYER_HEIGHT)/16*25)] == block) && !gravity) //return true if player is touching a block on top of him
|
2020-06-27 02:16:38 +02:00
|
|
|
{
|
2020-06-29 22:31:30 +02:00
|
|
|
*vert=1;
|
2020-06-27 02:16:38 +02:00
|
|
|
}
|
2020-06-29 22:31:30 +02:00
|
|
|
else *vert=0;
|
|
|
|
|
|
|
|
if(level[(int)((x+PLAYER_HEIGHT)/16)+(int)(y/16*25)] == block ||
|
|
|
|
level[(int)((x+PLAYER_HEIGHT)/16)+(int)((y+PLAYER_HEIGHT-1)/16*25)] == block) //return if player is next to a block on his right
|
2020-06-27 14:47:58 +02:00
|
|
|
{
|
2020-06-29 22:31:30 +02:00
|
|
|
*hor=1;
|
2020-06-27 14:47:58 +02:00
|
|
|
}
|
2020-06-29 22:31:30 +02:00
|
|
|
else if(level[(int)((x-1)/16)+(int)(y/16*25)] == block ||
|
|
|
|
level[(int)((x-1)/16)+(int)((y+PLAYER_HEIGHT-1)/16*25)] == block) //return if player is next to a block on his left
|
2020-06-27 14:47:58 +02:00
|
|
|
{
|
2020-06-29 22:31:30 +02:00
|
|
|
*hor=2;
|
2020-06-27 14:47:58 +02:00
|
|
|
}
|
2020-06-29 22:31:30 +02:00
|
|
|
else *hor=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void collide_solid(int x, int y, char level[], char gravity, int *hor, int *vert)
|
|
|
|
{
|
|
|
|
collide(x, y, level, gravity, hor, vert, '2'); //Truc étrange ici, les blocs 2 (rouges) agissent bizarrement
|
|
|
|
if(!*vert || !*hor) collide(x, y, level, gravity, hor, vert, '1');
|
2020-06-27 14:47:58 +02:00
|
|
|
}
|