Spikes.
authorWintermate <wintermute@hannover.ccc.de>
Fri, 18 Oct 2013 20:14:51 +0000 (22:14 +0200)
committerWintermate <wintermute@hannover.ccc.de>
Fri, 18 Oct 2013 20:14:51 +0000 (22:14 +0200)
badge/jumpnrun/collision.c
badge/jumpnrun/collision.h
badge/jumpnrun/enemies.c
badge/jumpnrun/jumpnrun.c
badge/jumpnrun/levels.txt
badge/jumpnrun/smb.lv
badge/jumpnrun/tiles.c
badge/jumpnrun/tiles.h
badge/jumpnrun/wrongturn.lv
mock/tools/level-converter.cc

index 2b946f2..0f254e0 100644 (file)
@@ -1,33 +1,39 @@
 #include "collision.h"
 
-void collision_displace(vec2d             *desired_pos,
-                        jumpnrun_moveable *current,
-                        rectangle   const *obstacle,
-                        vec2d             *inertia_mod) {
+uint8_t collision_displace(vec2d             *desired_pos,
+                           jumpnrun_moveable *current,
+                           rectangle   const *obstacle,
+                           vec2d             *inertia_mod) {
   rectangle desired = current->current_box;
   rectangle_move_to(&desired, *desired_pos);
 
   if(!rectangle_intersect(obstacle, &desired)) {
-    return;
+    return 0;
   }
 
   fixed_point x = FIXED_INT(1000), y = FIXED_INT(1000);
   fixed_point dx = desired_pos->x, dy = desired_pos->y;
   bool bottom_collision = false;
 
+  uint8_t coll_x = 0;
+  uint8_t coll_y = 0;
+  uint8_t coll   = 0;
+
   if(fixed_point_le(rectangle_top   ( obstacle), rectangle_top(&desired)) &&
      fixed_point_gt(rectangle_bottom( obstacle), rectangle_top(&desired)) &&
      fixed_point_lt(rectangle_top   (&desired ), rectangle_top(&current->current_box))) {
 
-    y  = fixed_point_sub(rectangle_bottom(obstacle), rectangle_top(&desired));
-    dy =                 rectangle_bottom(obstacle);
+    coll_y = JUMPNRUN_COLLISION_BOTTOM;
+    y      = fixed_point_sub(rectangle_bottom(obstacle), rectangle_top(&desired));
+    dy     =                 rectangle_bottom(obstacle);
 
   } else if(fixed_point_gt(rectangle_bottom( obstacle), rectangle_bottom(&desired)) &&
             fixed_point_le(rectangle_top   ( obstacle), rectangle_bottom(&desired)) &&
             fixed_point_gt(rectangle_top   (&desired ), rectangle_top   (&current->current_box))) {
 
-    y  = fixed_point_sub(rectangle_bottom(&desired ), rectangle_top   ( obstacle));
-    dy = fixed_point_sub(rectangle_top   ( obstacle), rectangle_height(&desired ));
+    coll_y = JUMPNRUN_COLLISION_TOP;
+    y      = fixed_point_sub(rectangle_bottom(&desired ), rectangle_top   ( obstacle));
+    dy     = fixed_point_sub(rectangle_top   ( obstacle), rectangle_height(&desired ));
     bottom_collision = true;
 
   }
@@ -36,35 +42,39 @@ void collision_displace(vec2d             *desired_pos,
      fixed_point_gt(rectangle_right( obstacle), rectangle_left(&desired)) &&
      fixed_point_lt(rectangle_left (&desired ), rectangle_left(&current->current_box))) {
 
-    x  = fixed_point_sub(rectangle_right(obstacle), rectangle_left(&desired));
-    dx =                 rectangle_right(obstacle);
+    coll_x = JUMPNRUN_COLLISION_RIGHT;
+    x      = fixed_point_sub(rectangle_right(obstacle), rectangle_left(&desired));
+    dx     =                 rectangle_right(obstacle);
 
   } else if(fixed_point_gt(rectangle_right( obstacle), rectangle_right(&desired)) &&
             fixed_point_le(rectangle_left ( obstacle), rectangle_right(&desired)) &&
             fixed_point_gt(rectangle_left (&desired ), rectangle_left (&current->current_box))) {
 
-    x  = fixed_point_sub(rectangle_right(&desired ), rectangle_left ( obstacle));
-    dx = fixed_point_sub(rectangle_left ( obstacle), rectangle_width(&desired ));
+    coll_x = JUMPNRUN_COLLISION_LEFT;
+    x      = fixed_point_sub(rectangle_right(&desired ), rectangle_left ( obstacle));
+    dx     = fixed_point_sub(rectangle_left ( obstacle), rectangle_width(&desired ));
 
   }
 
   if(fixed_point_eq(x, y)) {
     desired_pos->x = dx;
     desired_pos->y = dy;
+    coll = coll_x | coll_y;
   } else if(fixed_point_gt(x, y)) {
     desired_pos->y = dy;
     inertia_mod->y = FIXED_INT(0);
-
     current->touching_ground = bottom_collision;
+    coll = coll_y;
   } else {
     desired_pos->x = dx;
     inertia_mod->x = FIXED_INT(0);
+    coll = coll_x;
   }
 
-  return;
+  return coll;
 }
 
-void collisions_tiles_displace(vec2d                     *desired_position,
+bool collisions_tiles_displace(vec2d                     *desired_position,
                                jumpnrun_moveable         *thing,
                                jumpnrun_level      const *lv,
                                jumpnrun_tile_range const *visible_tiles,
@@ -123,6 +133,7 @@ void collisions_tiles_displace(vec2d                     *desired_position,
   }
 
   /* collision: sort by priority (top/bottom, left/right, then diagonal) */
+  bool lethal = false;
   thing->touching_ground = false;
 
   for(size_t collision_index = 0; collision_index < ARRAY_SIZE(collision_order); ++collision_index) {
@@ -130,10 +141,16 @@ void collisions_tiles_displace(vec2d                     *desired_position,
       continue;
     }
 
-    rectangle tile_rect = rect_from_tile(&lv->tiles[collision_tile[collision_order[collision_index]]]);
+    jumpnrun_tile *tile_obj = &lv->tiles[collision_tile[collision_order[collision_index]]];
+    rectangle tile_rect = rect_from_tile(tile_obj);
 
-    collision_displace(desired_position, thing, &tile_rect, inertia_mod);
+    uint8_t coll = collision_displace(desired_position, thing, &tile_rect, inertia_mod);
+    if(coll & tile_type(tile_obj)->lethal_sides) {
+      lethal = true;
+    }
   }
 
   rectangle_move_to(&thing->current_box, *desired_position);
+
+  return lethal;
 }
index 65016e9..405a4f4 100644 (file)
@@ -6,15 +6,15 @@
 #include "../util/rectangle.h"
 #include <stdbool.h>
 
-void collision_displace(vec2d             *desired_pos,
-                       jumpnrun_moveable *current,
-                       rectangle   const *obstacle,
-                       vec2d             *inertia_mod);
+uint8_t collision_displace(vec2d             *desired_pos,
+                           jumpnrun_moveable *current,
+                           rectangle   const *obstacle,
+                           vec2d             *inertia_mod);
 
-void collisions_tiles_displace(vec2d                     *desired_position,
-                              jumpnrun_moveable         *thing,
-                              jumpnrun_level      const *level,
-                              jumpnrun_tile_range const *visible_tiles,
-                              vec2d                     *inertia_mod);
+bool collisions_tiles_displace(vec2d                     *desired_position,
+                               jumpnrun_moveable         *thing,
+                               jumpnrun_level      const *level,
+                               jumpnrun_tile_range const *visible_tiles,
+                               vec2d                     *inertia_mod);
 
 #endif
index 09a8764..cc72db3 100644 (file)
@@ -139,11 +139,15 @@ void enemy_collision_tiles_bounce_horiz(jumpnrun_enemy            *self,
                                         jumpnrun_tile_range const *visible_tiles) {
   vec2d inertia_mod = self->base.inertia;
 
-  collisions_tiles_displace(desired_position,
-                            &self->base,
-                            lv,
-                            visible_tiles,
-                            &inertia_mod);
+  bool killed = collisions_tiles_displace(desired_position,
+                                          &self->base,
+                                          lv,
+                                          visible_tiles,
+                                          &inertia_mod);
+
+  if(killed) {
+    self->flags &= ~JUMPNRUN_ENEMY_SPAWNED;
+  }
 
   if(fixed_point_ne(inertia_mod.x, self->base.inertia.x)) {
     self->base.inertia.x = fixed_point_neg(self->base.inertia.x);
index ae0b80f..5fc5eb7 100644 (file)
@@ -191,10 +191,10 @@ static void jumpnrun_apply_movement(jumpnrun_level      const *lv,
   }
 
   *inertia_mod = state->player.inertia;
-  collisions_tiles_displace(&new_pos, &state->player, lv, tilerange, inertia_mod);
+  bool killed = collisions_tiles_displace(&new_pos, &state->player, lv, tilerange, inertia_mod);
   state->player.inertia = *inertia_mod;
 
-  if(fixed_point_gt(state->player.current_box.pos.y, FIXED_INT(BADGE_DISPLAY_HEIGHT))) {
+  if(killed || fixed_point_gt(state->player.current_box.pos.y, FIXED_INT(BADGE_DISPLAY_HEIGHT))) {
     state->status = JUMPNRUN_DEAD;
   }
 }
index 035b5d7..b4b5113 100644 (file)
@@ -1,5 +1,6 @@
 smb
-foo
 wrongturn
+smb
+foo
 gnobbel
 mean
index ce34f8e..bc96897 100644 (file)
@@ -5,12 +5,12 @@
                      ?                                                     X   ########   ###?        W     ?           ###    #??#                                                        ##        #
                                                                                                                                                                                           ###        #
                                                                                                                                                                                          ####        #     #
-                       G                                                                                                                                                                #####        #    ###
-               ?   #?#?#                     01         01                  #?#              #     ##    ?  ?  ?     #          ##      #  #          ##  #            ##?#            ######        #    ###
-                                     01  V   23         23          @                R R                                               ##  ##        ###  ##                          #######        #   #####
-   P                       01        23      23         23                                                M                           ###  ###      ####  ###     01              01 ########   D    #   #####
+      vvv              G                                                                                                                                                                #####        #    ###
+>           <  ?   #?#?#                     01         01                  #?#              #     ##    ?  ?  ?     #          ##      #  #          ##  #            ##?#            ######        #    ###
+>           <                        01  V   23         23          @                R R                                               ##  ##        ###  ##                          #######        #   #####
+>  P        <              01        23      23         23                                                M                           ###  ###      ####  ###     01              01 ########   D    #   #####
                      S     23        23B     23   H H   23                                      C C              C C      C C  H H   ####  ####    #####  ####    23         C C  23#########        #   #####
-####################################################################  ###############   ################################################################  #####################################################
+########^^^#########################################################  ###############   ################################################################  #####################################################
 
 [tiles]
 0 tube_top_left
 3 tube_right
 # brick
 ? square
+^ spike_up
+v spike_down
+> spike_right
+< spike_left
 
 [items]
 D doc
index a707950..8fb10ce 100644 (file)
@@ -1,10 +1,14 @@
 #include "tiles.h"
 
 jumpnrun_tile_type const jumpnrun_tile_type_data[JUMPNRUN_TILE_TYPE_COUNT] = {
-  { 0, { 5, 5, (uint8_t const *) "\x3f\xf7\xfe\x01" } },
-  { 0, { 5, 5, (uint8_t const *) "\x3f\xc6\xf8\x01" } },
-  { 0, { 5, 5, (uint8_t const *) "\x2f\x87\x10\x00" } },
-  { 0, { 5, 5, (uint8_t const *) "\x21\x84\xfc\x00" } },
-  { 0, { 5, 5, (uint8_t const *) "\xe0\x03\x00\x00" } },
-  { 0, { 5, 5, (uint8_t const *) "\x00\x80\x0f\x00" } }
+  {                         0, { 5, 5, (uint8_t const *) "\x3f\xf7\xfe\x01" } },
+  {                         0, { 5, 5, (uint8_t const *) "\x3f\xc6\xf8\x01" } },
+  {                         0, { 5, 5, (uint8_t const *) "\x2f\x87\x10\x00" } },
+  {                         0, { 5, 5, (uint8_t const *) "\x21\x84\xfc\x00" } },
+  {                         0, { 5, 5, (uint8_t const *) "\xe0\x03\x00\x00" } },
+  {                         0, { 5, 5, (uint8_t const *) "\x00\x80\x0f\x00" } },
+  { JUMPNRUN_COLLISION_TOP   , { 5, 5, (uint8_t const *) "\x98\x4e\x8a\x01" } },
+  { JUMPNRUN_COLLISION_RIGHT , { 5, 5, (uint8_t const *) "\x3f\x2a\x42\x00" } },
+  { JUMPNRUN_COLLISION_BOTTOM, { 5, 5, (uint8_t const *) "\xa3\xe4\x32\x00" } },
+  { JUMPNRUN_COLLISION_LEFT  , { 5, 5, (uint8_t const *) "\x84\xa8\xf8\x01" } }
 };
index f0cde4b..a6a5f70 100644 (file)
@@ -7,12 +7,12 @@
 
 #include <stdint.h>
 
-typedef enum {
-  JUMPNRUN_TILE_TOP    = 1,
-  JUMPNRUN_TILE_BOTTOM = 2,
-  JUMPNRUN_TILE_LEFT   = 4,
-  JUMPNRUN_TILE_RIGHT  = 8
-} jumpnrun_tile_sides;
+enum {
+  JUMPNRUN_COLLISION_TOP    = 1,
+  JUMPNRUN_COLLISION_BOTTOM = 2,
+  JUMPNRUN_COLLISION_LEFT   = 4,
+  JUMPNRUN_COLLISION_RIGHT  = 8
+};
 
 enum {
   JUMPNRUN_TILE_PIXEL_WIDTH  = 5,
@@ -53,6 +53,10 @@ enum {
   JUMPNRUN_TILE_TYPE_TUBE_TOP_RIGHT,
   JUMPNRUN_TILE_TYPE_TUBE_LEFT,
   JUMPNRUN_TILE_TYPE_TUBE_RIGHT,
+  JUMPNRUN_TILE_TYPE_SPIKE_UP,
+  JUMPNRUN_TILE_TYPE_SPIKE_RIGHT,
+  JUMPNRUN_TILE_TYPE_SPIKE_DOWN,
+  JUMPNRUN_TILE_TYPE_SPIKE_LEFT,
 
   JUMPNRUN_TILE_TYPE_COUNT
 };
index af86928..50bfea0 100644 (file)
@@ -2,10 +2,10 @@
                                01                                           #       01                                           23           01                      23                             #                                   
                                23                                          K#       23                                           23           23 01                   23                             #                                   
                              #####                                   ##########     #####                                   ###  23           23 23                   23  01                 01      #                                   
-      P                             ?                           01             ##       #       01            01          ##  #  23 M01      ######                   23  #####################      #                                   
+                                    ?                           01             ##       #       01            01    P     ##  #  23 M01      ######                   23  #####################      #                                   
                                                                 23         M     ##     #       ##            ##       ###    #  23  23   MM #    #                   23                     23      #                                   
       #               01                ?                       23   #######       ##   #         ##        ##     ####       #  230123######     #                   23   CMKCMKCMKCMK   D  23      #                                   
-                      23                             01         23          ##          #           #      #                  #  ##2323        #  #                   23 CMKCMKCMKCMKCMKCMK  23      #                                   
+                      23                             01         23          ##          #           #      #                     ##2323        #  #                   23 CMKCMKCMKCMKCMKCMK  23      #                                   
                       23       ?            ?        23  CC     23            ##    M   #            #    #                        2323       ##  # C K M C K M C K M ######################### M##  #                                   
                       23                             #############              #########            #    #                        ####      ##    #####################                     ######  #                                   
                     M 23                                     #                                        #  #                  ? ?             ###                                                      #                                   
index 7f67732..e5bfa98 100644 (file)
@@ -33,6 +33,10 @@ namespace jnrcpp {
         ("tube_right"    , JUMPNRUN_TILE_TYPE_TUBE_RIGHT    )
         ("brick"         , JUMPNRUN_TILE_TYPE_BRICK         )
         ("square"        , JUMPNRUN_TILE_TYPE_SQUARE        )
+        ("spike_up"      , JUMPNRUN_TILE_TYPE_SPIKE_UP      )
+        ("spike_right"   , JUMPNRUN_TILE_TYPE_SPIKE_RIGHT   )
+        ("spike_down"    , JUMPNRUN_TILE_TYPE_SPIKE_DOWN    )
+        ("spike_left"    , JUMPNRUN_TILE_TYPE_SPIKE_LEFT    )
         ;
 
       items.add
This page took 0.041658 seconds and 4 git commands to generate.