diff options
author | kdx <kikoodx@paranoici.org> | 2023-03-17 21:07:07 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-03-17 21:08:01 +0100 |
commit | 1ae914f3baf48d199985bb34c55e6b7159dfdb76 (patch) | |
tree | 01a50b77c143646429792d8760e2395dd834d0d0 | |
parent | 127299656cb1de29a6deffb6f982bbfcecd64d2e (diff) | |
download | hyperultra-1ae914f3baf48d199985bb34c55e6b7159dfdb76.tar.gz |
second level
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | map/01.json | 1 | ||||
-rw-r--r-- | src/game.c | 6 | ||||
-rw-r--r-- | src/game.h | 1 | ||||
-rw-r--r-- | src/map.c | 22 | ||||
-rw-r--r-- | src/map.h | 1 | ||||
-rw-r--r-- | src/player.c | 3 |
7 files changed, 33 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b29e1f..807d626 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ find_package(Gint 2.9 REQUIRED) set(SOURCES src/background.c src/entity.c + src/exit.c src/input.c src/game.c src/lzy.c diff --git a/map/01.json b/map/01.json new file mode 100644 index 0000000..88edf18 --- /dev/null +++ b/map/01.json @@ -0,0 +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,0,0,0,0,1,1,1,1,0,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,0,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,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,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,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,1,1,0,0,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 @@ -21,6 +21,12 @@ game_deinit(Game *this) void game_update(Game *this) { + if (this->queue_next_scene) { + this->queue_next_scene = false; + map_next(); + game_restart_scene(this); + return; + } for (int i = 0; i < MAX_ENTITIES; i++) { Entity *const e = &this->entities[i]; if (e->type != ET_NONE && e->update != NULL) @@ -5,6 +5,7 @@ enum { MAX_ENTITIES = 64 }; typedef struct Game { unsigned int uuid; + bool queue_next_scene; Entity entities[MAX_ENTITIES]; } Game; @@ -2,6 +2,24 @@ #include "lzy.h" #include "cfg.h" #include "00.h" +#include "01.h" +#include <stddef.h> + +unsigned char *maps[] = { + map_00_json.data, + map_01_json.data, + NULL +}; +unsigned int map_id = 0; + +void +map_next(void) +{ + if (maps[map_id + 1] != NULL) + map_id += 1; + else + map_id = 0; +} int map_width(void) @@ -20,7 +38,7 @@ map_get(int x, int y) { if (x < 0 || y < 0 || x >= map_00_json.width || y >= map_00_json.height) return 0; - return map_00_json.data[x + y * map_00_json.width]; + return maps[map_id][x + y * map_00_json.width]; } int @@ -36,7 +54,7 @@ map_draw(void) { for (int y = 0; y < 14; y++) for (int x = 0; x < map_00_json.width; x++) - if (map_00_json.data[x + y * map_00_json.width] == 1) { + if (maps[map_id][x + y * map_00_json.width] == 1) { LZY_DrawSetColor(BLACK); LZY_DrawTile(2, x * 16, y * 16); } @@ -1,5 +1,6 @@ #pragma once +void map_next(void); int map_width(void); int map_height(void); int map_get(int x, int y); diff --git a/src/player.c b/src/player.c index 32f4f6f..c729085 100644 --- a/src/player.c +++ b/src/player.c @@ -48,6 +48,9 @@ player_update(Entity *this, Game *g) entity_move(this, g); if (this->vel[0] == 0.0 && this->vel[1] >= -0.0) this->player.dirx *= -1; + + if (entity_place_meeting(this, g, ET_EXIT) != NULL) + g->queue_next_scene = true; } static void |