1 #include "game_state.h"
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
);
8 void jumpnrun_game_state_respawn(jumpnrun_game_state
*state
, jumpnrun_level
const *lv
) {
9 jumpnrun_player_respawn(&state
->player
, lv
->start_pos
);
11 state
->screen_left
= 0;
13 memset(state
->shots
, 0, sizeof(state
->shots
));
15 for(size_t i
= 0; i
< lv
->header
.enemy_count
; ++i
) {
16 jumpnrun_enemy_reset(&lv
->enemies
[i
]);
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) };
24 shot
->inertia
= shot_spawn_inertia
;
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
);
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
) });
35 shot
->old_box
= shot
->current_box
;
36 shot
->inertia
= vec2d_add(shot
->inertia
, state
->player
.base
.inertia
);
This page took 0.045351 seconds and 5 git commands to generate.