Mark
/
celeste-ai
Archived
1
0
Fork 0

Reworked celeste integration

master
Mark 2023-02-17 22:27:53 -08:00
parent 1216378c49
commit 720a1b63c4
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 109 additions and 31 deletions

View File

@ -29,21 +29,23 @@ k_down=3
k_jump=4 k_jump=4
k_dash=5 k_dash=5
-- HACK: used to slow down frame rate
frame_counter = 0
draw_frame_counter = 0
-- False until the game has initialized -- False until the game has initialized
hack_ready = false hack_ready = false
hack_no_shake = true
-- Skip each nth frame. -- Slow down frame rate
-- Celeste usually runs at 30 fps, we run it at 60. hack_frame_counter = 0
-- so, a value of 2 gives normal speed hack_frame_freeze = 10 -- Freeze for n frames
-- and a value of 3 gives 3/2 speed. hack_frame_foward = 3 -- Run this many frames without sending status
frame_rate_hack = 10 hack_frame_foward_bonus = 0 -- Set when actions need extra frames (like dashes)
-- HACK: keep track of player state -- HACK: keep track of player state
player_state = {} hack_player_state = {}
hack_can_dash = false
hack_has_sent_first_message = false
-- entry point -- -- entry point --
----------------- -----------------
@ -157,6 +159,10 @@ player =
local on_ground=this.is_solid(0,1) local on_ground=this.is_solid(0,1)
local on_ice=this.is_ice(0,1) local on_ice=this.is_ice(0,1)
if on_ground then
hack_can_dash = true
end
-- smoke particles -- smoke particles
if on_ground and not this.was_on_ground then if on_ground and not this.was_on_ground then
init_object(smoke,this.x,this.y+4) init_object(smoke,this.x,this.y+4)
@ -269,6 +275,11 @@ player =
this.djump-=1 this.djump-=1
this.dash_time=4 this.dash_time=4
has_dashed=true has_dashed=true
-- HACK: fast-forward dashes
hack_frame_foward_bonus = 8
hack_can_dash = false
this.dash_effect_time=10 this.dash_effect_time=10
local v_input=(btn(k_up) and -1 or (btn(k_down) and 1 or 0)) local v_input=(btn(k_up) and -1 or (btn(k_down) and 1 or 0))
if input!=0 then if input!=0 then
@ -337,9 +348,8 @@ player =
this.was_on_ground=on_ground this.was_on_ground=on_ground
-- HACK: print player status
hack_ready = true hack_ready = true
player_state = { hack_player_state = {
px = tostr(this.x), px = tostr(this.x),
py = tostr(this.y), py = tostr(this.y),
vx = tostr(this.spd.x), vx = tostr(this.spd.x),
@ -1194,34 +1204,100 @@ end
----------------------- -----------------------
-- _update30 runs at 30 fps -- _update runs at 30 fps
-- _update60 does 60 fps -- _update60 does 60 fps
-- default for celeste is 30. -- default for celeste is 30.
function _update60() function _update()
if frame_counter < frame_rate_hack then
frame_counter+=1
else
frame_counter = 0
old_update()
if hack_ready then -- Skip a few frames at start to initialize
if not hack_ready then
old_update()
old_draw()
-- Screenshot
extcmd("screen")
return
end
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) .. ";" out_string = "dc:" .. tostr(deaths) .. ";"
for k, v in pairs(player_state) do
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 .. ";" out_string = out_string .. k ..":" .. v .. ";"
end end
printh(out_string) printh(out_string)
end end
end
end end
-- Called at the same rate as _update -- Called at the same rate as _update
function _draw() function _draw()
if draw_frame_counter < frame_rate_hack then
--old_draw()
--[[
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
return
end
if draw_frame_counter < frame_rate_hack and hack_run_delay then
draw_frame_counter += 1 draw_frame_counter += 1
else else
draw_frame_counter = 0 draw_frame_counter = 0
old_draw() old_draw()
end end
--]]
end end
function old_update() function old_update()
@ -1248,6 +1324,7 @@ function old_update()
if freeze>0 then freeze-=1 return end if freeze>0 then freeze-=1 return end
-- screenshake -- screenshake
if not hack_no_shake then
if shake>0 then if shake>0 then
shake-=1 shake-=1
camera() camera()
@ -1255,6 +1332,7 @@ function old_update()
camera(-2+rnd(5),-2+rnd(5)) camera(-2+rnd(5),-2+rnd(5))
end end
end end
end
-- restart (soon) -- restart (soon)
if will_restart and delay_restart>0 then if will_restart and delay_restart>0 then