level module
This commit is contained in:
parent
c4ea9e75fa
commit
7157b827c5
|
@ -13,10 +13,12 @@ set(SOURCES
|
|||
src/main.c
|
||||
src/draw.c
|
||||
src/input.c
|
||||
src/level.c
|
||||
src/player.c
|
||||
)
|
||||
|
||||
set(ASSETS
|
||||
res/test.kble
|
||||
)
|
||||
|
||||
set(FLAGS -std=c99 -Os -Wall -Wextra -Wshadow)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
struct LevelBin {
|
||||
uint8_t format, chunk_size;
|
||||
uint16_t width, height;
|
||||
uint8_t data[];
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct Level {
|
||||
int width, height, size;
|
||||
const struct LevelBin *bin;
|
||||
uint8_t *data;
|
||||
};
|
||||
|
||||
void level_init(void);
|
||||
void level_deinit(void);
|
||||
|
||||
void level_load(const struct LevelBin *);
|
||||
void level_reload(void);
|
|
@ -0,0 +1,5 @@
|
|||
# https://git.sr.ht/~kikoodx/jle
|
||||
tileset = res/tileset.png
|
||||
tile_size = 16
|
||||
new_level_width = 25
|
||||
new_level_height = 14
|
|
@ -0,0 +1,3 @@
|
|||
*.kble:
|
||||
type: binary
|
||||
name_regex: (.*)\.kble kble_\1
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 119 B |
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
# https://sr.ht/~kikoodx/sle
|
||||
sle -tile-width 16 -tile-height 16 -level-width 25 -level-height 14 \
|
||||
-editor-width 396 -editor-height 224 -editor-off-x -2 -editor-off-y 0 \
|
||||
-editor-bg-color '#000000' -picker-bg-color '#000005' \
|
||||
-tileset res/tileset.png $@
|
|
@ -0,0 +1,47 @@
|
|||
#include "level.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static struct Level level;
|
||||
|
||||
static void level_free(void);
|
||||
|
||||
void
|
||||
level_init(void)
|
||||
{
|
||||
level.data = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
level_deinit(void)
|
||||
{
|
||||
level_free();
|
||||
}
|
||||
|
||||
void
|
||||
level_load(const struct LevelBin *b)
|
||||
{
|
||||
int i = b->width * b->height;
|
||||
level_free();
|
||||
level.width = b->width;
|
||||
level.height = b->height;
|
||||
level.size = i;
|
||||
level.data = malloc(i);
|
||||
level.bin = b;
|
||||
while (i-- > 0)
|
||||
level.data[i] = b->data[i];
|
||||
}
|
||||
|
||||
void
|
||||
level_reload(void)
|
||||
{
|
||||
level_load(level.bin);
|
||||
}
|
||||
|
||||
static void
|
||||
level_free(void)
|
||||
{
|
||||
if (level.data != NULL) {
|
||||
free(level.data);
|
||||
level.data = NULL;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#include "input.h"
|
||||
#include "level.h"
|
||||
#include "player.h"
|
||||
#include <gint/display.h>
|
||||
|
||||
|
@ -12,7 +13,10 @@ static void update(void);
|
|||
int
|
||||
main(void)
|
||||
{
|
||||
extern const struct LevelBin kble_test;
|
||||
|
||||
init();
|
||||
level_load(&kble_test);
|
||||
|
||||
draw();
|
||||
do {
|
||||
|
@ -28,12 +32,14 @@ static void
|
|||
init(void)
|
||||
{
|
||||
input_init();
|
||||
level_init();
|
||||
player_init(&player);
|
||||
}
|
||||
|
||||
static void
|
||||
deinit(void)
|
||||
{
|
||||
level_deinit();
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue