diff --git a/.gitignore b/.gitignore index 3f21bab..0f66025 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ backup_*.kble # Generated C files. gen_*.c + +# Krita backup files +*.png~ diff --git a/CMakeLists.txt b/CMakeLists.txt index d452397..d10a8c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,12 +31,12 @@ set(SOURCES src/input.c src/level.c src/player.c - src/tiles.c src/gen_levels.c - # ... ) -set(ASSETS) +set(ASSETS + assets/graphics/tileset.png +) set(FLAGS -Wall -Wextra -Os -std=c99) diff --git a/assets/graphics/fxconv-metadata.txt b/assets/graphics/fxconv-metadata.txt new file mode 100644 index 0000000..8134606 --- /dev/null +++ b/assets/graphics/fxconv-metadata.txt @@ -0,0 +1,3 @@ +tileset.png: + type: bopti-image + name: bimg_tileset diff --git a/assets/graphics/tileset.png b/assets/graphics/tileset.png new file mode 100644 index 0000000..164f1bb Binary files /dev/null and b/assets/graphics/tileset.png differ diff --git a/include/tiles.h b/include/tiles.h index f906b74..90e5923 100644 --- a/include/tiles.h +++ b/include/tiles.h @@ -19,5 +19,3 @@ enum { CHECKY_TILE, }; #define OUT_OF_BOUNDS AIR_TILE - -u32 tile_color(tile_t tile); diff --git a/src/level.c b/src/level.c index 706803a..6302216 100644 --- a/src/level.c +++ b/src/level.c @@ -13,9 +13,12 @@ #include #include +extern bopti_image_t bimg_tileset; + void level_draw(Level level, i16 y_offset) { + const int tileset_width = bimg_tileset.width / TILE_SIZE; /* Pixel position (where we draw). */ i32 x = DRAW_OFFSET_X; i16 y = y_offset; @@ -26,9 +29,10 @@ level_draw(Level level, i16 y_offset) while (cy < LEVEL_HEIGHT) { const tile_t tile = level.content[cy * LEVEL_WIDTH + cx]; - const u32 color = tile_color(tile); - drect(x, y, x + TILE_SIZE - 1, y + TILE_SIZE - 1, - color); + dsubimage(x, y, &bimg_tileset, + (int)(tile % tileset_width) * TILE_SIZE, + (int)(tile / tileset_width) * TILE_SIZE, + TILE_SIZE, TILE_SIZE, DIMAGE_NOCLIP); y += TILE_SIZE; cy += 1; } diff --git a/src/main.c b/src/main.c index 7f43f66..871a022 100644 --- a/src/main.c +++ b/src/main.c @@ -39,8 +39,8 @@ main(void) /* UPS control. */ volatile int has_ticked = true; - int timer = - timer_configure(TIMER_ANY, 1000000 / TARGET_UPS, GINT_CALL(callback, &has_ticked)); + int timer = timer_configure(TIMER_ANY, 1000000 / TARGET_UPS, + GINT_CALL(callback, &has_ticked)); timer_start(timer); /* Core loop. */ diff --git a/src/tiles.c b/src/tiles.c deleted file mode 100644 index d5f4d24..0000000 --- a/src/tiles.c +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: MIT - * Copyright (c) 2021 KikooDX - * This file is part of - * [Painfull Success CG](https://git.sr.ht/~kikoodx/painfull-success-cg), - * which is MIT licensed. The MIT license requires this copyright notice to be - * included in all copies and substantial portions of the software. */ -#include "tiles.h" -#include "lazyint.h" -#include - -u32 -tile_color(tile_t tile) -{ - int color = 0; - switch (tile) { - case AIR_TILE: - color = C_RGB(0 / 8, 0 / 8, 0 / 8); - break; - case SOLID_TILE: - color = C_RGB(10 / 8, 210 / 8, 180 / 8); - break; - case PAIN_TILE: - color = C_RGB(210 / 8, 10 / 8, 180 / 8); - break; - case SPAWN_TILE: - color = C_RGB(20 / 8, 220 / 8, 20 / 8); - break; - case EXIT_TILE: - color = C_RGB(250 / 8, 220 / 8, 10 / 8); - break; - case KEY_TILE: - color = C_RGB(210 / 8, 210 / 8, 210 / 8); - break; - case SEMI_SOLID_TILE: - color = C_RGB(5 / 8, 105 / 8, 90 / 8); - break; - } - return color; -}