diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-06-21 23:01:18 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-06-21 23:01:18 +0100 |
commit | 16c38fc10c7120bd86f69c25f179f7ed81262a70 (patch) | |
tree | d958b8e930c02695d8e64710c1c2d2d5654e7a0e /src | |
parent | ba2a2dbe3434a1ffc10542ca38e6116c0bde7b65 (diff) | |
download | gold-mine-run-16c38fc10c7120bd86f69c25f179f7ed81262a70.tar.gz gold-mine-run-16c38fc10c7120bd86f69c25f179f7ed81262a70.zip |
Add "coyote time"
If the player moves and gains momentum, allow jumping then the gravity
as already kicked in to make easier tricky jumps.
Diffstat (limited to 'src')
-rw-r--r-- | src/player.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/player.c b/src/player.c index 4fe916e..52595f4 100644 --- a/src/player.c +++ b/src/player.c @@ -25,10 +25,13 @@ #define GRAVITY_SEQ_LEN 24 +/* used for "coyote time" */ +#define MAX_MOMENTUM 8 + #define IS_NOT_GOING_UP(x) (gravity == GRAVITY_OFF || (x)>=GRAVITY_DOWN) static uint16_t x, y; -static uint8_t dir, frame, delay, gravity, jump; +static uint8_t dir, frame, delay, gravity, jump, momentum; const uint8_t gravity_seq[GRAVITY_SEQ_LEN] = { 6, 4, 4, 2, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 4 @@ -72,6 +75,7 @@ void player_init(uint16_t start_x, uint8_t start_y) frame = FRAME_STANDING; delay = 0; jump = 0; + momentum = 0; x = start_x; y = start_y; @@ -82,6 +86,9 @@ void player_update() { uint8_t moved = 0; + if (momentum) + momentum--; + if (gravity == GRAVITY_OFF && !map_is_blocked(x + 4, y + 16) && !map_is_blocked(x + 11, y + 16)) @@ -93,9 +100,10 @@ void player_update() if (keys[KEY_UP]) { - if (gravity == GRAVITY_OFF && !jump) + if ((gravity == GRAVITY_OFF || momentum) && !jump) { jump = 1; + momentum = 0; frame = FRAME_JUMPING; gravity = GRAVITY_UP; } @@ -115,7 +123,11 @@ void player_update() || (!IS_NOT_GOING_UP(gravity) && !(map_is_blocked(x + 16, y + 15) && map_is_blocked(x + 16, y + 7)))) + { + if (gravity == GRAVITY_OFF && momentum < MAX_MOMENTUM) + momentum += 4; x++; + } } } @@ -131,7 +143,11 @@ void player_update() || (!IS_NOT_GOING_UP(gravity) && !(map_is_blocked(x - 1, y + 15) && map_is_blocked(x - 1, y + 7)))) + { + if (gravity == GRAVITY_OFF && momentum < MAX_MOMENTUM) + momentum += 4; x--; + } } } |