forked from kdx/jtmm2-old
Nicer acceleration code and gravity
This commit is contained in:
parent
e306da5e41
commit
c8bd190ec1
11
src/player.c
11
src/player.c
|
@ -8,8 +8,10 @@
|
|||
#include "collide.h"
|
||||
|
||||
/* TODO: Determine FRICTION and ACCELERATION from UPS. */
|
||||
#define MAX_SPD (64 * PXS)
|
||||
#define FRICTION 0.9
|
||||
#define ACCELERATION 64
|
||||
#define ACCELERATION (MAX_SPD * (1 - FRICTION))
|
||||
#define GRAVITY PXS
|
||||
#define SGN(x) ((x > 0) ? (1) : ((x < 0) ? (-1) : (0)))
|
||||
#define PLAYER_COLLIDE(pos) player_collide(player, pos, level, level->solid_layer)
|
||||
|
||||
|
@ -51,9 +53,10 @@ void player_step(Player *player, Input *input, const Level *level) {
|
|||
(input_is_down(input, K_RIGHT) - input_is_down(input, K_LEFT)),
|
||||
(input_is_down(input, K_DOWN) - input_is_down(input, K_UP))
|
||||
};
|
||||
vec_mulf(&player->spd, FRICTION); /* apply friction */
|
||||
vec_mul(&move, ACCELERATION); /* apply acceleration */
|
||||
vec_add(&player->spd, move);
|
||||
int xacc = move.x * ACCELERATION; /* calculate horizontal acceleration */
|
||||
player->spd.x *= FRICTION; /* apply horizontal friction */
|
||||
player->spd.x += xacc; /* apply horizontal acceleration */
|
||||
player->spd.y += GRAVITY; /* apply gravity */
|
||||
player_move(player, level);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue