summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--map.c14
-rw-r--r--sdl3_main.c19
2 files changed, 33 insertions, 0 deletions
diff --git a/map.c b/map.c
new file mode 100644
index 0000000..8c12514
--- /dev/null
+++ b/map.c
@@ -0,0 +1,14 @@
+int map_width = 8;
+int map_height = 8;
+
+char map_data[] = {
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 0, 0, 0, 0, 0,
+ 0, 1, 1, 0, 0, 0, 0, 0,
+ 0, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 1, 0,
+ 0, 0, 0, 0, 0, 1, 1, 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,
+};
diff --git a/sdl3_main.c b/sdl3_main.c
index 26b447d..1bb4a89 100644
--- a/sdl3_main.c
+++ b/sdl3_main.c
@@ -45,6 +45,9 @@ static float camera_x, camera_y;
static bool shot;
static int shotx, shoty;
+extern char map_data[];
+extern int map_width, map_height;
+
int
main()
{
@@ -114,6 +117,20 @@ render(void)
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
SDL_RenderClear(renderer);
+ SDL_SetRenderDrawColor(renderer, 0xAA, 0xAA, 0xAA, 0xFF);
+ for(int y = 0; y < map_height; y++)
+ for(int x = 0; x < map_width; x++) {
+ if(!map_data[x + map_width * y])
+ continue;
+
+ SDL_RenderFillRect(renderer, &(SDL_FRect) {
+ .x = 2 * ENTITY_SIZE * x - ENTITY_SIZE - camera_x,
+ .y = 2 * ENTITY_SIZE * y - ENTITY_SIZE - camera_y,
+ .w = 2.0 * ENTITY_SIZE,
+ .h = 2.0 * ENTITY_SIZE,
+ });
+ }
+
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderRect(renderer, &(SDL_FRect){
.x = player.x - ENTITY_SIZE - camera_x,
@@ -188,6 +205,7 @@ update(float delta)
}
}
+
for(int i = 0; i < 1024; i++) {
if(!bullet[i].active)
continue;
@@ -305,3 +323,4 @@ checkcollision(float p1[2], float s1[2], float p2[2], float s2[2])
return minx < 0 && maxx > 0 && miny < 0 && maxy > 0;
}
+