From d83ecdfb615aaf71e2807886488941bc1cb7a80d Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sat, 3 Dec 2022 11:13:40 -0800 Subject: game: give adult some acceleration steps from standstill When navigating tight situations the existing instantaneous 0-100 is difficult to control. By introducing a small bit of acceleration, one can pulse the controls to make small movements. Note this doesn't introduce a deceleration curve, movement still stops immediately upon release of the controls. It's not anything like a physics simulation, it's just a few frames worth of ramping up to 100% movement speed for the adult, plain linear ramp for now. Now it feels like pixel-accurate collision detection might be worth adding... --- src/game.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/game.c') diff --git a/src/game.c b/src/game.c index 1f0cf8d..f2133d3 100644 --- a/src/game.c +++ b/src/game.c @@ -48,7 +48,8 @@ #define GAME_NUM_BABIES 10 #define GAME_VIRUS_SPEED .01f -#define GAME_ADULT_SPEED .04f +#define GAME_ADULT_SPEED .05f +#define GAME_ADULT_ACCEL .25f #define GAME_MASK_SPEED .02f #define GAME_ENTITIES_DELAY_MS 20 @@ -1051,6 +1052,7 @@ static void game_update(play_t *play, void *context) if (play_ticks_elapsed(play, GAME_KBD_TIMER, GAME_KBD_DELAY_MS)) { const Uint8 *key_state = SDL_GetKeyboardState(NULL); v2f_t dir = {}, *move = NULL; + static float velocity; /* TODO: acceleration curve for movement? it'd enable more precise * negotiating of obstacles, but that's not really worthwhile until there's @@ -1084,14 +1086,20 @@ static void game_update(play_t *play, void *context) if (move) { float distance; + if (velocity < 1.f) + velocity += GAME_ADULT_ACCEL; + if (velocity > 1.f) + velocity = 1.f; + distance = v2f_length(move); if (distance) { *move = v2f_normalize(move); - *move = v2f_mult_scalar(move, distance < GAME_ADULT_SPEED ? distance : GAME_ADULT_SPEED); + *move = v2f_mult_scalar(move, velocity * (distance < GAME_ADULT_SPEED ? distance : GAME_ADULT_SPEED)); } game_move_adult(game, move); - } + } else + velocity = 0; } if (play_ticks_elapsed(play, GAME_TV_TIMER, GAME_TV_DELAY_MS)) { -- cgit v1.2.3