From 74e337691a69a709aaa85569f312ba0493645ad3 Mon Sep 17 00:00:00 2001 From: Wintermute Date: Sun, 20 Oct 2013 18:09:48 +0200 Subject: [PATCH] Gegner splodieren. --- badge/jumpnrun/enemies.c | 22 ++++++++++++++++++---- badge/jumpnrun/levels.txt | 2 +- badge/jumpnrun/moveable.h | 3 ++- badge/jumpnrun/render.c | 23 ++++++++++++++++++++++- badge/jumpnrun/render.h | 7 +++++++ 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/badge/jumpnrun/enemies.c b/badge/jumpnrun/enemies.c index ed044bd..81643b3 100644 --- a/badge/jumpnrun/enemies.c +++ b/badge/jumpnrun/enemies.c @@ -99,9 +99,14 @@ static void enemy_spawn(jumpnrun_enemy *self) { self->base.jumpable_frames = 0; } +static void jumpnrun_enemy_kill(jumpnrun_enemy *self) { + self->base.flags |= JUMPNRUN_MOVEABLE_DYING; + self->base.tick_minor = 0; +} + void jumpnrun_enemy_despawn(jumpnrun_enemy *self) { // Despawned enemies are reset to their spawn position, so enemy_in_spawn_area will determine whether the spawn point is in the spawn area. - self->base.flags &= ~(JUMPNRUN_ENEMY_SPAWNED | JUMPNRUN_ENEMY_MOVING); + self->base.flags &= ~(JUMPNRUN_ENEMY_SPAWNED | JUMPNRUN_ENEMY_MOVING | JUMPNRUN_MOVEABLE_DYING); self->base.hitbox = rectangle_new(self->spawn_pos, self->type->hitbox.extent); self->base.inertia = self->type->spawn_inertia; } @@ -147,6 +152,15 @@ void jumpnrun_process_enemy(jumpnrun_enemy *self, if(self->base.flags & JUMPNRUN_ENEMY_SPAWNED) { if(!enemy_in_spawn_area(self, state) || fixed_point_gt(rectangle_top (enemy_hitbox(self)), FIXED_INT(BADGE_DISPLAY_HEIGHT))) { jumpnrun_enemy_despawn(self); + } else if(self->base.flags & JUMPNRUN_MOVEABLE_DYING) { + if(self->base.tick_minor == JUMPNRUN_SPLOSION_FRAMES * JUMPNRUN_SPLOSION_TICKS_PER_FRAME) { + jumpnrun_enemy_despawn(self); + } else { + if(fb) { + jumpnrun_render_splosion(fb, state, &self->base); + } + ++self->base.tick_minor; + } } else { if((self->base.flags & JUMPNRUN_ENEMY_MOVING) || enemy_on_screen(self, state)) { self->base.flags |= JUMPNRUN_ENEMY_MOVING; @@ -184,7 +198,7 @@ void enemy_collision_tiles_bounce_horiz(jumpnrun_enemy *self, &inertia_mod); if(killed) { - jumpnrun_enemy_despawn(self); + jumpnrun_enemy_kill(self); } else if(fixed_point_ne(inertia_mod.x, self->base.inertia.x)) { enemy_bounce(self); } @@ -208,7 +222,7 @@ void enemy_collision_player_jumpable(jumpnrun_enemy *self, if(fixed_point_lt(rectangle_top(&state->player.base.hitbox), rectangle_top(enemy_hitbox(self))) && fixed_point_gt(state->player.base.inertia.y, FIXED_INT(0))) { - jumpnrun_enemy_despawn(self); + jumpnrun_enemy_kill(self); player_inertia_mod->y = FIXED_POINT(0, -250); state->player.base.jumpable_frames = 12; } else { @@ -234,7 +248,7 @@ void enemy_collision_shots_die(struct jumpnrun_enemy *self, if(jumpnrun_shot_spawned(shot)) { if(rectangle_intersect(enemy_hitbox(self), &shot->current_box)) { - self->base.flags &= ~JUMPNRUN_ENEMY_SPAWNED; + jumpnrun_enemy_kill(self); jumpnrun_shot_despawn(shot); } } diff --git a/badge/jumpnrun/levels.txt b/badge/jumpnrun/levels.txt index 243a4ac..5292917 100644 --- a/badge/jumpnrun/levels.txt +++ b/badge/jumpnrun/levels.txt @@ -1,6 +1,6 @@ +smb skynet wrongturn -smb lubiXOXO lubilove gnobbel diff --git a/badge/jumpnrun/moveable.h b/badge/jumpnrun/moveable.h index 7b680d2..016a059 100644 --- a/badge/jumpnrun/moveable.h +++ b/badge/jumpnrun/moveable.h @@ -7,7 +7,8 @@ enum { // Do not collide with JUMPNRUN_ENEMY_* and JUMPNRUN_PLAYER_* flags. JUMPNRUN_MOVEABLE_TOUCHING_GROUND = 1, - JUMPNRUN_MOVEABLE_MIRRORED = 2 + JUMPNRUN_MOVEABLE_MIRRORED = 2, + JUMPNRUN_MOVEABLE_DYING = 4 }; typedef struct jumpnrun_moveable { diff --git a/badge/jumpnrun/render.c b/badge/jumpnrun/render.c index 3755aa6..e3b09ed 100644 --- a/badge/jumpnrun/render.c +++ b/badge/jumpnrun/render.c @@ -5,13 +5,20 @@ static badge_sprite const anim_sickle[JUMPNRUN_SHOT_FRAMES] = { { 3, 3, (uint8_t const *) "\xee" } }; -static badge_sprite const anim_player[JUMPNRUN_PLAYER_FRAMES ] = { +static badge_sprite const anim_player[JUMPNRUN_PLAYER_FRAMES] = { { 5, 8, (uint8_t const *) "\x1c\xff\xfd\x04\x04" }, { 5, 8, (uint8_t const *) "\x1c\xff\x3d\xc4\x04" }, { 5, 8, (uint8_t const *) "\xdc\x3f\x1d\x24\xc4" }, { 5, 8, (uint8_t const *) "\x1c\xff\x3d\xc4\x04" } }; +static badge_sprite const anim_splosion[JUMPNRUN_SPLOSION_FRAMES] = { + { 7, 5, (uint8_t const *) "\x00\x28\xa0\x00" }, + { 7, 5, (uint8_t const *) "\x51\x29\xa0\x54\x04" }, + { 7, 5, (uint8_t const *) "\x51\x01\x00\x54\x04" }, + { 7, 5, (uint8_t const *) "\x11\x00\x00\x40\x04" } +}; + vec2d jumpnrun_player_extents(void) { return (vec2d) { FIXED_INT_I(5), FIXED_INT_I(8) }; } void jumpnrun_render_moveable (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_moveable const *moveable, badge_sprite const *animation, vec2d sprite_offset) { @@ -65,6 +72,20 @@ void jumpnrun_render_item (badge_framebuffer *fb, jumpnrun_game_state co 0); } +void jumpnrun_render_splosion (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_moveable const *moveable) { + badge_sprite const *sprite = &anim_splosion[moveable->tick_minor / JUMPNRUN_SPLOSION_TICKS_PER_FRAME]; + vec2d sprite_offset = { + fixed_point_div(fixed_point_sub(FIXED_INT(sprite->width ), rectangle_width (&moveable->hitbox)), FIXED_INT(2)), + fixed_point_div(fixed_point_sub(FIXED_INT(sprite->height), rectangle_height(&moveable->hitbox)), FIXED_INT(2)) + }; + vec2d render_pos = vec2d_sub(moveable->hitbox.pos, sprite_offset); + + badge_framebuffer_blt(fb, + fixed_point_cast_int(render_pos.x) - jumpnrun_screen_left(state), + fixed_point_cast_int(render_pos.y), + sprite, 0); +} + void jumpnrun_render_player_symbol(badge_framebuffer *fb, int8_t x, int8_t y) { badge_framebuffer_blt(fb, x, y, &anim_player[0], 0); } diff --git a/badge/jumpnrun/render.h b/badge/jumpnrun/render.h index 64c6aa9..9237ba6 100644 --- a/badge/jumpnrun/render.h +++ b/badge/jumpnrun/render.h @@ -19,7 +19,14 @@ void jumpnrun_render_enemy (badge_framebuffer *fb, jumpnrun_game_state co void jumpnrun_render_tile (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_tile const *tile ); void jumpnrun_render_item (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_item const *item ); +void jumpnrun_render_splosion (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_moveable const *moveable); + void jumpnrun_render_player_symbol(badge_framebuffer *fb, int8_t x, int8_t y); void jumpnrun_render_key_symbol (badge_framebuffer *fb, int8_t x, int8_t y); +enum { + JUMPNRUN_SPLOSION_FRAMES = 4, + JUMPNRUN_SPLOSION_TICKS_PER_FRAME = 15 +}; + #endif -- 2.20.1