summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-12-03 11:13:40 -0800
committerVito Caputo <vcaputo@pengaru.com>2022-12-03 11:16:16 -0800
commitd83ecdfb615aaf71e2807886488941bc1cb7a80d (patch)
treebbaf68986429fab254cf6289fb5c7b9891bb7a18
parent5cf1d72cef303cc71a6a2295ff0074a8e40b5cd6 (diff)
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...
-rw-r--r--src/game.c14
1 files changed, 11 insertions, 3 deletions
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)) {
© All Rights Reserved