1
0
Fork 0
mirror of https://git.sr.ht/~kikoodx/momento synced 2024-06-11 04:17:07 +02:00
momento/src/level/draw.c
KikooDX 184498f947 Use libimg for drawing
This will come handy later on.
2021-05-06 13:48:22 +02:00

28 lines
712 B
C

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright (C) 2021 KikooDX */
#include "conf.h"
#include "level.h"
#include <libimg.h>
extern struct Level level;
extern img_t const img_tileset;
void level_draw(void)
{
int x;
int y;
const int tileset_width = img_tileset.width / TILE_WIDTH;
for (y = 0; y < level.height; y += 1)
for (x = 0; x < level.width; x += 1) {
const int draw_x = x * TILE_WIDTH;
const int draw_y = y * TILE_HEIGHT;
const Tile tile =
level.data[x + y * level.width];
img_render_vram(img_sub(img_tileset,
(int)(tile % tileset_width) * TILE_WIDTH,
(int)(tile / tileset_width) * TILE_HEIGHT,
TILE_WIDTH, TILE_HEIGHT), draw_x, draw_y);
}
}