From ac05cee74d9922fdca433dd2c03fd8542002bb28 Mon Sep 17 00:00:00 2001 From: Wintermate Date: Sun, 20 Oct 2013 04:14:09 +0200 Subject: [PATCH] Vergessene Dinge eingecheckt. --- badge/jumpnrun/enemies.c | 4 ++-- badge/jumpnrun/game_state.c | 36 ++++++++++++++++++++++++++++++++++++ badge/jumpnrun/player.c | 14 ++++++++++++++ badge/jumpnrun/render.h | 25 +++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 badge/jumpnrun/game_state.c create mode 100644 badge/jumpnrun/player.c create mode 100644 badge/jumpnrun/render.h diff --git a/badge/jumpnrun/enemies.c b/badge/jumpnrun/enemies.c index 61859a8..744e2f9 100644 --- a/badge/jumpnrun/enemies.c +++ b/badge/jumpnrun/enemies.c @@ -517,8 +517,8 @@ jumpnrun_enemy_type const jumpnrun_enemy_type_data[JUMPNRUN_ENEMY_TYPE_COUNT] = .animation_ticks_per_frame = 6, .animation_length = ARRAY_SIZE(anim_spiral), .animation_frames = anim_spiral, - .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(1) }, - { FIXED_INT_I(8), FIXED_INT_I(8) } }, + .hitbox = { { FIXED_INT_I(0), FIXED_INT_I(0) }, + { FIXED_INT_I(10), FIXED_INT_I(10) } }, .spawn_inertia = { FIXED_INT_I(0), FIXED_POINT_I(0, -200) }, .collision_tiles = enemy_collision_tiles_pass_through, .collision_player = enemy_collision_player_deadly, diff --git a/badge/jumpnrun/game_state.c b/badge/jumpnrun/game_state.c new file mode 100644 index 0000000..1fa1485 --- /dev/null +++ b/badge/jumpnrun/game_state.c @@ -0,0 +1,36 @@ +#include "game_state.h" + +void jumpnrun_game_state_init(jumpnrun_game_state *state, jumpnrun_level const *lv) { + memset(state, 0, sizeof(*state)); + jumpnrun_player_spawn(&state->player, lv->start_pos, 99); +} + +void jumpnrun_game_state_respawn(jumpnrun_game_state *state, jumpnrun_level const *lv) { + jumpnrun_player_respawn(&state->player, lv->start_pos); + state->flags = 0; + state->screen_left = 0; + memset(state->shots, 0, sizeof(state->shots)); + + for(size_t i = 0; i < lv->header.enemy_count; ++i) { + jumpnrun_enemy_reset(&lv->enemies[i]); + } +} + +void jumpnrun_shot_spawn(jumpnrun_shot *shot, jumpnrun_game_state const *state) { + static vec2d const shot_spawn_inertia = { FIXED_POINT_I(0, 800), FIXED_POINT_I(0, -800) }; + + shot->tick = 0; + shot->inertia = shot_spawn_inertia; + + if(jumpnrun_moveable_mirrored(&state->player.base)) { + shot->current_box = rectangle_new((vec2d) { fixed_point_sub(rectangle_left(&state->player.base.hitbox), FIXED_INT(JUMPNRUN_SHOT_EXTENT)), rectangle_top(&state->player.base.hitbox) }, + (vec2d) { FIXED_INT(JUMPNRUN_SHOT_EXTENT), FIXED_INT(JUMPNRUN_SHOT_EXTENT) }); + shot->inertia.x = fixed_point_neg(shot->inertia.x); + } else { + shot->current_box = rectangle_new((vec2d) { rectangle_right(&state->player.base.hitbox), rectangle_top(&state->player.base.hitbox) }, + (vec2d) { FIXED_INT(JUMPNRUN_SHOT_EXTENT), FIXED_INT(JUMPNRUN_SHOT_EXTENT) }); + } + + shot->old_box = shot->current_box; + shot->inertia = vec2d_add(shot->inertia, state->player.base.inertia); +} diff --git a/badge/jumpnrun/player.c b/badge/jumpnrun/player.c new file mode 100644 index 0000000..1031e70 --- /dev/null +++ b/badge/jumpnrun/player.c @@ -0,0 +1,14 @@ +#include "player.h" +#include "jumpnrun.h" +#include + +void jumpnrun_player_respawn(jumpnrun_player *self, vec2d spawn_pos) { + memset(&self->base, 0, sizeof(self->base)); + self->base.hitbox = rectangle_new(spawn_pos, jumpnrun_player_extents()); +} + +void jumpnrun_player_spawn (jumpnrun_player *self, vec2d spawn_pos, uint8_t lives) { + memset(self, 0, sizeof(*self)); + jumpnrun_player_respawn(self, spawn_pos); + self->lives = lives; +} diff --git a/badge/jumpnrun/render.h b/badge/jumpnrun/render.h new file mode 100644 index 0000000..64c6aa9 --- /dev/null +++ b/badge/jumpnrun/render.h @@ -0,0 +1,25 @@ +#ifndef INCLUDED_BADGE_JUMPNRUN_RENDER_H +#define INCLUDED_BADGE_JUMPNRUN_RENDER_H + +#include "enemies.h" +#include "game_state.h" +#include "items.h" +#include "player.h" +#include "shots.h" +#include "tiles.h" + +#include "../ui/display.h" +#include "../ui/sprite.h" +#include "../util/util.h" + +void jumpnrun_render_moveable (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_moveable const *moveable, badge_sprite const *animation, vec2d sprite_offset); +void jumpnrun_render_player (badge_framebuffer *fb, jumpnrun_game_state const *state); +void jumpnrun_render_shot (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_shot *shot ); +void jumpnrun_render_enemy (badge_framebuffer *fb, jumpnrun_game_state const *state, jumpnrun_enemy const *enemy); +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_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); + +#endif -- 2.20.1