.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,
--- /dev/null
+#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);
+}
--- /dev/null
+#include "player.h"
+#include "jumpnrun.h"
+#include <stdlib.h>
+
+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;
+}
--- /dev/null
+#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