1 #ifndef INCLUDED_JUMPNRUN_LEVEL_H
2 #define INCLUDED_JUMPNRUN_LEVEL_H
8 #include "../util/rectangle.h"
13 typedef struct jumpnrun_level_header
{
17 } jumpnrun_level_header
;
19 typedef struct jumpnrun_level
{
20 jumpnrun_level_header header
;
26 jumpnrun_enemy
*enemies
;
30 JUMPNRUN_LEVEL_LOAD_OK
,
31 JUMPNRUN_LEVEL_LOAD_ERROR
34 size_t jumpnrun_level_count(void);
35 void jumpnrun_levels_dump(void);
37 // Use stack-local VLAs to store dynamic content.
38 #define JUMPNRUN_LEVEL_MAKE_SPACE(var) \
39 jumpnrun_tile var ## _tiles [var.header.tile_count]; \
40 jumpnrun_item var ## _items [var.header.item_count]; \
41 jumpnrun_enemy var ## _enemies[var.header.enemy_count]; \
43 var.tiles = var ## _tiles; \
44 var.items = var ## _items; \
45 var.enemies = var ## _enemies;
50 int jumpnrun_load_level_header_from_file(jumpnrun_level
*dest
, FILE *fd
);
51 int jumpnrun_load_level_from_file (jumpnrun_level
*dest
, FILE *fd
);
53 #define JUMPNRUN_LEVEL_LOAD(lv, lvname) \
54 memset(&(lv), 0, sizeof(lv)); \
55 FILE *fd = fopen((lvname), "r"); \
56 if(fd == NULL) return JUMPNRUN_ERROR; \
57 int err = jumpnrun_load_level_header_from_file(&(lv), fd); \
60 return JUMPNRUN_ERROR; \
62 JUMPNRUN_LEVEL_MAKE_SPACE(lv); \
63 err = jumpnrun_load_level_from_file(&(lv), fd); \
65 if(err != 0) return JUMPNRUN_ERROR;
67 #include <drivers/fatfs/ff.h>
69 int jumpnrun_load_level_header_from_file(jumpnrun_level
*dest
, FIL
*fd
);
70 int jumpnrun_load_level_from_file (jumpnrun_level
*dest
, FIL
*fd
);
72 #define JUMPNRUN_LEVEL_LOAD(lv, lvname) \
73 memset(&(lv), 0, sizeof(lv)); \
75 if(FR_OK != f_open(&fd, (lvname), FA_OPEN_EXISTING | FA_READ)) { \
76 return JUMPNRUN_ERROR; \
78 if(0 != jumpnrun_load_level_header_from_file(&(lv), &fd)) { \
80 return JUMPNRUN_ERROR; \
82 JUMPNRUN_LEVEL_MAKE_SPACE(lv); \
83 int err = jumpnrun_load_level_from_file(&(lv), &fd); \
86 return JUMPNRUN_ERROR; \