Mark
/
celeste-ai
Archived
1
0
Fork 0

Modified celeste cart

master
Mark 2023-02-15 19:30:44 -08:00
parent f0c69e551c
commit aaab67e054
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 103 additions and 78 deletions

View File

@ -29,9 +29,16 @@ 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
-- entry point -- -- entry point --
----------------- -----------------
-- HACK: wait function to slow down frame rate
function wait(a) for i = 1,a do flip() end end
function _init() function _init()
title_screen() title_screen()
end end
@ -46,7 +53,7 @@ function title_screen()
start_game=false start_game=false
start_game_flash=0 start_game_flash=0
music(40,0,7) music(40,0,7)
-- HACK: skip title screen -- HACK: skip title screen
begin_game() begin_game()
@ -104,9 +111,9 @@ dead_particles = {}
-- player entity -- -- player entity --
------------------- -------------------
player = player =
{ {
init=function(this) init=function(this)
this.p_jump=false this.p_jump=false
this.p_dash=false this.p_dash=false
this.grace=0 this.grace=0
@ -123,20 +130,20 @@ player =
end, end,
update=function(this) update=function(this)
if (pause_player) return if (pause_player) return
local input = btn(k_right) and 1 or (btn(k_left) and -1 or 0) local input = btn(k_right) and 1 or (btn(k_left) and -1 or 0)
-- spikes collide -- spikes collide
if spikes_at(this.x+this.hitbox.x,this.y+this.hitbox.y,this.hitbox.w,this.hitbox.h,this.spd.x,this.spd.y) then if spikes_at(this.x+this.hitbox.x,this.y+this.hitbox.y,this.hitbox.w,this.hitbox.h,this.spd.x,this.spd.y) then
kill_player(this) end kill_player(this) end
-- bottom death -- bottom death
if this.y>128 then if this.y>128 then
kill_player(this) end kill_player(this) end
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)
-- 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)
@ -149,10 +156,10 @@ player =
elseif this.jbuffer>0 then elseif this.jbuffer>0 then
this.jbuffer-=1 this.jbuffer-=1
end end
local dash = btn(k_dash) and not this.p_dash local dash = btn(k_dash) and not this.p_dash
this.p_dash = btn(k_dash) this.p_dash = btn(k_dash)
if on_ground then if on_ground then
this.grace=6 this.grace=6
if this.djump<max_djump then if this.djump<max_djump then
@ -168,14 +175,14 @@ player =
init_object(smoke,this.x,this.y) init_object(smoke,this.x,this.y)
this.dash_time-=1 this.dash_time-=1
this.spd.x=appr(this.spd.x,this.dash_target.x,this.dash_accel.x) this.spd.x=appr(this.spd.x,this.dash_target.x,this.dash_accel.x)
this.spd.y=appr(this.spd.y,this.dash_target.y,this.dash_accel.y) this.spd.y=appr(this.spd.y,this.dash_target.y,this.dash_accel.y)
else else
-- move -- move
local maxrun=1 local maxrun=1
local accel=0.6 local accel=0.6
local deccel=0.15 local deccel=0.15
if not on_ground then if not on_ground then
accel=0.4 accel=0.4
elseif on_ice then elseif on_ice then
@ -184,13 +191,13 @@ player =
accel=0.05 accel=0.05
end end
end end
if abs(this.spd.x) > maxrun then if abs(this.spd.x) > maxrun then
this.spd.x=appr(this.spd.x,sign(this.spd.x)*maxrun,deccel) this.spd.x=appr(this.spd.x,sign(this.spd.x)*maxrun,deccel)
else else
this.spd.x=appr(this.spd.x,input*maxrun,accel) this.spd.x=appr(this.spd.x,input*maxrun,accel)
end end
--facing --facing
if this.spd.x!=0 then if this.spd.x!=0 then
this.flip.x=(this.spd.x<0) this.flip.x=(this.spd.x<0)
@ -203,7 +210,7 @@ player =
if abs(this.spd.y) <= 0.15 then if abs(this.spd.y) <= 0.15 then
gravity*=0.5 gravity*=0.5
end end
-- wall slide -- wall slide
if input!=0 and this.is_solid(input,0) and not this.is_ice(input,0) then if input!=0 and this.is_solid(input,0) and not this.is_ice(input,0) then
maxfall=0.4 maxfall=0.4
@ -239,14 +246,14 @@ player =
end end
end end
end end
-- dash -- dash
local d_full=5 local d_full=5
local d_half=d_full*0.70710678118 local d_half=d_full*0.70710678118
if this.djump>0 and dash then if this.djump>0 and dash then
init_object(smoke,this.x,this.y) init_object(smoke,this.x,this.y)
this.djump-=1 this.djump-=1
this.dash_time=4 this.dash_time=4
has_dashed=true has_dashed=true
this.dash_effect_time=10 this.dash_effect_time=10
@ -266,7 +273,7 @@ player =
this.spd.x=(this.flip.x and -1 or 1) this.spd.x=(this.flip.x and -1 or 1)
this.spd.y=0 this.spd.y=0
end end
psfx(3) psfx(3)
freeze=2 freeze=2
shake=6 shake=6
@ -274,24 +281,24 @@ player =
this.dash_target.y=2*sign(this.spd.y) this.dash_target.y=2*sign(this.spd.y)
this.dash_accel.x=1.5 this.dash_accel.x=1.5
this.dash_accel.y=1.5 this.dash_accel.y=1.5
if this.spd.y<0 then if this.spd.y<0 then
this.dash_target.y*=.75 this.dash_target.y*=.75
end end
if this.spd.y!=0 then if this.spd.y!=0 then
this.dash_accel.x*=0.70710678118 this.dash_accel.x*=0.70710678118
end end
if this.spd.x!=0 then if this.spd.x!=0 then
this.dash_accel.y*=0.70710678118 this.dash_accel.y*=0.70710678118
end end
elseif dash and this.djump<=0 then elseif dash and this.djump<=0 then
psfx(9) psfx(9)
init_object(smoke,this.x,this.y) init_object(smoke,this.x,this.y)
end end
end end
-- animation -- animation
this.spr_off+=0.25 this.spr_off+=0.25
if not on_ground then if not on_ground then
@ -309,13 +316,13 @@ player =
else else
this.spr=1+this.spr_off%4 this.spr=1+this.spr_off%4
end end
-- next level -- next level
if this.y<-4 and level_index()<30 then next_room() end if this.y<-4 and level_index()<30 then next_room() end
-- was on the ground -- was on the ground
this.was_on_ground=on_ground this.was_on_ground=on_ground
-- HACK: print player status -- HACK: print player status
printh( printh(
@ -328,18 +335,18 @@ player =
) )
end, --<end update loop end, --<end update loop
draw=function(this) draw=function(this)
-- clamp in screen -- clamp in screen
if this.x<-1 or this.x>121 then if this.x<-1 or this.x>121 then
this.x=clamp(this.x,-1,121) this.x=clamp(this.x,-1,121)
this.spd.x=0 this.spd.x=0
end end
set_hair_color(this.djump) set_hair_color(this.djump)
draw_hair(this,this.flip.x and -1 or 1) draw_hair(this,this.flip.x and -1 or 1)
spr(this.spr,this.x,this.y,1,1,this.flip.x,this.flip.y) spr(this.spr,this.x,this.y,1,1,this.flip.x,this.flip.y)
unset_hair_color() unset_hair_color()
end end
} }
@ -453,19 +460,19 @@ spring = {
hit.djump=max_djump hit.djump=max_djump
this.delay=10 this.delay=10
init_object(smoke,this.x,this.y) init_object(smoke,this.x,this.y)
-- breakable below us -- breakable below us
local below=this.collide(fall_floor,0,1) local below=this.collide(fall_floor,0,1)
if below~=nil then if below~=nil then
break_fall_floor(below) break_fall_floor(below)
end end
psfx(8) psfx(8)
end end
elseif this.delay>0 then elseif this.delay>0 then
this.delay-=1 this.delay-=1
if this.delay<=0 then if this.delay<=0 then
this.spr=18 this.spr=18
end end
end end
-- begin hiding -- begin hiding
@ -486,13 +493,13 @@ end
balloon = { balloon = {
tile=22, tile=22,
init=function(this) init=function(this)
this.offset=rnd(1) this.offset=rnd(1)
this.start=this.y this.start=this.y
this.timer=0 this.timer=0
this.hitbox={x=-1,y=-1,w=10,h=10} this.hitbox={x=-1,y=-1,w=10,h=10}
end, end,
update=function(this) update=function(this)
if this.spr==22 then if this.spr==22 then
this.offset+=0.01 this.offset+=0.01
this.y=this.start+sin(this.offset)*2 this.y=this.start+sin(this.offset)*2
@ -506,10 +513,10 @@ balloon = {
end end
elseif this.timer>0 then elseif this.timer>0 then
this.timer-=1 this.timer-=1
else else
psfx(7) psfx(7)
init_object(smoke,this.x,this.y) init_object(smoke,this.x,this.y)
this.spr=22 this.spr=22
end end
end, end,
draw=function(this) draw=function(this)
@ -599,7 +606,7 @@ smoke={
fruit={ fruit={
tile=26, tile=26,
if_not_fruit=true, if_not_fruit=true,
init=function(this) init=function(this)
this.start=this.y this.start=this.y
this.off=0 this.off=0
end, end,
@ -622,7 +629,7 @@ add(types,fruit)
fly_fruit={ fly_fruit={
tile=28, tile=28,
if_not_fruit=true, if_not_fruit=true,
init=function(this) init=function(this)
this.start=this.y this.start=this.y
this.fly=false this.fly=false
this.step=0.5 this.step=0.5
@ -903,7 +910,7 @@ orb={
max_djump=2 max_djump=2
hit.djump=2 hit.djump=2
end end
spr(102,this.x,this.y) spr(102,this.x,this.y)
local off=frames/30 local off=frames/30
for i=0,7 do for i=0,7 do
@ -951,7 +958,7 @@ room_title = {
if this.delay<-30 then if this.delay<-30 then
destroy_object(this) destroy_object(this)
elseif this.delay<0 then elseif this.delay<0 then
rectfill(24,58,104,70,0) rectfill(24,58,104,70,0)
--rect(26,64-10,102,64+10,7) --rect(26,64-10,102,64+10,7)
--print("---",31,64-2,13) --print("---",31,64-2,13)
@ -964,7 +971,7 @@ room_title = {
print(level.." m",52+(level<1000 and 2 or 0),62,7) print(level.." m",52+(level<1000 and 2 or 0),62,7)
end end
--print("---",86,64-2,13) --print("---",86,64-2,13)
draw_time(4,4) draw_time(4,4)
end end
end end
@ -1000,30 +1007,30 @@ function init_object(type,x,y)
or obj.check(fall_floor,ox,oy) or obj.check(fall_floor,ox,oy)
or obj.check(fake_wall,ox,oy) or obj.check(fake_wall,ox,oy)
end end
obj.is_ice=function(ox,oy) obj.is_ice=function(ox,oy)
return ice_at(obj.x+obj.hitbox.x+ox,obj.y+obj.hitbox.y+oy,obj.hitbox.w,obj.hitbox.h) return ice_at(obj.x+obj.hitbox.x+ox,obj.y+obj.hitbox.y+oy,obj.hitbox.w,obj.hitbox.h)
end end
obj.collide=function(type,ox,oy) obj.collide=function(type,ox,oy)
local other local other
for i=1,count(objects) do for i=1,count(objects) do
other=objects[i] other=objects[i]
if other ~=nil and other.type == type and other != obj and other.collideable and if other ~=nil and other.type == type and other != obj and other.collideable and
other.x+other.hitbox.x+other.hitbox.w > obj.x+obj.hitbox.x+ox and other.x+other.hitbox.x+other.hitbox.w > obj.x+obj.hitbox.x+ox and
other.y+other.hitbox.y+other.hitbox.h > obj.y+obj.hitbox.y+oy and other.y+other.hitbox.y+other.hitbox.h > obj.y+obj.hitbox.y+oy and
other.x+other.hitbox.x < obj.x+obj.hitbox.x+obj.hitbox.w+ox and other.x+other.hitbox.x < obj.x+obj.hitbox.x+obj.hitbox.w+ox and
other.y+other.hitbox.y < obj.y+obj.hitbox.y+obj.hitbox.h+oy then other.y+other.hitbox.y < obj.y+obj.hitbox.y+obj.hitbox.h+oy then
return other return other
end end
end end
return nil return nil
end end
obj.check=function(type,ox,oy) obj.check=function(type,ox,oy)
return obj.collide(type,ox,oy) ~=nil return obj.collide(type,ox,oy) ~=nil
end end
obj.move=function(ox,oy) obj.move=function(ox,oy)
local amount local amount
-- [x] get move amount -- [x] get move amount
@ -1031,14 +1038,14 @@ function init_object(type,x,y)
amount = flr(obj.rem.x + 0.5) amount = flr(obj.rem.x + 0.5)
obj.rem.x -= amount obj.rem.x -= amount
obj.move_x(amount,0) obj.move_x(amount,0)
-- [y] get move amount -- [y] get move amount
obj.rem.y += oy obj.rem.y += oy
amount = flr(obj.rem.y + 0.5) amount = flr(obj.rem.y + 0.5)
obj.rem.y -= amount obj.rem.y -= amount
obj.move_y(amount) obj.move_y(amount)
end end
obj.move_x=function(amount,start) obj.move_x=function(amount,start)
if obj.solids then if obj.solids then
local step = sign(amount) local step = sign(amount)
@ -1055,7 +1062,7 @@ function init_object(type,x,y)
obj.x += amount obj.x += amount
end end
end end
obj.move_y=function(amount) obj.move_y=function(amount)
if obj.solids then if obj.solids then
local step = sign(amount) local step = sign(amount)
@ -1159,16 +1166,16 @@ function load_room(x,y)
elseif tile==12 then elseif tile==12 then
init_object(platform,tx*8,ty*8).dir=1 init_object(platform,tx*8,ty*8).dir=1
else else
foreach(types, foreach(types,
function(type) function(type)
if type.tile == tile then if type.tile == tile then
init_object(type,tx*8,ty*8) init_object(type,tx*8,ty*8)
end end
end) end)
end end
end end
end end
if not is_title() then if not is_title() then
init_object(room_title,0,0) init_object(room_title,0,0)
end end
@ -1177,7 +1184,25 @@ end
-- update function -- -- update function --
----------------------- -----------------------
-- _update30 runs at 30 fps
-- _update60 does 60 fps
-- default for celeste is 30.
function _update() function _update()
--wait(10)
old_update()
--[[
if frame_counter < 10 then
frame_counter+=1
else
frame_counter = 0
old_update()
end
]]--
end
function old_update()
frames=((frames+1)%30) frames=((frames+1)%30)
if frames==0 and level_index()<30 then if frames==0 and level_index()<30 then
seconds=((seconds+1)%60) seconds=((seconds+1)%60)
@ -1185,18 +1210,18 @@ function _update()
minutes+=1 minutes+=1
end end
end end
if music_timer>0 then if music_timer>0 then
music_timer-=1 music_timer-=1
if music_timer<=0 then if music_timer<=0 then
music(10,0,7) music(10,0,7)
end end
end end
if sfx_timer>0 then if sfx_timer>0 then
sfx_timer-=1 sfx_timer-=1
end end
-- cancel if freeze -- cancel if freeze
if freeze>0 then freeze-=1 return end if freeze>0 then freeze-=1 return end
@ -1208,7 +1233,7 @@ function _update()
camera(-2+rnd(5),-2+rnd(5)) camera(-2+rnd(5),-2+rnd(5))
end end
end end
-- restart (soon) -- restart (soon)
if will_restart and delay_restart>0 then if will_restart and delay_restart>0 then
delay_restart-=1 delay_restart-=1
@ -1222,10 +1247,10 @@ function _update()
foreach(objects,function(obj) foreach(objects,function(obj)
obj.move(obj.spd.x,obj.spd.y) obj.move(obj.spd.x,obj.spd.y)
if obj.type.update~=nil then if obj.type.update~=nil then
obj.type.update(obj) obj.type.update(obj)
end end
end) end)
-- start game -- start game
if is_title() then if is_title() then
if not start_game and (btn(k_jump) or btn(k_dash)) then if not start_game and (btn(k_jump) or btn(k_dash)) then
@ -1247,10 +1272,10 @@ end
----------------------- -----------------------
function _draw() function _draw()
if freeze>0 then return end if freeze>0 then return end
-- reset all palette values -- reset all palette values
pal() pal()
-- start game flash -- start game flash
if start_game then if start_game then
local c=10 local c=10
@ -1262,7 +1287,7 @@ function _draw()
c=2 c=2
elseif start_game_flash>0 then elseif start_game_flash>0 then
c=1 c=1
else else
c=0 c=0
end end
if c<10 then if c<10 then
@ -1309,29 +1334,29 @@ function _draw()
-- draw terrain -- draw terrain
local off=is_title() and -4 or 0 local off=is_title() and -4 or 0
map(room.x*16,room.y * 16,off,0,16,16,2) map(room.x*16,room.y * 16,off,0,16,16,2)
-- draw objects -- draw objects
foreach(objects, function(o) foreach(objects, function(o)
if o.type~=platform and o.type~=big_chest then if o.type~=platform and o.type~=big_chest then
draw_object(o) draw_object(o)
end end
end) end)
-- draw fg terrain -- draw fg terrain
map(room.x * 16,room.y * 16,0,0,16,16,8) map(room.x * 16,room.y * 16,0,0,16,16,8)
-- particles -- particles
foreach(particles, function(p) foreach(particles, function(p)
p.x += p.spd p.x += p.spd
p.y += sin(p.off) p.y += sin(p.off)
p.off+= min(0.05,p.spd/32) p.off+= min(0.05,p.spd/32)
rectfill(p.x,p.y,p.x+p.s,p.y+p.s,p.c) rectfill(p.x,p.y,p.x+p.s,p.y+p.s,p.c)
if p.x>128+4 then if p.x>128+4 then
p.x=-4 p.x=-4
p.y=rnd(128) p.y=rnd(128)
end end
end) end)
-- dead particles -- dead particles
foreach(dead_particles, function(p) foreach(dead_particles, function(p)
p.x += p.spd.x p.x += p.spd.x
@ -1340,20 +1365,20 @@ function _draw()
if p.t <= 0 then del(dead_particles,p) end if p.t <= 0 then del(dead_particles,p) end
rectfill(p.x-p.t/5,p.y-p.t/5,p.x+p.t/5,p.y+p.t/5,14+p.t%2) rectfill(p.x-p.t/5,p.y-p.t/5,p.x+p.t/5,p.y+p.t/5,14+p.t%2)
end) end)
-- draw outside of the screen for screenshake -- draw outside of the screen for screenshake
rectfill(-5,-5,-1,133,0) rectfill(-5,-5,-1,133,0)
rectfill(-5,-5,133,-1,0) rectfill(-5,-5,133,-1,0)
rectfill(-5,128,133,133,0) rectfill(-5,128,133,133,0)
rectfill(128,-5,133,133,0) rectfill(128,-5,133,133,0)
-- credits -- credits
if is_title() then if is_title() then
print("x+c",58,80,5) print("x+c",58,80,5)
print("matt thorson",42,96,5) print("matt thorson",42,96,5)
print("noel berry",46,102,5) print("noel berry",46,102,5)
end end
if level_index()==30 then if level_index()==30 then
local p local p
for i=1,count(objects) do for i=1,count(objects) do
@ -1386,7 +1411,7 @@ function draw_time(x,y)
local s=seconds local s=seconds
local m=minutes%60 local m=minutes%60
local h=flr(minutes/60) local h=flr(minutes/60)
rectfill(x,y,x+32,y+6,0) rectfill(x,y,x+32,y+6,0)
print((h<10 and "0"..h or h)..":"..(m<10 and "0"..m or m)..":"..(s<10 and "0"..s or s),x+1,y+1,7) print((h<10 and "0"..h or h)..":"..(m<10 and "0"..m or m)..":"..(s<10 and "0"..s or s),x+1,y+1,7)
@ -1400,8 +1425,8 @@ function clamp(val,a,b)
end end
function appr(val,target,amount) function appr(val,target,amount)
return val > target return val > target
and max(val - amount, target) and max(val - amount, target)
or min(val + amount, target) or min(val + amount, target)
end end