Schrift fest in Firmware eingebacken, damit die auch funktioniert, wenn auf dem
[hackover2013-badge-firmware.git] / badge / jumpnrun / game_state.c
1 #include "game_state.h"
2
3 void jumpnrun_game_state_init(jumpnrun_game_state *state, jumpnrun_level const *lv) {
4 memset(state, 0, sizeof(*state));
5 jumpnrun_player_spawn(&state->player, lv->start_pos, lv->start_lives);
6 }
7
8 void jumpnrun_game_state_respawn(jumpnrun_game_state *state, jumpnrun_level const *lv) {
9 jumpnrun_player_respawn(&state->player, lv->start_pos);
10 state->flags = 0;
11 state->screen_left = 0;
12 state->tick = 0;
13 memset(state->shots, 0, sizeof(state->shots));
14
15 for(size_t i = 0; i < lv->header.enemy_count; ++i) {
16 jumpnrun_enemy_reset(&lv->enemies[i]);
17 }
18 }
19
20 void jumpnrun_shot_spawn(jumpnrun_shot *shot, jumpnrun_game_state const *state) {
21 static vec2d const shot_spawn_inertia = { FIXED_POINT_I(0, 800), FIXED_POINT_I(0, -800) };
22
23 shot->tick = 0;
24 shot->inertia = shot_spawn_inertia;
25
26 if(jumpnrun_moveable_mirrored(&state->player.base)) {
27 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) },
28 (vec2d) { FIXED_INT(JUMPNRUN_SHOT_EXTENT), FIXED_INT(JUMPNRUN_SHOT_EXTENT) });
29 shot->inertia.x = fixed_point_neg(shot->inertia.x);
30 } else {
31 shot->current_box = rectangle_new((vec2d) { rectangle_right(&state->player.base.hitbox), rectangle_top(&state->player.base.hitbox) },
32 (vec2d) { FIXED_INT(JUMPNRUN_SHOT_EXTENT), FIXED_INT(JUMPNRUN_SHOT_EXTENT) });
33 }
34
35 shot->old_box = shot->current_box;
36 shot->inertia = vec2d_add(shot->inertia, state->player.base.inertia);
37 }
This page took 0.043328 seconds and 5 git commands to generate.