Add quake-style jump buffering

scene_man
En Yi 2023-09-28 21:31:52 +08:00
parent 5398c08782
commit c2c00cfa51
3 changed files with 9 additions and 6 deletions

View File

@ -439,7 +439,7 @@ static void level_scene_render_func(Scene_t* scene)
DrawText(buffer, gui_x + 80, gui_y, 12, BLACK); DrawText(buffer, gui_x + 80, gui_y, 12, BLACK);
gui_y += 45; gui_y += 45;
sprintf(buffer, "Jumps: %u", p_cjump->jumps); sprintf(buffer, "Jumps: %u, %u", p_cjump->jumps, p_cjump->jump_released);
DrawText(buffer, gui_x, gui_y, 12, BLACK); DrawText(buffer, gui_x, gui_y, 12, BLACK);
gui_y += 30; gui_y += 30;
sprintf(buffer, "Crouch: %u", p_pstate->is_crouch); sprintf(buffer, "Crouch: %u", p_pstate->is_crouch);

View File

@ -71,12 +71,13 @@ typedef struct _CTileCoord_t {
} CTileCoord_t; } CTileCoord_t;
typedef struct _CJump_t { typedef struct _CJump_t {
unsigned int jumps;
unsigned int max_jumps;
int jump_speed; int jump_speed;
uint8_t jumps;
uint8_t max_jumps;
bool jumped; bool jumped;
bool jump_ready; bool jump_ready;
bool short_hop; bool short_hop;
bool jump_released;
} CJump_t; } CJump_t;
typedef enum PlayerState { typedef enum PlayerState {

View File

@ -337,6 +337,7 @@ void player_movement_input_system(Scene_t* scene)
{ {
if (!p_pstate->jump_pressed) if (!p_pstate->jump_pressed)
{ {
p_cjump->jump_released = true;
if (!p_cjump->short_hop && p_ctransform->velocity.y < 0) if (!p_cjump->short_hop && p_ctransform->velocity.y < 0)
{ {
p_cjump->short_hop = true; p_cjump->short_hop = true;
@ -359,7 +360,7 @@ void player_movement_input_system(Scene_t* scene)
// Jumps is possible as long as you have a jump // Jumps is possible as long as you have a jump
// Check if possible to jump when jump is pressed // Check if possible to jump when jump is pressed
if (p_pstate->jump_pressed && p_cjump->jumps > 0 && p_cjump->jump_ready) if (p_cjump->jump_released && p_pstate->jump_pressed && p_cjump->jumps > 0 && p_cjump->jump_ready)
{ {
p_pstate->ladder_state = false; p_pstate->ladder_state = false;
p_cjump->jumps--; p_cjump->jumps--;
@ -381,8 +382,8 @@ void player_movement_input_system(Scene_t* scene)
p_cjump->jumped = true; p_cjump->jumped = true;
p_cjump->jump_ready = false; p_cjump->jump_ready = false;
p_cjump->jump_released = false;
} }
} }
} }
@ -1225,11 +1226,12 @@ void player_ground_air_transition_system(Scene_t* scene)
// Handle Ground<->Air Transition // Handle Ground<->Air Transition
bool in_water = (p_mstate->water_state & 1); bool in_water = (p_mstate->water_state & 1);
// Landing or in water // Landing or in water
if ((p_mstate->ground_state & 1 || in_water || p_pstate->ladder_state) && !p_pstate->jump_pressed ) if ((p_mstate->ground_state & 1 || in_water || p_pstate->ladder_state))
{ {
// Recover jumps // Recover jumps
p_cjump->jumps = p_cjump->max_jumps; p_cjump->jumps = p_cjump->max_jumps;
p_cjump->jumped = false; p_cjump->jumped = false;
if(!p_cjump->jump_released && !p_pstate->jump_pressed) p_cjump->jump_released = true;
p_cjump->short_hop = false; p_cjump->short_hop = false;
p_cjump->jump_ready = true; p_cjump->jump_ready = true;
} }