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
;
27 jumpnrun_enemy
*enemies
;
31 JUMPNRUN_LEVEL_LOAD_OK
,
32 JUMPNRUN_LEVEL_LOAD_ERROR
35 size_t jumpnrun_level_count(void);
36 void jumpnrun_levels_dump(void);
38 // Use stack-local VLAs to store dynamic content.
39 #define JUMPNRUN_LEVEL_MAKE_SPACE(var) \
40 jumpnrun_tile var ## _tiles [var.header.tile_count]; \
41 jumpnrun_item var ## _items [var.header.item_count]; \
42 jumpnrun_enemy var ## _enemies[var.header.enemy_count]; \
44 var.tiles = var ## _tiles; \
45 var.items = var ## _items; \
46 var.enemies = var ## _enemies;
51 int jumpnrun_load_level_header_from_file(jumpnrun_level
*dest
, FILE *fd
);
52 int jumpnrun_load_level_from_file (jumpnrun_level
*dest
, FILE *fd
);
54 #define JUMPNRUN_LEVEL_LOAD(lv, lvname) \
55 memset(&(lv), 0, sizeof(lv)); \
56 FILE *fd = fopen((lvname), "r"); \
57 if(fd == NULL) return JUMPNRUN_ERROR; \
58 int err = jumpnrun_load_level_header_from_file(&(lv), fd); \
61 return JUMPNRUN_ERROR; \
63 JUMPNRUN_LEVEL_MAKE_SPACE(lv); \
64 err = jumpnrun_load_level_from_file(&(lv), fd); \
66 if(err != 0) return JUMPNRUN_ERROR;
68 #include <drivers/fatfs/ff.h>
70 int jumpnrun_load_level_header_from_file(jumpnrun_level
*dest
, FIL
*fd
);
71 int jumpnrun_load_level_from_file (jumpnrun_level
*dest
, FIL
*fd
);
73 #define JUMPNRUN_LEVEL_LOAD(lv, lvname) \
74 memset(&(lv), 0, sizeof(lv)); \
76 if(FR_OK != f_open(&fd, (lvname), FA_OPEN_EXISTING | FA_READ)) { \
77 return JUMPNRUN_ERROR; \
79 if(0 != jumpnrun_load_level_header_from_file(&(lv), &fd)) { \
81 return JUMPNRUN_ERROR; \
83 JUMPNRUN_LEVEL_MAKE_SPACE(lv); \
84 int err = jumpnrun_load_level_from_file(&(lv), &fd); \
87 return JUMPNRUN_ERROR; \