#include "game.h"
|
|
#include "map.h"
|
|
#include "player.h"
|
|
|
|
typedef enum {
|
|
COLLF_WALK = (1 << 0),
|
|
COLLF_LADDER = (1 << 1),
|
|
COLLF_PORTAL = (1 << 2),
|
|
} coll_state_t;
|
|
|
|
uint8_t can_move_to(uint8_t x, uint8_t y) {
|
|
const uint8_t coll = ((uint8_t*)MAP.collision_ptr)[y * MAP.map_width + x];
|
|
return coll & COLLF_WALK;
|
|
}
|
|
|
|
uint8_t get_tile_coord(uint8_t pixel_coord) {
|
|
uint8_t offset = 0;
|
|
if (pixel_coord & 0x7) {
|
|
offset = 8;
|
|
}
|
|
return (pixel_coord + offset) >> 3;
|
|
}
|
|
|
|
uint8_t player_bg_collides(void) {
|
|
const int8_t map_x = get_tile_coord(PLAYER.x) + MAP.camera_x;
|
|
if (map_x < 0 || map_x + 1 >= MAP.map_width) {
|
|
return 1;
|
|
}
|
|
|
|
const int8_t map_y = get_tile_coord(PLAYER.y_hi) + MAP.camera_y;
|
|
if (map_y < 0 || map_y + 1 >= MAP.map_height) {
|
|
return 1;
|
|
}
|
|
|
|
return !(can_move_to(map_x, map_y) && can_move_to(map_x + 1, map_y) &&
|
|
can_move_to(map_x, map_y + 1) &&
|
|
can_move_to(map_x + 1, map_y + 1));
|
|
}
|
|
|
|
uint8_t player_in_air(void) {
|
|
const int8_t x = get_tile_coord(PLAYER.x) + MAP.camera_x;
|
|
if (x < 0 || x + 1 >= MAP.map_width) {
|
|
return 0;
|
|
}
|
|
|
|
const int8_t y = get_tile_coord(PLAYER.y_hi) + MAP.camera_y;
|
|
if (y < 0 || y + 2 >= MAP.map_height) {
|
|
return 0;
|
|
}
|
|
|
|
return can_move_to(x, y + 2) && can_move_to(x + 1, y + 2);
|
|
}
|