From: Wintermute Date: Mon, 21 Oct 2013 20:14:32 +0000 (+0200) Subject: Lebenszahl levelweise einstellbar. X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/commitdiff_plain/36890cbce498784c05cd591b41e16b5c69f6f29e Lebenszahl levelweise einstellbar. --- diff --git a/badge/jumpnrun/enemies.h b/badge/jumpnrun/enemies.h index c7dfa7e..c66a28e 100644 --- a/badge/jumpnrun/enemies.h +++ b/badge/jumpnrun/enemies.h @@ -14,8 +14,8 @@ struct jumpnrun_tile_range; struct jumpnrun_enemy; typedef struct jumpnrun_enemy_type { - unsigned animation_ticks_per_frame; - size_t animation_length; + uint8_t animation_ticks_per_frame; + uint8_t animation_length; badge_sprite const *animation_frames; rectangle hitbox; diff --git a/badge/jumpnrun/game_state.c b/badge/jumpnrun/game_state.c index 1085e7f..21bd809 100644 --- a/badge/jumpnrun/game_state.c +++ b/badge/jumpnrun/game_state.c @@ -2,7 +2,7 @@ void jumpnrun_game_state_init(jumpnrun_game_state *state, jumpnrun_level const *lv) { memset(state, 0, sizeof(*state)); - jumpnrun_player_spawn(&state->player, lv->start_pos, 3); + jumpnrun_player_spawn(&state->player, lv->start_pos, lv->start_lives); } void jumpnrun_game_state_respawn(jumpnrun_game_state *state, jumpnrun_level const *lv) { diff --git a/badge/jumpnrun/jumpnrun.c b/badge/jumpnrun/jumpnrun.c index 36a5261..c91aac1 100644 --- a/badge/jumpnrun/jumpnrun.c +++ b/badge/jumpnrun/jumpnrun.c @@ -16,11 +16,11 @@ #include #include -static vec2d const gravity () { return (vec2d) { FIXED_POINT(0, 0), FIXED_POINT(0, 56) }; } -static vec2d const move_max () { return (vec2d) { FIXED_POINT(0, 600), FIXED_POINT(1, 300) }; } -static fixed_point const accel_horiz () { return FIXED_POINT(0, 50); } -static fixed_point const accel_vert () { return FIXED_POINT(0, 167); } -static fixed_point const drag_factor () { return FIXED_POINT(0, 854); } +static vec2d gravity () { return (vec2d) { FIXED_POINT(0, 0), FIXED_POINT(0, 56) }; } +static vec2d move_max () { return (vec2d) { FIXED_POINT(0, 600), FIXED_POINT(1, 300) }; } +static fixed_point accel_horiz () { return FIXED_POINT(0, 50); } +static fixed_point accel_vert () { return FIXED_POINT(0, 167); } +static fixed_point drag_factor () { return FIXED_POINT(0, 854); } static inline int imax(int x, int y) { return x < y ? y : x; @@ -162,11 +162,11 @@ void jumpnrun_level_tick(jumpnrun_level *lv, if(state->tick == 0) { badge_framebuffer fb = { { { 0 } } }; - for(size_t tile = tilerange.first; tile < tilerange.last; ++tile) { + for(uint16_t tile = tilerange.first; tile < tilerange.last; ++tile) { jumpnrun_render_tile(&fb, state, &lv->tiles[tile]); } - for(size_t item = 0; item < lv->header.item_count; ++item) { + for(uint16_t item = 0; item < lv->header.item_count; ++item) { jumpnrun_item *item_obj = &lv->items[item]; if(item_obj->flags & JUMPNRUN_ITEM_COLLECTED) { @@ -186,7 +186,7 @@ void jumpnrun_level_tick(jumpnrun_level *lv, } } - for(size_t shot_ix = 0; shot_ix < JUMPNRUN_MAX_SHOTS; ++shot_ix) { + for(uint16_t shot_ix = 0; shot_ix < JUMPNRUN_MAX_SHOTS; ++shot_ix) { jumpnrun_shot *shot = &state->shots[shot_ix]; jumpnrun_shot_process(shot); if(jumpnrun_shot_spawned(shot)) { @@ -194,7 +194,7 @@ void jumpnrun_level_tick(jumpnrun_level *lv, } } - for(size_t enemy_ix = 0; enemy_ix < lv->header.enemy_count; ++enemy_ix) { + for(uint16_t enemy_ix = 0; enemy_ix < lv->header.enemy_count; ++enemy_ix) { jumpnrun_enemy *enemy = &lv->enemies[enemy_ix]; jumpnrun_process_enemy(enemy, &fb, state, lv, &tilerange, &inertia_mod); } @@ -219,11 +219,11 @@ void jumpnrun_level_tick(jumpnrun_level *lv, state->player.base.anim_frame = 0; } } else { - for(size_t shot_ix = 0; shot_ix < JUMPNRUN_MAX_SHOTS; ++shot_ix) { + for(uint16_t shot_ix = 0; shot_ix < JUMPNRUN_MAX_SHOTS; ++shot_ix) { jumpnrun_shot_process(&state->shots[shot_ix]); } - for(size_t enemy_ix = 0; enemy_ix < lv->header.enemy_count; ++enemy_ix) { + for(uint16_t enemy_ix = 0; enemy_ix < lv->header.enemy_count; ++enemy_ix) { jumpnrun_enemy *enemy = &lv->enemies[enemy_ix]; jumpnrun_process_enemy(enemy, NULL, state, lv, &tilerange, &inertia_mod); } diff --git a/badge/jumpnrun/level_load.c b/badge/jumpnrun/level_load.c index ae1a91f..a386ecf 100644 --- a/badge/jumpnrun/level_load.c +++ b/badge/jumpnrun/level_load.c @@ -100,6 +100,14 @@ int jumpnrun_load_level_from_file(jumpnrun_level *dest, FIL *fd) { dest->start_pos.y = FIXED_INT( spos[1] * JUMPNRUN_TILE_PIXEL_HEIGHT); } +#ifdef __linux__ + if(1 != fread(&dest->start_lives, 1, 1, fd)) { +#else + if(FR_OK != f_read(fd, &dest->start_lives, sizeof(dest->start_lives), &count) || count != sizeof(dest->start_lives)) { +#endif + return JUMPNRUN_LEVEL_LOAD_ERROR; + } + for(i = 0; i < dest->header.tile_count; ++i) { #ifdef __linux__ if(1 != fread(buf, 3, 1, fd)) { diff --git a/badge/jumpnrun/levels.h b/badge/jumpnrun/levels.h index 182cafd..c4336cb 100644 --- a/badge/jumpnrun/levels.h +++ b/badge/jumpnrun/levels.h @@ -11,15 +11,16 @@ #include typedef struct jumpnrun_level_header { - size_t tile_count; - size_t item_count; - size_t enemy_count; + uint16_t tile_count; + uint16_t item_count; + uint16_t enemy_count; } jumpnrun_level_header; typedef struct jumpnrun_level { jumpnrun_level_header header; vec2d start_pos; + uint8_t start_lives; jumpnrun_tile *tiles; jumpnrun_item *items; @@ -43,25 +44,25 @@ void jumpnrun_levels_dump(void); var.tiles = var ## _tiles; \ var.items = var ## _items; \ var.enemies = var ## _enemies; -#else +#else #ifdef __linux__ int jumpnrun_load_level_header_from_file(jumpnrun_level *dest, FILE *fd); int jumpnrun_load_level_from_file (jumpnrun_level *dest, FILE *fd); -#define JUMPNRUN_LEVEL_LOAD(lv, lvname) \ - memset(&(lv), 0, sizeof(lv)); \ - FILE *fd = fopen((lvname), "r"); \ - if(fd == NULL) return JUMPNRUN_ERROR; \ - int err = jumpnrun_load_level_header_from_file(&(lv), fd); \ - if(err != 0) { \ - fclose(fd); \ - return JUMPNRUN_ERROR; \ - } \ - JUMPNRUN_LEVEL_MAKE_SPACE(lv); \ - err = jumpnrun_load_level_from_file(&(lv), fd); \ - fclose(fd); \ +#define JUMPNRUN_LEVEL_LOAD(lv, lvname) \ + memset(&(lv), 0, sizeof(lv)); \ + FILE *fd = fopen((lvname), "r"); \ + if(fd == NULL) return JUMPNRUN_ERROR; \ + int err = jumpnrun_load_level_header_from_file(&(lv), fd); \ + if(err != 0) { \ + fclose(fd); \ + return JUMPNRUN_ERROR; \ + } \ + JUMPNRUN_LEVEL_MAKE_SPACE(lv); \ + err = jumpnrun_load_level_from_file(&(lv), fd); \ + fclose(fd); \ if(err != 0) return JUMPNRUN_ERROR; #else #include @@ -69,21 +70,21 @@ int jumpnrun_load_level_from_file (jumpnrun_level *dest, FILE *fd); int jumpnrun_load_level_header_from_file(jumpnrun_level *dest, FIL *fd); int jumpnrun_load_level_from_file (jumpnrun_level *dest, FIL *fd); -#define JUMPNRUN_LEVEL_LOAD(lv, lvname) \ - memset(&(lv), 0, sizeof(lv)); \ - FIL fd; \ - if(FR_OK != f_open(&fd, (lvname), FA_OPEN_EXISTING | FA_READ)) { \ - return JUMPNRUN_ERROR; \ - } \ - if(0 != jumpnrun_load_level_header_from_file(&(lv), &fd)) { \ - f_close(&fd); \ - return JUMPNRUN_ERROR; \ - } \ - JUMPNRUN_LEVEL_MAKE_SPACE(lv); \ - int err = jumpnrun_load_level_from_file(&(lv), &fd); \ - f_close(&fd); \ - if(err != 0) { \ - return JUMPNRUN_ERROR; \ +#define JUMPNRUN_LEVEL_LOAD(lv, lvname) \ + memset(&(lv), 0, sizeof(lv)); \ + FIL fd; \ + if(FR_OK != f_open(&fd, (lvname), FA_OPEN_EXISTING | FA_READ)) { \ + return JUMPNRUN_ERROR; \ + } \ + if(0 != jumpnrun_load_level_header_from_file(&(lv), &fd)) { \ + f_close(&fd); \ + return JUMPNRUN_ERROR; \ + } \ + JUMPNRUN_LEVEL_MAKE_SPACE(lv); \ + int err = jumpnrun_load_level_from_file(&(lv), &fd); \ + f_close(&fd); \ + if(err != 0) { \ + return JUMPNRUN_ERROR; \ } #endif diff --git a/badge/jumpnrun/sltwice.lv b/badge/jumpnrun/sltwice.lv index c0931d2..9882400 100644 --- a/badge/jumpnrun/sltwice.lv +++ b/badge/jumpnrun/sltwice.lv @@ -42,3 +42,6 @@ G giraffe V bird W bird_straight X bird_dip + +[parameters] +L 5 diff --git a/badge/jumpnrun/tiles.h b/badge/jumpnrun/tiles.h index 3ce7869..efc0161 100644 --- a/badge/jumpnrun/tiles.h +++ b/badge/jumpnrun/tiles.h @@ -35,8 +35,8 @@ typedef struct jumpnrun_tile { } jumpnrun_tile; typedef struct jumpnrun_tile_range { - size_t first; - size_t last; // actually one past last. + uint16_t first; + uint16_t last; // actually one past last. } jumpnrun_tile_range; static inline fixed_point tile_left (jumpnrun_tile const *tile) { return FIXED_INT(tile->pos.x * JUMPNRUN_TILE_PIXEL_WIDTH ); } diff --git a/mock/tools/level-converter.cc b/mock/tools/level-converter.cc index 54be8f7..eccd3e0 100644 --- a/mock/tools/level-converter.cc +++ b/mock/tools/level-converter.cc @@ -114,6 +114,8 @@ namespace jnrcpp { objmap = &item_types; } else if(line == "[enemies]") { objmap = &enemy_types; + } else if(line == "[parameters]") { + objmap = &level_params; } else { throw std::invalid_argument("Unkown type: " + line); } @@ -236,8 +238,21 @@ namespace jnrcpp { static_cast(player_pos.second) }; - dest.write(static_cast(static_cast(head)), sizeof(head)); - dest.write(static_cast(static_cast(spos)), sizeof(spos)); + uint8_t lives = 3; + { + std::map::const_iterator iter = level_params.find('L'); + if(iter != level_params.end()) { + unsigned x; + std::istringstream parser(iter->second); + if(parser >> x) { + lives = static_cast(x); + } + } + } + + dest.write(static_cast(static_cast(head )), sizeof(head )); + dest.write(static_cast(static_cast(spos )), sizeof(spos )); + dest.write(static_cast(static_cast(&lives)), sizeof(lives)); dump_tiles(dest); dump_items(dest); @@ -250,6 +265,7 @@ namespace jnrcpp { std::map tile_types; std::map item_types; std::map enemy_types; + std::map level_params; }; }