From a262d351465957eadba265f1c3976e202e5b768d Mon Sep 17 00:00:00 2001 From: kdx Date: Tue, 21 Mar 2023 21:29:20 +0100 Subject: hope this doesn't lag --- map/wakywakysnakysnake.json | 2 +- src/game.c | 14 +++++++++++++- src/game.h | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/map/wakywakysnakysnake.json b/map/wakywakysnakysnake.json index e2fbf09..d2c8e00 100644 --- a/map/wakywakysnakysnake.json +++ b/map/wakywakysnakysnake.json @@ -1 +1 @@ -{"width":25,"height":14,"data":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,5,0,0,0,1,1,1,1,5,0,0,0,0,0,0,0,0,2,0,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,5,0,0,0,0,0,4,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,5,0,0,1,1,1,1,1,1,1,5,0,0,0,0,0,5,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,0,0,5,1,1,5,0,0,0,0,0,0,0,0,0,0,5,1,1,1,1,5,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,0,0,5,0,0,1,1,0,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]} \ No newline at end of file +{"width":25,"height":14,"data":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,5,0,0,0,1,1,1,1,5,0,0,0,0,0,0,0,2,0,0,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,5,0,0,0,0,0,4,1,1,1,1,1,1,0,0,5,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,5,0,0,1,1,1,1,1,1,1,5,0,0,0,0,0,5,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,0,0,5,1,1,5,0,0,0,0,0,0,0,0,0,0,5,1,1,1,1,5,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,0,0,5,0,0,1,1,0,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]} \ No newline at end of file diff --git a/src/game.c b/src/game.c index 62726ca..877385a 100644 --- a/src/game.c +++ b/src/game.c @@ -10,6 +10,7 @@ void game_init(Game *this) { memset(this, 0, sizeof(*this)); + this->player_dir = 1; game_restart_scene(this); } @@ -28,6 +29,7 @@ game_update(Game *this) } if (this->queue_next_scene) { this->queue_next_scene = false; + this->player_dir = game_get_entity(this, ET_exit)->exit.dir; map_next(); game_restart_scene(this); return; @@ -61,7 +63,8 @@ game_restart_scene(Game *this) Entity *e; switch (map_get(x, y)) { case 2: - player_init(game_create_entity(this), dx, dy); + e = player_init(game_create_entity(this), dx, dy); + e->player.dirx = this->player_dir; break; case 3: case 4: @@ -100,3 +103,12 @@ game_entity_count(Game *this, unsigned int type) count += (this->entities[i].type == type); return count; } + +Entity * +game_get_entity(Game *this, unsigned int type) +{ + for (int i = 0; i < MAX_ENTITIES; i++) + if (this->entities[i].type == type) + return &this->entities[i]; + return NULL; +} diff --git a/src/game.h b/src/game.h index ebb5c09..001d467 100644 --- a/src/game.h +++ b/src/game.h @@ -7,6 +7,7 @@ typedef struct Game { unsigned int uuid; bool queue_next_scene; int queue_restart_scene; + int player_dir; Entity entities[MAX_ENTITIES]; } Game; @@ -17,3 +18,4 @@ void game_draw(Game *this); void game_restart_scene(Game *this); Entity *game_create_entity(Game *this); int game_entity_count(Game *this, unsigned int type); +Entity *game_get_entity(Game *this, unsigned int type); -- cgit v1.2.3