friggin spikes

This commit is contained in:
KikooDX 2021-11-12 16:47:36 +01:00
parent 606fc1e8fb
commit 198aa97c7c
1 changed files with 50 additions and 1 deletions

View File

@ -17,6 +17,11 @@ static void death(void);
static int oob(int x, int y);
static int collide_tile(int x, int y, enum Tile);
static int collide_solid(int x, int y);
static int collide_spike(int x, int y);
static int collide_spike_right(int x, int y);
static int collide_spike_left(int x, int y);
static int collide_spike_down(int x, int y);
static int collide_spike_up(int x, int y);
void
player_init(struct Vec pos)
@ -78,7 +83,8 @@ player_update(void)
self.lock_direction = 0;
/* death */
if (oob(self.pos.x, self.pos.y)) {
if (oob(self.pos.x, self.pos.y) ||
collide_spike(self.pos.x, self.pos.y)) {
death();
return;
}
@ -216,6 +222,49 @@ collide_solid(int x, int y)
return collide_tile(x, y, TILE_SOLID);
}
static int
collide_spike(int x, int y)
{
return (self.spd.x <= 0.0f && collide_spike_right(x, y)) ||
(self.spd.x >= 0.0f && collide_spike_left(x, y)) ||
(self.spd.y <= 0.0f && collide_spike_down(x, y)) ||
(self.spd.y >= 0.0f && collide_spike_up(x, y));
}
static int
collide_spike_right(int x, int y)
{
const int y2 = y + PLAYER_HEIGHT - 1;
return x % TILE_SIZE == 0 && (level_get_px(x, y) == TILE_SPIKE_R ||
level_get_px(x, y2) == TILE_SPIKE_R);
}
static int
collide_spike_left(int x, int y)
{
const int y2 = y + PLAYER_HEIGHT - 1;
return x % TILE_SIZE == TILE_SIZE - PLAYER_WIDTH &&
(level_get_px(x, y) == TILE_SPIKE_L ||
level_get_px(x, y2) == TILE_SPIKE_L);
}
static int
collide_spike_down(int x, int y)
{
const int x2 = x + PLAYER_WIDTH - 1;
return y % TILE_SIZE == 0 && (level_get_px(x, y) == TILE_SPIKE_D ||
level_get_px(x2, y) == TILE_SPIKE_D);
}
static int
collide_spike_up(int x, int y)
{
const int x2 = x + PLAYER_WIDTH - 1;
return y % TILE_SIZE == TILE_SIZE - PLAYER_HEIGHT &&
(level_get_px(x, y) == TILE_SPIKE_U ||
level_get_px(x2, y) == TILE_SPIKE_U);
}
static int
oob(int x, int y)
{