diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-06-22 22:10:28 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-06-22 22:10:28 +0100 |
commit | 4a8127146eafd4fef5b478c1bf9f5a152c8c4cd5 (patch) | |
tree | 05b820a74bcaffa340eede419b3e1fe24059c477 /src | |
parent | 7723c5f8a9f0ea5345ebefecd31fe22f3601b32e (diff) | |
download | gold-mine-run-4a8127146eafd4fef5b478c1bf9f5a152c8c4cd5.tar.gz gold-mine-run-4a8127146eafd4fef5b478c1bf9f5a152c8c4cd5.zip |
Import entities from the map and spawn them
Diffstat (limited to 'src')
-rw-r--r-- | src/game.c | 1 | ||||
-rw-r--r-- | src/map.c | 15 | ||||
-rw-r--r-- | src/map.h | 5 | ||||
-rw-r--r-- | src/player.c | 4 | ||||
-rw-r--r-- | src/player.h | 2 |
5 files changed, 23 insertions, 4 deletions
@@ -82,7 +82,6 @@ void run_game() map_init(binary_stage_start); map_render(); - player_init(16, 128); player_draw(); timer_start(GAME_TIME_MAX, &clock_updated); @@ -4,6 +4,8 @@ #include "vga.h" #include "data.h" +#include "player.h" + #include "map.h" /* current map; set via map_init */ @@ -24,6 +26,19 @@ void map_init(const uint8_t map[]) /* gold is not 0xff */ if (gold[i] != 0xff) total_gold++; + + /* spawn entities, 0xff is the list terminator */ + for ( + const uint8_t *ent = map + MAP_W * MAP_H * 2; + *ent != 0xff; + ent += 4 + ) + switch (*ent) + { + case Player: + player_init(ent[1] * MAP_TILE_W, ent[2] * MAP_TILE_H, ent[3] & 1); + break; + } } void map_render() @@ -14,6 +14,11 @@ #define MAP_FIRST_BLOCKED 40 #define MAP_FIRST_DEADLY 100 +typedef enum +{ + Player = 0, +} EntityType; + void map_init(const uint8_t map[]); void map_render(); diff --git a/src/player.c b/src/player.c index 52595f4..a0b840f 100644 --- a/src/player.c +++ b/src/player.c @@ -69,9 +69,9 @@ static const Rect frames[2][6] = }, }; -void player_init(uint16_t start_x, uint8_t start_y) +void player_init(uint16_t start_x, uint8_t start_y, uint8_t start_dir) { - dir = DIR_RIGHT; + dir = start_dir; frame = FRAME_STANDING; delay = 0; jump = 0; diff --git a/src/player.h b/src/player.h index 56bbd22..a2a946c 100644 --- a/src/player.h +++ b/src/player.h @@ -1,7 +1,7 @@ #ifndef _PLAYER_H #define _PLAYER_H -void player_init(uint16_t start_x, uint8_t start_y); +void player_init(uint16_t start_x, uint8_t start_y, uint8_t start_dir); void player_update(); void player_erase(); |