summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-03-17 20:44:59 +0100
committerkdx <kikoodx@paranoici.org>2023-03-17 20:44:59 +0100
commitf7f7d4f9d1828a481841f18f0884a8bc223b3cfc (patch)
tree668fd31eb29ba7b9b048809114df39fa7337be64
parent1e02a6cf8a3acad1469eb7f3d718c54a4bb6cad3 (diff)
downloadhyperultra-f7f7d4f9d1828a481841f18f0884a8bc223b3cfc.tar.gz
spawn player from map
-rw-r--r--map/00.json2
-rw-r--r--res/tset.pngbin132 -> 236 bytes
-rw-r--r--src/game.c21
-rw-r--r--src/game.h1
-rw-r--r--src/main.c1
-rw-r--r--src/map.c14
-rw-r--r--src/map.h2
-rw-r--r--src/player.c6
-rw-r--r--src/player.h2
9 files changed, 42 insertions, 7 deletions
diff --git a/map/00.json b/map/00.json
index 2558349..57f5963 100644
--- a/map/00.json
+++ b/map/00.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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,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,1,1,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,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,1,1,1,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,0,0,0,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]} \ 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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,1,1,1,1,1,1,1,1,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,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,1,1,1,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,1,0,2,0,0,0,0,0,0,0,0,1,0,1,1,1,0,0,0,0,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]} \ No newline at end of file
diff --git a/res/tset.png b/res/tset.png
index b1d9e2f..481c648 100644
--- a/res/tset.png
+++ b/res/tset.png
Binary files differ
diff --git a/src/game.c b/src/game.c
index 7adbae0..ab1554c 100644
--- a/src/game.c
+++ b/src/game.c
@@ -1,11 +1,14 @@
#include "game.h"
#include "map.h"
+#include "player.h"
+#include "cfg.h"
#include <string.h>
void
game_init(Game *this)
{
memset(this, 0, sizeof(*this));
+ game_restart_scene(this);
}
void
@@ -35,6 +38,24 @@ game_draw(Game *this)
}
}
+void
+game_restart_scene(Game *this)
+{
+ memset(this->entities, 0, sizeof(this->entities));
+ for (int y = 0; y < map_height(); y++)
+ for (int x = 0; x < map_width(); x++) {
+ const int dx = x * TSIZE + TSIZE / 2;
+ const int dy = y * TSIZE + TSIZE / 2;
+ switch (map_get(x, y)) {
+ case 2:
+ player_init(game_create_entity(this), dx, dy);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
Entity *
game_create_entity(Game *this)
{
diff --git a/src/game.h b/src/game.h
index 185c89b..73406f7 100644
--- a/src/game.h
+++ b/src/game.h
@@ -12,4 +12,5 @@ void game_init(Game *this);
void game_deinit(Game *this);
void game_update(Game *this);
void game_draw(Game *this);
+void game_restart_scene(Game *this);
Entity *game_create_entity(Game *this);
diff --git a/src/main.c b/src/main.c
index be96629..f9ae592 100644
--- a/src/main.c
+++ b/src/main.c
@@ -22,7 +22,6 @@ int main(void)
return 1;
}
game_init(game);
- player_init(game_create_entity(game));
while (!LZY_ShouldQuit()) {
LZY_CycleEvents();
diff --git a/src/map.c b/src/map.c
index bcd40a0..6139473 100644
--- a/src/map.c
+++ b/src/map.c
@@ -4,6 +4,18 @@
#include "00.h"
int
+map_width(void)
+{
+ return map_00_json.width;
+}
+
+int
+map_height(void)
+{
+ return map_00_json.height;
+}
+
+int
map_get(int x, int y)
{
if (x < 0 || y < 0 || x >= map_00_json.width || y >= map_00_json.height)
@@ -26,6 +38,6 @@ map_draw(void)
for (int x = 0; x < map_00_json.width; x++)
if (map_00_json.data[x + y * map_00_json.width] == 1) {
LZY_DrawSetColor(BLACK);
- LZY_DrawTile(1, x * 16, y * 16);
+ LZY_DrawTile(2, x * 16, y * 16);
}
}
diff --git a/src/map.h b/src/map.h
index 344a48f..ec2ce04 100644
--- a/src/map.h
+++ b/src/map.h
@@ -1,5 +1,7 @@
#pragma once
+int map_width(void);
+int map_height(void);
int map_get(int x, int y);
int map_get_px(int x, int y);
void map_draw(void);
diff --git a/src/player.c b/src/player.c
index 3ff73f7..32f4f6f 100644
--- a/src/player.c
+++ b/src/player.c
@@ -68,11 +68,11 @@ player_draw(Entity *this, Game *g)
}
void
-player_init(Entity *this)
+player_init(Entity *this, int x, int y)
{
memset(this, 0, sizeof(*this));
- this->pos[0] = 32;
- this->pos[1] = 32;
+ this->pos[0] = x;
+ this->pos[1] = y;
this->type = ET_PLAYER;
this->update = player_update;
this->draw = player_draw;
diff --git a/src/player.h b/src/player.h
index 878b338..a492354 100644
--- a/src/player.h
+++ b/src/player.h
@@ -9,4 +9,4 @@ typedef struct {
struct Entity;
struct Game;
-void player_init(struct Entity *this);
+void player_init(struct Entity *this, int x, int y);