#include "collide.h" #include "draw.h" #include "shared_define.h" #define SPIKE_SCAM 2 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_H)/16) * LEVEL_WIDTH] == tile) || (level[(int)((x+PLAYER_W)/16) + (int)((y+PLAYER_H)/16) * LEVEL_WIDTH] == tile) || (level[(int)((x+PLAYER_W)/16) + (int)(y/16) * LEVEL_WIDTH] == tile)) return 1; return 0; } char collide_spike(int x, int y, char level[]) { return (collide_point(x + SPIKE_SCAM, y + SPIKE_SCAM, level, 'v') || collide_point(x + PLAYER_W - SPIKE_SCAM, y + SPIKE_SCAM, level, 'v') || collide_point(x + SPIKE_SCAM, y + PLAYER_H - SPIKE_SCAM, level, 'v') || collide_point(x + PLAYER_W - SPIKE_SCAM, y + PLAYER_H - SPIKE_SCAM, level, 'v')); } 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[], char polarity, char test_semi_solid) { char collided; if (polarity) collided = collide(x, y, level, 'b'); else collided = collide(x, y, level, 'r'); if (!collided && test_semi_solid && ((y + PLAYER_H) % 16) <= 5) { collided = (collide_point(x, y + PLAYER_H, level, '/') || collide_point(x + PLAYER_W, y + PLAYER_H, level, '/')); } return (collided || collide(x, y, level, '0') || collide(x, y, level, '1') || collide(x, y, level, '^') || collide(x, y, level, 'd') || 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 + PLAYER_W, y, level, tile)) { erase_tile(x + PLAYER_W, y, level); collided = 1; } if (collide_point(x, y + PLAYER_H, level, tile)) { erase_tile(x, y + PLAYER_H, level); collided = 1; } if (collide_point(x + PLAYER_W, y + PLAYER_H, level, tile)) { erase_tile(x + PLAYER_W, y + PLAYER_H, level); collided = 1; } return collided; }