wehfou/src/level.c

49 lines
816 B
C

#include "level.h"
#include "conf.h"
#include "levels_bin.h"
#include "lzy.h"
#include "player.h"
#include <stdint.h>
#include <stdlib.h>
static int width, height, id;
static uint8_t *data = NULL;
void level_deinit(void)
{
if (data != NULL) {
free(data);
data = NULL;
}
}
void level_load(int nid)
{
const uint8_t *const s = levels[nid].data;
width = s[3];
height = s[5];
data = calloc(width * height, sizeof(uint8_t));
id = nid;
for (int i = 0; i < width * height; i++)
data[i] = s[6 + i];
int px = 0, py = 0;
level_find(2, &px, &py);
player_init(px, py);
}
void level_find(int tile, int *x, int *y)
{
for (int i = 0; i < width * height; i++) {
if (data[i] == tile) {
if (x != NULL)
*x = i % width * TILE_SIZE;
if (y != NULL)
*y = i % height * TILE_SIZE;
return;
}
}
}