Make gravity a player variable, and everything fall appart.

This commit is contained in:
KikooDX 2021-01-15 13:10:27 +01:00
parent 9944f34055
commit cfeb0a423a
2 changed files with 4 additions and 2 deletions

View File

@ -5,6 +5,7 @@ typedef struct Player_vars {
float friction;
int acceleration;
int jump_spd;
int gravity;
} Player_vars;
#endif /* _DEF_PLAYER_VARS */

View File

@ -44,6 +44,7 @@ void player_set_vars(Player *player, const Level *level) {
player->vars.friction = FRICTION;
player->vars.acceleration = ACCELERATION;
player->vars.jump_spd = JUMP_SPD;
player->vars.gravity = GRAVITY;
/* apply modifiers */
Vec pos = { player->pos.x, player->pos.y + 1 };
Tile_flags flags = player_collide_or(player, pos, level);
@ -136,9 +137,9 @@ void player_step(Player *player, Input *input, const Level *level, uint step) {
if (player->spd.y < 0 && !player->jump_held) {
/* The player is rising and let go the jump key,
* accelerate gravity until they reach 0. */
player->spd.y += GRAVITY * FAST_FALL_FACTOR;
player->spd.y += player->vars.gravity * FAST_FALL_FACTOR;
} else {
player->spd.y += GRAVITY;
player->spd.y += player->vars.gravity;
}
/* Grace frames allow the player to jump a short
* time after leaving a platform. */