replace rectangles drawing with tileset
This commit is contained in:
parent
429dfee085
commit
7e86c32bba
|
@ -17,3 +17,6 @@ backup_*.kble
|
|||
|
||||
# Generated C files.
|
||||
gen_*.c
|
||||
|
||||
# Krita backup files
|
||||
*.png~
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
tileset.png:
|
||||
type: bopti-image
|
||||
name: bimg_tileset
|
Binary file not shown.
After Width: | Height: | Size: 548 B |
|
@ -19,5 +19,3 @@ enum {
|
|||
CHECKY_TILE,
|
||||
};
|
||||
#define OUT_OF_BOUNDS AIR_TILE
|
||||
|
||||
u32 tile_color(tile_t tile);
|
||||
|
|
10
src/level.c
10
src/level.c
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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. */
|
||||
|
|
39
src/tiles.c
39
src/tiles.c
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue