#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(¤t->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 (¤t->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;
}
fixed_point_gt(rectangle_right( obstacle), rectangle_left(&desired)) &&
fixed_point_lt(rectangle_left (&desired ), rectangle_left(¤t->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 (¤t->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,
}
/* 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) {
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;
}
#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
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);
}
*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;
}
}
smb
-foo
wrongturn
+smb
+foo
gnobbel
mean
? 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
#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" } }
};
#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,
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
};
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 # # # ? ? ### #
("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