~kikoodx/painfull-success-cg

7e86c32bba96649b7729fd34e42899d765b6d338 — KikooDX 1 year, 6 months ago 429dfee main
replace rectangles drawing with tileset
8 files changed, 18 insertions(+), 49 deletions(-)

M .gitignore
M CMakeLists.txt
A assets/graphics/fxconv-metadata.txt
A assets/graphics/tileset.png
M include/tiles.h
M src/level.c
M src/main.c
D src/tiles.c
M .gitignore => .gitignore +3 -0
@@ 17,3 17,6 @@ backup_*.kble

# Generated C files.
gen_*.c

# Krita backup files
*.png~

M CMakeLists.txt => CMakeLists.txt +3 -3
@@ 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)


A assets/graphics/fxconv-metadata.txt => assets/graphics/fxconv-metadata.txt +3 -0
@@ 0,0 1,3 @@
tileset.png:
  type: bopti-image
  name: bimg_tileset

A assets/graphics/tileset.png => assets/graphics/tileset.png +0 -0
M include/tiles.h => include/tiles.h +0 -2
@@ 19,5 19,3 @@ enum {
	CHECKY_TILE,
};
#define OUT_OF_BOUNDS AIR_TILE

u32 tile_color(tile_t tile);

M src/level.c => src/level.c +7 -3
@@ 13,9 13,12 @@
#include <gint/display.h>
#include <gint/std/string.h>

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;
		}

M src/main.c => src/main.c +2 -2
@@ 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. */

D src/tiles.c => src/tiles.c +0 -39
@@ 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 <gint/display.h>

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;
}