Lebenszahl levelweise einstellbar.
authorWintermute <wintermute@hannover.ccc.de>
Mon, 21 Oct 2013 20:14:32 +0000 (22:14 +0200)
committerWintermute <wintermute@hannover.ccc.de>
Mon, 21 Oct 2013 20:14:32 +0000 (22:14 +0200)
badge/jumpnrun/enemies.h
badge/jumpnrun/game_state.c
badge/jumpnrun/jumpnrun.c
badge/jumpnrun/level_load.c
badge/jumpnrun/levels.h
badge/jumpnrun/sltwice.lv
badge/jumpnrun/tiles.h
mock/tools/level-converter.cc

index c7dfa7e..c66a28e 100644 (file)
@@ -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;
index 1085e7f..21bd809 100644 (file)
@@ -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) {
index 36a5261..c91aac1 100644 (file)
 #include <stddef.h>
 #include <stdio.h>
 
-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);
     }
index ae1a91f..a386ecf 100644 (file)
@@ -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)) {
index 182cafd..c4336cb 100644 (file)
 #include <stdio.h>
 
 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 <drivers/fatfs/ff.h>
@@ -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
 
index c0931d2..9882400 100644 (file)
@@ -42,3 +42,6 @@ G giraffe
 V bird
 W bird_straight
 X bird_dip
+
+[parameters]
+L 5
index 3ce7869..efc0161 100644 (file)
@@ -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 ); }
index 54be8f7..eccd3e0 100644 (file)
@@ -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<uint16_t>(player_pos.second)
       };
 
-      dest.write(static_cast<char const *>(static_cast<void const *>(head)), sizeof(head));
-      dest.write(static_cast<char const *>(static_cast<void const *>(spos)), sizeof(spos));
+      uint8_t lives = 3;
+      {
+        std::map<char, std::string>::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<uint8_t>(x);
+          }
+        }
+      }
+
+      dest.write(static_cast<char const *>(static_cast<void const *>(head  )), sizeof(head ));
+      dest.write(static_cast<char const *>(static_cast<void const *>(spos  )), sizeof(spos ));
+      dest.write(static_cast<char const *>(static_cast<void const *>(&lives)), sizeof(lives));
 
       dump_tiles(dest);
       dump_items(dest);
@@ -250,6 +265,7 @@ namespace jnrcpp {
     std::map<char, std::string> tile_types;
     std::map<char, std::string> item_types;
     std::map<char, std::string> enemy_types;
+    std::map<char, std::string> level_params;
   };
 }
 
This page took 0.0451549999999999 seconds and 4 git commands to generate.