mirror of https://git.sr.ht/~kikoodx/crystal-tower
51 lines
961 B
C
51 lines
961 B
C
#include "level.h"
|
|
#include "conf.h"
|
|
#include <gint/display.h>
|
|
#include <stdlib.h>
|
|
|
|
struct Level
|
|
level_load(struct LevelBin *restrict s)
|
|
{
|
|
struct Level level;
|
|
int i = s->width * s->height;
|
|
level.width = s->width;
|
|
level.height = s->height;
|
|
level.data = malloc(i);
|
|
while (i-- > 0) {
|
|
level.data[i] = s->data[i];
|
|
}
|
|
return level;
|
|
}
|
|
|
|
void
|
|
level_free(struct Level *restrict s)
|
|
{
|
|
free(s->data);
|
|
}
|
|
|
|
void
|
|
level_draw(struct Level *restrict s)
|
|
{
|
|
extern bopti_image_t bimg_tileset;
|
|
const int tileset_width = bimg_tileset.width / TILE_SIZE;
|
|
int i;
|
|
int x = 0;
|
|
int y = 0;
|
|
|
|
for (i = 0; i < s->width * s->height; i++) {
|
|
const int sx = x * TILE_SIZE;
|
|
const int sy = y * TILE_SIZE;
|
|
const int tile = s->data[i];
|
|
const int rx = tile % tileset_width * TILE_SIZE;
|
|
const int ry = tile / tileset_width * TILE_SIZE;
|
|
|
|
dsubimage(sx, sy, &bimg_tileset, rx, ry, TILE_SIZE, TILE_SIZE,
|
|
DIMAGE_NONE);
|
|
|
|
if (++x >= s->width) {
|
|
x = 0;
|
|
y++;
|
|
}
|
|
}
|
|
}
|