Browse Source

replace rectangles drawing with tileset

main
KikooDX 1 month ago
parent
commit
7e86c32bba
8 changed files with 18 additions and 49 deletions
  1. +3
    -0
      .gitignore
  2. +3
    -3
      CMakeLists.txt
  3. +3
    -0
      assets/graphics/fxconv-metadata.txt
  4. BIN
      assets/graphics/tileset.png
  5. +0
    -2
      include/tiles.h
  6. +7
    -3
      src/level.c
  7. +2
    -2
      src/main.c
  8. +0
    -39
      src/tiles.c

+ 3
- 0
.gitignore View File

@ -17,3 +17,6 @@ backup_*.kble
# Generated C files.
gen_*.c
# Krita backup files
*.png~

+ 3
- 3
CMakeLists.txt View File

@ -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)


+ 3
- 0
assets/graphics/fxconv-metadata.txt View File

@ -0,0 +1,3 @@
tileset.png:
type: bopti-image
name: bimg_tileset

BIN
assets/graphics/tileset.png View File

Before After
Width: 112  |  Height: 16  |  Size: 548 B

+ 0
- 2
include/tiles.h View File

@ -19,5 +19,3 @@ enum {
CHECKY_TILE,
};
#define OUT_OF_BOUNDS AIR_TILE
u32 tile_color(tile_t tile);

+ 7
- 3
src/level.c View File

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


+ 2
- 2
src/main.c View File

@ -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. */


+ 0
- 39
src/tiles.c View File

@ -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…
Cancel
Save