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.

52 lines
1.3 KiB

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 = ((uint8_t*)MAP.collision_ptr)[y * MAP.map_width + x];
  11. return coll & COLLF_WALK;
  12. }
  13. uint8_t get_tile_coord(uint8_t pixel_coord) {
  14. uint8_t offset = 0;
  15. if (pixel_coord & 0x7) {
  16. offset = 8;
  17. }
  18. return (pixel_coord + offset) >> 3;
  19. }
  20. uint8_t player_bg_collides(void) {
  21. const int8_t map_x = get_tile_coord(PLAYER.x) + MAP.camera_x;
  22. if (map_x < 0 || map_x + 1 >= MAP.map_width) {
  23. return 1;
  24. }
  25. const int8_t map_y = get_tile_coord(PLAYER.y_hi) + MAP.camera_y;
  26. if (map_y < 0 || map_y + 1 >= MAP.map_height) {
  27. return 1;
  28. }
  29. return !(can_move_to(map_x, map_y) && can_move_to(map_x + 1, map_y) &&
  30. can_move_to(map_x, map_y + 1) &&
  31. can_move_to(map_x + 1, map_y + 1));
  32. }
  33. uint8_t player_in_air(void) {
  34. const int8_t x = get_tile_coord(PLAYER.x) + MAP.camera_x;
  35. if (x < 0 || x + 1 >= MAP.map_width) {
  36. return 0;
  37. }
  38. const int8_t y = get_tile_coord(PLAYER.y_hi) + MAP.camera_y;
  39. if (y < 0 || y + 2 >= MAP.map_height) {
  40. return 0;
  41. }
  42. return can_move_to(x, y + 2) && can_move_to(x + 1, y + 2);
  43. }