lol its in c
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.
 
 
 
 

53 lines
1.3 KiB

#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 + 1) + 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 = PLAYER.x / 8 + MAP.camera_x;
if (map_x < 0 || map_x + 1 >= MAP.map_width) {
return 1;
}
const int8_t map_y = PLAYER.y_hi / 8 + 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);
}