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

2 years ago
2 years ago
2 years ago
2 years ago
  1. #include "game.h"
  2. #include "map.h"
  3. #include "player.h"
  4. typedef enum {
  5. COLLF_WALK = (1 << 0),
  6. COLLF_LADDER = (1 << 1),
  7. COLLF_PORTAL = (1 << 2),
  8. } coll_state_t;
  9. uint8_t can_move_to(uint8_t x, uint8_t y) {
  10. const uint8_t coll =
  11. ((uint8_t*)MAP.collision_ptr)[y * (MAP.map_width + 1) + x];
  12. return coll & COLLF_WALK;
  13. }
  14. uint8_t get_tile_coord(uint8_t pixel_coord) {
  15. uint8_t offset = 0;
  16. if (pixel_coord & 0x7) {
  17. offset = 8;
  18. }
  19. return (pixel_coord + offset) >> 3;
  20. }
  21. uint8_t player_bg_collides(void) {
  22. const int8_t map_x = PLAYER.x / 8 + MAP.camera_x;
  23. if (map_x < 0 || map_x + 1 >= MAP.map_width) {
  24. return 1;
  25. }
  26. const int8_t map_y = PLAYER.y_hi / 8 + MAP.camera_y;
  27. if (map_y < 0 || map_y + 1 >= MAP.map_height) {
  28. return 1;
  29. }
  30. return !(can_move_to(map_x, map_y) && can_move_to(map_x + 1, map_y) &&
  31. can_move_to(map_x, map_y + 1) &&
  32. can_move_to(map_x + 1, map_y + 1));
  33. }
  34. uint8_t player_in_air(void) {
  35. const int8_t x = get_tile_coord(PLAYER.x) + MAP.camera_x;
  36. if (x < 0 || x + 1 >= MAP.map_width) {
  37. return 0;
  38. }
  39. const int8_t y = get_tile_coord(PLAYER.y_hi) + MAP.camera_y;
  40. if (y < 0 || y + 2 >= MAP.map_height) {
  41. return 0;
  42. }
  43. return can_move_to(x, y + 2) && can_move_to(x + 1, y + 2);
  44. }