From 16c38fc10c7120bd86f69c25f179f7ed81262a70 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Wed, 21 Jun 2023 23:01:18 +0100 Subject: Add "coyote time" If the player moves and gains momentum, allow jumping then the gravity as already kicked in to make easier tricky jumps. --- TODO.md | 4 +++- src/player.c | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 92957ad..aacb433 100644 --- a/TODO.md +++ b/TODO.md @@ -3,7 +3,9 @@ - entity system - free/used lists - player - - "coyote time" + - damage + - invulnerable + - respawn - map - entities - pick ups 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--; + } } } -- cgit v1.2.3