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"
|
2021-04-07 11:45:47 +02:00
|
|
|
#include <libimg.h>
|
2021-03-28 19:35:07 +02:00
|
|
|
|
|
|
|
extern struct Level level;
|
2021-04-07 11:45:47 +02:00
|
|
|
extern img_t const img_tileset;
|
2021-03-28 19:35:07 +02:00
|
|
|
|
|
|
|
void level_draw(void)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
2021-04-07 11:45:47 +02:00
|
|
|
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];
|
2021-04-07 11:45:47 +02:00
|
|
|
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,
|
2021-04-07 11:45:47 +02:00
|
|
|
TILE_WIDTH, TILE_HEIGHT), draw_x, draw_y);
|
2021-03-28 19:35:07 +02:00
|
|
|
}
|
|
|
|
}
|