AST3_C/src/collide.c

34 lines
1.2 KiB
C
Raw Normal View History

#include "collide.h"
2020-06-27 14:47:58 +02:00
#include "define.h"
#include <gint/display.h>
int collide_vert(int x, int y, char level[], char gravity) //detect if a block is colliding when changing gravity
{
if((level[(int)(x/16)+(int)((y-1)/16*25)] != '0' ||
level[(int)((x+PLAYER_HEIGHT-1)/16)+(int)((y-1)/16*25)] != '0') && gravity) //return true if player is touching a block on top of him
{
2020-06-27 02:16:38 +02:00
return 1;
}
else if((level[(int)(x/16)+(int)((y+PLAYER_HEIGHT)/16*25)] != '0' ||
level[(int)((x+PLAYER_HEIGHT-1)/16)+(int)((y+PLAYER_HEIGHT)/16*25)] != '0') && !gravity) //return true if player is touching a block on the bottom of him
2020-06-27 02:16:38 +02:00
{
return 1;
2020-06-27 02:16:38 +02:00
}
else return 0;
}
2020-06-27 14:47:58 +02:00
int collide_hor(int x, int y, char level[]) //detect if a block is colliding with the player when going left or right
2020-06-27 14:47:58 +02:00
{
if(level[(int)((x+PLAYER_HEIGHT)/16)+(int)(y/16*25)] != '0' ||
level[(int)((x+PLAYER_HEIGHT)/16)+(int)((y+PLAYER_HEIGHT-1)/16*25)] != '0') //return if player is next to a block on his right
2020-06-27 14:47:58 +02:00
{
return 1;
}
else if(level[(int)((x-1)/16)+(int)(y/16*25)] != '0' ||
level[(int)((x-1)/16)+(int)((y+PLAYER_HEIGHT-1)/16*25)] != '0') //return if player is next to a block on his left
2020-06-27 14:47:58 +02:00
{
return 2;
}
else return 0;
}