Use gint.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
unnamed-platformer/src/collide.c

54 lines
1.3 KiB

#include "collide.h"
#include "draw.h"
#define PLAYER_SIDES 11
#define LEVEL_WIDTH 28
char collide(int x, int y, char level[], char tile)
{
if ((level[(int)(x/16) + (int)(y/16) * LEVEL_WIDTH] == tile) ||
(level[(int)(x/16) + (int)((y+PLAYER_SIDES)/16) * LEVEL_WIDTH] == tile) ||
(level[(int)((x+PLAYER_SIDES)/16) + (int)((y+PLAYER_SIDES)/16) *
LEVEL_WIDTH] == tile) || (level[(int)((x+PLAYER_SIDES)/16) + (int)(y/16) *
LEVEL_WIDTH] == tile)) return 1;
return 0;
}
char collide_point(int x, int y, char level[], char tile)
{
return (level[(int)(x/16) + (int)(y/16) * LEVEL_WIDTH] == tile);
}
char collide_solid(int x, int y, char level[])
{
return (collide(x, y, level, '0') ||
collide(x, y, level, '^') ||
collide(x, y, level, '~') ||
collide(x, y, level, '#'));
}
char collide_and_erase(int x, int y, char level[], char tile)
{
char collided = 0;
if (collide_point(x, y, level, tile))
{
erase_tile(x, y, level);
collided = 1;
}
if (collide_point(x + 11, y, level, tile))
{
erase_tile(x + 11, y, level);
collided = 1;
}
if (collide_point(x, y + 11, level, tile))
{
erase_tile(x, y + 11, level);
collided = 1;
}
if (collide_point(x + 11, y + 11, level, tile))
{
erase_tile(x + 11, y + 11, level);
collided = 1;
}
return collided;
}