From 137f8cefc1597c9be0c383796c8939a070448556 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 18 Feb 2023 18:46:01 -0800 Subject: [PATCH] Improved delays --- celeste/bin/carts/hackcel.p8 | 121 ++++++++++++++++------------------- 1 file changed, 55 insertions(+), 66 deletions(-) diff --git a/celeste/bin/carts/hackcel.p8 b/celeste/bin/carts/hackcel.p8 index f150436..8ba634a 100755 --- a/celeste/bin/carts/hackcel.p8 +++ b/celeste/bin/carts/hackcel.p8 @@ -30,16 +30,17 @@ k_jump=4 k_dash=5 +-- If true, disable screensake +hack_no_shake = true -- False until the game has initialized hack_ready = false -hack_no_shake = true -- Slow down frame rate hack_frame_counter = 0 -hack_frame_freeze = 10 -- Freeze for n frames -hack_frame_foward = 3 -- Run this many frames without sending status -hack_frame_foward_bonus = 0 -- Set when actions need extra frames (like dashes) +hack_frame_freeze = 10 -- Freeze for n frames +hack_frame_foward = 3 -- Run this many frames without sending status +hack_frame_foward_bonus = 0 -- Set when actions need extra frames (like dashes) -- HACK: keep track of player state hack_player_state = {} @@ -277,7 +278,7 @@ player = has_dashed=true -- HACK: fast-forward dashes - hack_frame_foward_bonus = 8 + hack_frame_foward_bonus = 10 hack_can_dash = false this.dash_effect_time=10 @@ -1209,7 +1210,7 @@ end -- default for celeste is 30. function _update() - -- Skip a few frames at start to initialize + -- Run at full speed until ready if not hack_ready then old_update() old_draw() @@ -1221,83 +1222,71 @@ function _update() - - - + -- Do nothing for a few frames. + -- This gives us time to run computations if hack_frame_counter < hack_frame_freeze then - -- Freeze frames hack_frame_counter+=1 return - elseif hack_frame_counter < (hack_frame_foward + hack_frame_freeze + hack_frame_foward_bonus) then - -- Forward frames - hack_frame_counter+=1 - old_update() - old_draw() - extcmd("screen") - else - -- Wait for input - if (not ( - btn(k_left) or - btn(k_right) or - btn(k_up) or - btn(k_down) or - btn(k_jump) or - btn(k_dash) - ) - and hack_has_sent_first_message - ) then - return - end - - - hack_frame_counter = 0 - hack_frame_foward_bonus = 0 - - - old_update() - old_draw() - extcmd("screen") - - hack_has_sent_first_message = true - out_string = "dc:" .. tostr(deaths) .. ";" - - if hack_can_dash then - out_string = out_string .. "ds:t;" - else - out_string = out_string .. "ds:f;" - end - - for k, v in pairs(hack_player_state) do - out_string = out_string .. k ..":" .. v .. ";" - end - printh(out_string) end -end --- Called at the same rate as _update -function _draw() - --old_draw() - - --[[ - if not ( + -- Wait for input + if (not ( btn(k_left) or btn(k_right) or btn(k_up) or btn(k_down) or btn(k_jump) or btn(k_dash) - ) and hack_run_delay then + ) + and hack_has_sent_first_message + ) then return end - if draw_frame_counter < frame_rate_hack and hack_run_delay then - draw_frame_counter += 1 - else - draw_frame_counter = 0 + + -- Delay for input to stabilize + -- Required to reliably send multiple key presses + wait(5) + + -- Run a few frames + for i=1,hack_frame_foward do + old_update() old_draw() + extcmd("screen") end - --]] + + -- Run bonus frames if we earned bonus frames + for i=1,hack_frame_foward_bonus do + old_update() + old_draw() + extcmd("screen") + end + + -- Reset counters + hack_frame_counter = 0 + hack_frame_foward_bonus = 0 + + + hack_has_sent_first_message = true + out_string = "dc:" .. tostr(deaths) .. ";" + + if hack_can_dash then + out_string = out_string .. "ds:t;" + else + out_string = out_string .. "ds:f;" + end + + for k, v in pairs(hack_player_state) do + out_string = out_string .. k ..":" .. v .. ";" + end + printh(out_string) +end + +-- Called at the same rate as _update, +-- but not necessarily at the same time. +function _draw() + --old_draw() end function old_update()