1 #ifndef INCLUDED_JUMPNRUN_LEVEL_H
2 #define INCLUDED_JUMPNRUN_LEVEL_H
8 #include "../util/rectangle.h"
13 #define JUMPNRUN_PATH "/hackio"
15 typedef struct jumpnrun_level_header
{
19 } jumpnrun_level_header
;
21 typedef struct jumpnrun_level
{
22 jumpnrun_level_header header
;
29 jumpnrun_enemy
*enemies
;
33 JUMPNRUN_LEVEL_LOAD_OK
,
34 JUMPNRUN_LEVEL_LOAD_ERROR
37 size_t jumpnrun_level_count(void);
38 void jumpnrun_levels_dump(void);
40 // Use stack-local VLAs to store dynamic content.
41 #define JUMPNRUN_LEVEL_MAKE_SPACE(var) \
42 jumpnrun_tile var ## _tiles [var.header.tile_count]; \
43 jumpnrun_item var ## _items [var.header.item_count]; \
44 jumpnrun_enemy var ## _enemies[var.header.enemy_count]; \
46 var.tiles = var ## _tiles; \
47 var.items = var ## _items; \
48 var.enemies = var ## _enemies;
53 int jumpnrun_load_level_header_from_file(jumpnrun_level
*dest
, FILE *fd
);
54 int jumpnrun_load_level_from_file (jumpnrun_level
*dest
, FILE *fd
);
56 #define JUMPNRUN_LEVEL_LOAD(lv, lvname) \
57 memset(&(lv), 0, sizeof(lv)); \
58 FILE *fd = fopen((lvname), "r"); \
59 if(fd == NULL) return JUMPNRUN_ERROR; \
60 int err = jumpnrun_load_level_header_from_file(&(lv), fd); \
63 return JUMPNRUN_ERROR; \
65 JUMPNRUN_LEVEL_MAKE_SPACE(lv); \
66 err = jumpnrun_load_level_from_file(&(lv), fd); \
68 if(err != 0) return JUMPNRUN_ERROR;
70 #include <drivers/fatfs/ff.h>
72 int jumpnrun_load_level_header_from_file(jumpnrun_level
*dest
, FIL
*fd
);
73 int jumpnrun_load_level_from_file (jumpnrun_level
*dest
, FIL
*fd
);
75 #define JUMPNRUN_LEVEL_LOAD(lv, lvname) \
76 memset(&(lv), 0, sizeof(lv)); \
78 if(FR_OK != f_chdir(JUMPNRUN_PATH) || \
79 FR_OK != f_open(&fd, (lvname), FA_OPEN_EXISTING | FA_READ)) { \
80 return JUMPNRUN_ERROR; \
82 if(0 != jumpnrun_load_level_header_from_file(&(lv), &fd)) { \
84 return JUMPNRUN_ERROR; \
86 JUMPNRUN_LEVEL_MAKE_SPACE(lv); \
87 int err = jumpnrun_load_level_from_file(&(lv), &fd); \
90 return JUMPNRUN_ERROR; \