momento/src/level/draw.c

28 lines
712 B
C
Raw Normal View History

2021-03-28 19:35:07 +02:00
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright (C) 2021 KikooDX */
#include "conf.h"
#include "level.h"
#include <libimg.h>
2021-03-28 19:35:07 +02:00
extern struct Level level;
extern img_t const img_tileset;
2021-03-28 19:35:07 +02:00
void level_draw(void)
{
int x;
int y;
const int tileset_width = img_tileset.width / TILE_WIDTH;
2021-03-28 19:35:07 +02:00
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,
2021-03-28 19:35:07 +02:00
(int)(tile % tileset_width) * TILE_WIDTH,
(int)(tile / tileset_width) * TILE_HEIGHT,
TILE_WIDTH, TILE_HEIGHT), draw_x, draw_y);
2021-03-28 19:35:07 +02:00
}
}