Merge branch 'gravityvar'
This commit is contained in:
commit
7bce93d092
|
@ -5,6 +5,7 @@ typedef struct Player_vars {
|
|||
float friction;
|
||||
int acceleration;
|
||||
int jump_spd;
|
||||
int gravity;
|
||||
} Player_vars;
|
||||
|
||||
#endif /* _DEF_PLAYER_VARS */
|
||||
|
|
|
@ -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);
|
||||
|
@ -72,7 +73,6 @@ void player_set_vars(Player *player, const Level *level) {
|
|||
}
|
||||
|
||||
void player_move(Player *player, const Level *level) {
|
||||
player_set_vars(player, level);
|
||||
/* TODO: Take into account player's hitbox */
|
||||
const int sgn_spd_x = SGN(player->spd.x);
|
||||
const int sgn_spd_y = SGN(player->spd.y);
|
||||
|
@ -120,6 +120,7 @@ void player_move(Player *player, const Level *level) {
|
|||
}
|
||||
|
||||
void player_step(Player *player, Input *input, const Level *level, uint step) {
|
||||
player_set_vars(player, level);
|
||||
/* Get directionnal input and assign it to move.x/move.y:
|
||||
* i.e., if the player hold left and down move will have
|
||||
* move.x = -1 and move.y = 1. */
|
||||
|
@ -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. */
|
||||
|
|
Reference in New Issue