momento/src/level/draw.c

50 lines
1.1 KiB
C

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright (C) 2021 KikooDX */
#include "conf.h"
#include "level.h"
#include "tiles.h"
#include <gint/display.h>
extern struct Level level;
extern const bopti_image_t bimg_tileset;
void level_draw(void)
{
int x;
int y;
const int tileset_width = bimg_tileset.width / TILE_WIDTH;
y = level.height;
while (y-- > 0) {
const int draw_y = y * TILE_HEIGHT;
x = level.width;
while (x-- > 0) {
const int draw_x = x * TILE_WIDTH;
const int tile_index = x + y * level.width;
const Tile tile = level.data[tile_index];
switch (tile) {
case TILE_VOID:
break;
case TILE_SOLID: {
const int autotile =
level.autotiling[tile_index];
dsubimage(draw_x, draw_y, &bimg_tileset,
autotile, TILE_HEIGHT,
TILE_WIDTH, TILE_HEIGHT,
DIMAGE_NOCLIP);
} break;
default:
dsubimage(draw_x, draw_y, &bimg_tileset,
(int)(tile % tileset_width) *
TILE_WIDTH,
(int)(tile / tileset_width) *
TILE_HEIGHT,
TILE_WIDTH, TILE_HEIGHT,
DIMAGE_NOCLIP);
break;
}
}
}
}