Mark
/
celeste-ai
Archived
1
0
Fork 0

Improved delays

master
Mark 2023-02-18 18:46:01 -08:00
parent e76a78d199
commit 137f8cefc1
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 55 additions and 66 deletions

View File

@ -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()