+void enemy_collision_tiles_pass_through(struct jumpnrun_enemy *self,
+ vec2d *desired_position,
+ struct jumpnrun_level *lv,
+ struct jumpnrun_tile_range const *visible_tiles) {
+ (void) self;
+ (void) desired_position;
+ (void) lv;
+ (void) visible_tiles;
+ return;
+}
+
+void enemy_collision_shots_die(struct jumpnrun_enemy *self,
+ struct jumpnrun_game_state *state) {
+ rectangle rect_self = enemy_hitbox(self);
+
+ for(uint8_t i = 0; i < JUMPNRUN_MAX_SHOTS; ++i) {
+ jumpnrun_shot *shot = &state->shots[i];
+
+ if(jumpnrun_shot_spawned(shot)) {
+ if(rectangle_intersect(&rect_self, &shot->current_box)) {
+ self->flags &= ~JUMPNRUN_ENEMY_SPAWNED;
+ jumpnrun_shot_despawn(shot);
+ }
+ }
+ }
+}
+
+void enemy_collision_shots_bounce(struct jumpnrun_enemy *self,
+ struct jumpnrun_game_state *state) {
+ rectangle rect_self = enemy_hitbox(self);
+
+ for(uint8_t i = 0; i < JUMPNRUN_MAX_SHOTS; ++i) {
+ jumpnrun_shot *shot = &state->shots[i];
+
+ if(jumpnrun_shot_spawned(shot)) {
+ if(rectangle_intersect(&rect_self, &shot->current_box)) {
+ if(fixed_point_gt(shot->inertia.x, FIXED_INT(0))) {
+ rectangle_move_to_x(&shot->current_box, fixed_point_sub(rectangle_left(&rect_self), rectangle_width(&shot->current_box)));
+ } else {
+ rectangle_move_to_x(&shot->current_box, rectangle_right(&rect_self));
+ }
+
+ shot->inertia.x = fixed_point_neg(shot->inertia.x);
+ }
+ }
+ }
+}
+
+void enemy_collision_shots_dontcare(struct jumpnrun_enemy *self,
+ struct jumpnrun_game_state *state) {
+ (void) self;
+ (void) state;
+}
+
+void enemy_tick_straight_ahead(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);
+
+ 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,
+ struct 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;
+ }
+
+ 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);
+
+ self->base.inertia.y =
+ fixed_point_add(fixed_point_add(self->base.inertia.y,
+ fixed_point_div(self->type->spawn_inertia.y, FIXED_INT(3))),
+ fixed_point_mul(FIXED_POINT(0, 5),
+ fixed_point_sub(self->spawn_pos.y,
+ enemy_position(self).y)));
+
+ enemy_animation_advance(self);
+}
+
+void enemy_tick_stationary(struct jumpnrun_enemy *self,
+ struct jumpnrun_game_state *state,
+ struct jumpnrun_level *lv,
+ struct 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;
+ }
+
+ self->type->collision_tiles(self, &self->base.current_box.pos, lv, visible_tiles);
+ self->type->collision_player(self, state, player_inertia_mod);
+
+ enemy_animation_advance(self);
+}
+
+void enemy_tick_jumper(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(self->base.touching_ground) {
+ self->base.inertia.y = self->type->spawn_inertia.y;
+ }
+
+ enemy_animation_advance(self);
+}
+
+void enemy_tick_dog(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(self->base.tick_minor % self->type->animation_ticks_per_frame == 0) {
+ switch(self->base.tick_minor / self->type->animation_ticks_per_frame) {
+ case 12:
+ self->base.tick_minor = 0;
+ case 0:
+ case 2:
+ case 4:
+ case 6:
+ self->base.anim_frame = 0;
+ if(self->flags & JUMPNRUN_ENEMY_FACING_RIGHT) {
+ self->base.inertia.x = fixed_point_neg(self->type->spawn_inertia.x);
+ } else {
+ self->base.inertia.x = self->type->spawn_inertia.x;
+ }
+
+ break;
+
+ case 1:
+ case 3:
+ case 5:
+ case 7:
+ self->base.anim_frame = 1;
+ if(self->flags & JUMPNRUN_ENEMY_FACING_RIGHT) {
+ self->base.inertia.x = fixed_point_neg(self->type->spawn_inertia.x);
+ } else {
+ self->base.inertia.x = self->type->spawn_inertia.x;
+ }
+ break;
+
+ case 8:
+ case 10:
+ self->base.anim_frame = 2;
+ self->base.inertia.x = FIXED_INT(0);
+ break;
+
+ case 9:
+ case 11:
+ self->base.anim_frame = 3;
+ self->base.inertia.x = FIXED_INT(0);
+ break;
+ }
+ }
+
+ ++self->base.tick_minor;
+ if (fixed_point_lt(self->base.inertia.x, FIXED_INT(0))) { self->flags &= ~JUMPNRUN_ENEMY_FACING_RIGHT; }
+ else if(fixed_point_ne(self->base.inertia.x, FIXED_INT(0))) { self->flags |= JUMPNRUN_ENEMY_FACING_RIGHT; }
+}
+
+void enemy_tick_giraffe(jumpnrun_enemy *self,
+ jumpnrun_game_state *state,
+ jumpnrun_level *lv,
+ jumpnrun_tile_range const *visible_tiles,
+ vec2d *player_inertia_mod) {