X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/9ae835c864d2b3e651a86ac4af7cfac0979f136a..eb0884ecd703881e43b1c34ac04e0d49dbab4c38:/badge/jumpnrun/enemies.c diff --git a/badge/jumpnrun/enemies.c b/badge/jumpnrun/enemies.c index a38976d..cc72db3 100644 --- a/badge/jumpnrun/enemies.c +++ b/badge/jumpnrun/enemies.c @@ -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); @@ -257,6 +261,35 @@ void enemy_tick_straight_ahead(jumpnrun_enemy *self, enemy_animation_advance(self); } +void enemy_tick_straight_follow(jumpnrun_enemy *self, + jumpnrun_game_state *state, + jumpnrun_level *lv, + jumpnrun_tile_range const *visible_tiles, + vec2d *player_inertia_mod) { + int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box)); + + if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left || + screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) { + return; + } + + jumpnrun_passive_movement(&self->base.inertia); + + vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia); + self->type->collision_tiles(self, &new_pos, lv, visible_tiles); + self->type->collision_player(self, state, player_inertia_mod); + rectangle_move_to(&self->base.current_box, new_pos); + + if(fixed_point_le(rectangle_mid_x(&state->player.current_box), rectangle_mid_x(enemy_box(self)))) { + self->base.inertia.x = self->type->spawn_inertia.x; + } else { + self->base.inertia.x = fixed_point_neg(self->type->spawn_inertia.x); + } + + + enemy_animation_advance(self); +} + void enemy_tick_swing_up_and_down(struct jumpnrun_enemy *self, struct jumpnrun_game_state *state, struct jumpnrun_level *lv, @@ -524,7 +557,7 @@ jumpnrun_enemy_type const jumpnrun_enemy_type_data[JUMPNRUN_ENEMY_TYPE_COUNT] = .collision_tiles = enemy_collision_tiles_bounce_horiz, .collision_player = enemy_collision_player_jumpable, .collision_shots = enemy_collision_shots_die, - .move_tick = enemy_tick_straight_ahead + .move_tick = enemy_tick_straight_follow }, { .animation_ticks_per_frame = 9, .animation_length = ARRAY_SIZE(anim_bunny),