Implement coyote time
parent
c2c00cfa51
commit
9f3061bae3
|
@ -1,5 +1,6 @@
|
||||||
.cache/
|
.cache/
|
||||||
build/
|
build/
|
||||||
|
release/
|
||||||
web/
|
web/
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
.gdb_history
|
.gdb_history
|
||||||
|
|
|
@ -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, %u", p_cjump->jumps, p_cjump->jump_released);
|
sprintf(buffer, "Jumps: %u, %u, %u", p_cjump->jumps, p_cjump->jump_released, p_cjump->coyote_timer);
|
||||||
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);
|
||||||
|
|
|
@ -74,6 +74,7 @@ typedef struct _CJump_t {
|
||||||
int jump_speed;
|
int jump_speed;
|
||||||
uint8_t jumps;
|
uint8_t jumps;
|
||||||
uint8_t max_jumps;
|
uint8_t max_jumps;
|
||||||
|
uint8_t coyote_timer;
|
||||||
bool jumped;
|
bool jumped;
|
||||||
bool jump_ready;
|
bool jump_ready;
|
||||||
bool short_hop;
|
bool short_hop;
|
||||||
|
|
|
@ -370,7 +370,7 @@ void player_movement_input_system(Scene_t* scene)
|
||||||
{
|
{
|
||||||
p_ctransform->velocity.y = -p_cjump->jump_speed;
|
p_ctransform->velocity.y = -p_cjump->jump_speed;
|
||||||
}
|
}
|
||||||
else
|
else if (p_pstate->ladder_state)
|
||||||
{
|
{
|
||||||
p_ctransform->velocity.y = -p_cjump->jump_speed / 1.4;
|
p_ctransform->velocity.y = -p_cjump->jump_speed / 1.4;
|
||||||
}
|
}
|
||||||
|
@ -380,6 +380,7 @@ void player_movement_input_system(Scene_t* scene)
|
||||||
p_ctransform->velocity.y = -p_cjump->jump_speed / 1.75;
|
p_ctransform->velocity.y = -p_cjump->jump_speed / 1.75;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p_cjump->coyote_timer = 0;
|
||||||
p_cjump->jumped = true;
|
p_cjump->jumped = true;
|
||||||
p_cjump->jump_ready = false;
|
p_cjump->jump_ready = false;
|
||||||
p_cjump->jump_released = false;
|
p_cjump->jump_released = false;
|
||||||
|
@ -1225,8 +1226,13 @@ 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);
|
||||||
|
bool jump_recover_cond = (p_mstate->ground_state & 1 || in_water || p_pstate->ladder_state);
|
||||||
// Landing or in water
|
// Landing or in water
|
||||||
if ((p_mstate->ground_state & 1 || in_water || p_pstate->ladder_state))
|
if (p_mstate->water_state == 0b10 || p_mstate->ground_state == 0b10)
|
||||||
|
{
|
||||||
|
p_cjump->coyote_timer = 3;
|
||||||
|
}
|
||||||
|
else if (jump_recover_cond)
|
||||||
{
|
{
|
||||||
// Recover jumps
|
// Recover jumps
|
||||||
p_cjump->jumps = p_cjump->max_jumps;
|
p_cjump->jumps = p_cjump->max_jumps;
|
||||||
|
@ -1234,8 +1240,15 @@ void player_ground_air_transition_system(Scene_t* scene)
|
||||||
if(!p_cjump->jump_released && !p_pstate->jump_pressed) p_cjump->jump_released = true;
|
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;
|
||||||
|
p_cjump->coyote_timer = 0;
|
||||||
}
|
}
|
||||||
else if (p_mstate->water_state == 0b10 || p_mstate->ground_state == 0b10)
|
else
|
||||||
|
{
|
||||||
|
if (p_cjump->coyote_timer > 0)
|
||||||
|
{
|
||||||
|
p_cjump->coyote_timer--;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
p_cjump->jumps -= (p_cjump->jumps > 0)? 1:0;
|
p_cjump->jumps -= (p_cjump->jumps > 0)? 1:0;
|
||||||
if (p_mstate->ground_state & 1)
|
if (p_mstate->ground_state & 1)
|
||||||
|
@ -1244,6 +1257,7 @@ void player_ground_air_transition_system(Scene_t* scene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void state_transition_update_system(Scene_t* scene)
|
void state_transition_update_system(Scene_t* scene)
|
||||||
|
|
Loading…
Reference in New Issue