From 7e86c32bba96649b7729fd34e42899d765b6d338 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Sat, 1 May 2021 02:43:10 +0200 Subject: [PATCH] replace rectangles drawing with tileset --- .gitignore | 3 +++ CMakeLists.txt | 6 ++--- assets/graphics/fxconv-metadata.txt | 3 +++ assets/graphics/tileset.png | Bin 0 -> 548 bytes include/tiles.h | 2 -- src/level.c | 10 ++++--- src/main.c | 4 +-- src/tiles.c | 39 ---------------------------- 8 files changed, 18 insertions(+), 49 deletions(-) create mode 100644 assets/graphics/fxconv-metadata.txt create mode 100644 assets/graphics/tileset.png delete mode 100644 src/tiles.c 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 0000000000000000000000000000000000000000..164f1bbaf748691fb8b45ad8864b3daae8c2c032 GIT binary patch literal 548 zcmV+<0^9wGP)OVv zMgO3-LEC~LD1wMK{efyr8LrOND z6h0C5YH~s0TT@Ro_|4=@gTGAHqLD?gnls&*Hcqs$lGXCUQ^KBnuB{QVWt|BTcRi)McyhEG;w6eiq|V@S*E6>rbSQ5lcQqh z{y$GWJu}^y?hJta)i6FMz_Aats$u+|8b<95Y%g$KX!(nh)7-b{)t2Tt2GctZ)B+W92=x@7-r+oJtldbGcKjrQ}gNBgnp*8v15fC30m m00mG00Scf13LroM)VIC)nF{9$ak1k70000 #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; -}