diff --git a/CMakeLists.txt b/CMakeLists.txt index 37d27d8..ae4d218 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,8 +15,10 @@ find_package(Gint 2.1 REQUIRED) set(SOURCES src/main.c - src/player.c src/input.c + src/level.c + src/player.c + src/tiles.c src/gen_levels.c # ... ) diff --git a/include/conf.h b/include/conf.h index 455717d..824bb9d 100644 --- a/include/conf.h +++ b/include/conf.h @@ -6,3 +6,5 @@ #define LEVEL_WIDTH 16 #define LEVEL_HEIGHT 16 #define LEVEL_SIZE (LEVEL_WIDTH * LEVEL_HEIGHT) +#define DRAW_OFFSET_X 70 +#define DRAW_OFFSET_Y 0 diff --git a/include/level.h b/include/level.h index 9cad609..4a8ca8f 100644 --- a/include/level.h +++ b/include/level.h @@ -1,10 +1,12 @@ #pragma once #include #include "conf.h" +#include "tiles.h" #include "vec2.h" -typedef uint8_t tile_t; typedef struct Level{ tile_t content[LEVEL_WIDTH * LEVEL_HEIGHT]; Vec2 start_pos; } Level; + +void level_draw(Level level); diff --git a/include/tiles.h b/include/tiles.h index e4b1a43..d97b396 100644 --- a/include/tiles.h +++ b/include/tiles.h @@ -1,5 +1,6 @@ #pragma once +typedef uint8_t tile_t; enum { AIR_TILE, SOLID_TILE, @@ -11,3 +12,5 @@ enum { CHECKY_TILE, }; #define OUT_OF_BOUNDS AIR_TILE + +int tile_color(tile_t tile); diff --git a/src/level.c b/src/level.c new file mode 100644 index 0000000..686f0f5 --- /dev/null +++ b/src/level.c @@ -0,0 +1,25 @@ +#include +#include "level.h" +#include "tiles.h" + +void level_draw(Level level) { + /* Pixel position (where we draw). */ + uint16_t x = DRAW_OFFSET_X; + uint16_t y = DRAW_OFFSET_Y; + /* Cursor position. */ + uint16_t cx = 0; + while (cx < LEVEL_WIDTH) { + uint16_t cy = 0; + while (cy < LEVEL_HEIGHT) { + const tile_t tile = level.content[cy * LEVEL_WIDTH + cx]; + const int color = tile_color(tile); + drect(x, y, x + TILE_SIZE - 1, y + TILE_SIZE - 1, color); + y += TILE_SIZE; + cy += 1; + } + y = DRAW_OFFSET_Y; + x += TILE_SIZE; + cx += 1; + } +} + diff --git a/src/main.c b/src/main.c index f90dcce..6211d06 100644 --- a/src/main.c +++ b/src/main.c @@ -52,6 +52,7 @@ int main(void) { /* Draw. */ dclear(C_BLACK); /* player_draw(player); */ + level_draw(level); dupdate(); } diff --git a/src/tiles.c b/src/tiles.c new file mode 100644 index 0000000..aaf6aec --- /dev/null +++ b/src/tiles.c @@ -0,0 +1,16 @@ +#include +#include "tiles.h" + +int tile_color(tile_t tile) { + int color = 0; + switch (tile) { + case AIR_TILE: color = C_RGB(0, 0, 0); break; + case SOLID_TILE: color = C_RGB(10, 210, 180); break; + case PAIN_TILE: color = C_RGB(210, 10, 180); break; + case SPAWN_TILE: color = C_RGB(20, 220, 20); break; + case EXIT_TILE: color = C_RGB(250, 220, 10); break; + case KEY_TILE: color = C_RGB(210, 210, 210); break; + case SEMI_SOLID: color = C_RGB(5, 105, 90); break; + } + return color; +}