forked from pyrex/chameleonic
main #12
112
chameleonic.p8
112
chameleonic.p8
@ -584,54 +584,27 @@ player={}
|
|||||||
add(real_modules,player)
|
add(real_modules,player)
|
||||||
|
|
||||||
function player:init()
|
function player:init()
|
||||||
--self:reinit(8,14)
|
|
||||||
|
|
||||||
-- don't change this on reinit:
|
-- don't change this on reinit:
|
||||||
-- it stays the same when the level is changed or reloaded
|
-- it stays the same when the level is changed or reloaded
|
||||||
self.vanish_frame=0
|
self.vanish_frame=0
|
||||||
end
|
end
|
||||||
|
|
||||||
function player:reinit(x,y)
|
function player:reinit(x,y)
|
||||||
self.x=x
|
self.x,self.y=x,y
|
||||||
self.y=y
|
self.px,self.py=0,0
|
||||||
self.px=0
|
|
||||||
self.py=0
|
|
||||||
self.todo={}
|
self.todo={}
|
||||||
|
|
||||||
self.fall_frame=0
|
self.fall_frame=0
|
||||||
self.reset_frame=0
|
|
||||||
|
|
||||||
self.orientx=-1
|
self.orientx,self.orienty=-1,0
|
||||||
self.orienty=0
|
|
||||||
|
|
||||||
self.rope=nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function player:any_busy()
|
|
||||||
if (#self.todo>0) return true
|
|
||||||
if (level:busy()) return true
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function player:update()
|
function player:update()
|
||||||
local _addall=function(t,xs)
|
|
||||||
for i in all(xs) do
|
|
||||||
add(t,i)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local f4 = function(xs)
|
|
||||||
-- todo: other anim stuff
|
|
||||||
xs[#xs].px=0
|
|
||||||
xs[#xs].py=0
|
|
||||||
return xs
|
|
||||||
end
|
|
||||||
|
|
||||||
-- this is a non-gameplay action that takes precedence over
|
-- this is a non-gameplay action that takes precedence over
|
||||||
-- all gameplay actions
|
-- all gameplay actions
|
||||||
self:_vanish_if_requested()
|
self:_vanish_if_requested()
|
||||||
|
|
||||||
if not self:any_busy() then
|
if not (#self.todo>0 or level:busy()) then
|
||||||
if level:win_at(self.x,self.y) then
|
if level:win_at(self.x,self.y) then
|
||||||
level:advance()
|
level:advance()
|
||||||
return
|
return
|
||||||
@ -660,23 +633,19 @@ function player:update()
|
|||||||
end
|
end
|
||||||
-- wait for user to release it
|
-- wait for user to release it
|
||||||
else
|
else
|
||||||
|
local function try_move(dx,dy,f)
|
||||||
|
if (level:can_move(true,self.x,self.y,dx,dy,0,2)) self.todo=f return
|
||||||
|
wrongbleep:bleep()
|
||||||
|
end
|
||||||
if kbd:btn(0) then
|
if kbd:btn(0) then
|
||||||
if level:can_move(true,self.x,self.y,-1,0,0,2) then
|
try_move(-1,0,{{orientx=-1,orienty=0,px=-2},{px=-7},{x=self.x-1,px=0}})
|
||||||
self.todo=f4({{orientx=-1,orienty=0,px=-2},{px=-7},{x=self.x-1}})
|
|
||||||
else wrongbleep:bleep() end
|
|
||||||
elseif kbd:btn(1) then
|
elseif kbd:btn(1) then
|
||||||
if level:can_move(true,self.x,self.y,1,0,0,2) then
|
try_move(1,0,{{orientx=1,orienty=0,px=2},{px=7},{x=self.x+1,px=0}})
|
||||||
self.todo=f4({{orientx=1,orienty=0,px=2},{px=7},{x=self.x+1}})
|
|
||||||
else wrongbleep:bleep() end
|
|
||||||
elseif kbd:btn(2) then
|
elseif kbd:btn(2) then
|
||||||
if level:can_move(true,self.x,self.y,0,-1,0,2) then
|
try_move(0,-1,{{orienty=-1,py=-2},{py=-7},{y=self.y-1,py=0}})
|
||||||
self.todo=f4({{orienty=-1,py=-2},{py=-7},{y=self.y-1}})
|
|
||||||
else wrongbleep:bleep() end
|
|
||||||
elseif kbd:btn(3) then
|
elseif kbd:btn(3) then
|
||||||
if level:can_move(true,self.x,self.y,0,1,0,2) then
|
try_move(0,1,{{orienty=1,py=2},{py=7},{y=self.y+1,py=0}})
|
||||||
self.todo=f4({{orienty=1,py=2},{py=7},{y=self.y+1}})
|
elseif not self.rope and kbd:btnr(4) then
|
||||||
else wrongbleep:bleep() end
|
|
||||||
elseif self.rope==nil and kbd:btnr(4) then
|
|
||||||
local dx,dy=self.orientx,self.orienty
|
local dx,dy=self.orientx,self.orienty
|
||||||
if (dy!=0) dx=0
|
if (dy!=0) dx=0
|
||||||
|
|
||||||
@ -695,37 +664,31 @@ function player:update()
|
|||||||
end
|
end
|
||||||
}}
|
}}
|
||||||
elseif kbd:btnp(5) then
|
elseif kbd:btnp(5) then
|
||||||
if self.rope!=nil then
|
if (self.rope and not self.rope:tug()) wrongbleep:bleep(9)
|
||||||
if (not self.rope:tug()) wrongbleep:bleep(9)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.rope then
|
|
||||||
self.rope:update()
|
|
||||||
end
|
|
||||||
_apply(self,self.todo)
|
_apply(self,self.todo)
|
||||||
|
|
||||||
if self.rope then
|
if self.rope then
|
||||||
self.rope:update()
|
self.rope:update()
|
||||||
if self.rope:done_reeling() then
|
if self.rope:done_reeling() then
|
||||||
self.x=self.rope.latch.rec.mx+self.rope.latch.dx
|
local latch=self.rope.latch
|
||||||
self.y=self.rope.latch.rec.my+self.rope.latch.dy
|
self.x=latch.rec.mx+latch.dx
|
||||||
|
self.y=latch.rec.my+latch.dy
|
||||||
end
|
end
|
||||||
|
|
||||||
local rx=self.x+self.px/8+0.5
|
self.rope:drag_dst(
|
||||||
local ry=self.y+self.py/8+0.5
|
self.x+self.px/8+0.5,
|
||||||
-- do the hokey pokey to work out kinks in the rope
|
self.y+self.py/8+0.5
|
||||||
self.rope:drag_dst(rx,ry)
|
)
|
||||||
|
|
||||||
local tdx,tdy=self.rope:tug_orientxy()
|
local tdx,tdy=self.rope:tug_orientxy()
|
||||||
if (tdx!=0) self.orientx=tdx
|
if (tdx) self.orientx=tdx
|
||||||
if (tdy!=0) self.orienty=tdy
|
if (tdy) self.orienty=tdy
|
||||||
|
|
||||||
if self.rope:done() then
|
if (self.rope:done()) self.rope=nil
|
||||||
self.rope=nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -754,23 +717,27 @@ function player:draw()
|
|||||||
local px=self.x*8+self.px+wrongbleep:vibrate()
|
local px=self.x*8+self.px+wrongbleep:vibrate()
|
||||||
local py=self.y*8+self.py+wrongbleep:vibrate()
|
local py=self.y*8+self.py+wrongbleep:vibrate()
|
||||||
|
|
||||||
|
|
||||||
local head=1-self.orienty
|
local head=1-self.orienty
|
||||||
|
|
||||||
local vanish_level=max((self.vanish_frame-4)/16,0)
|
local vanish_level=max((self.vanish_frame-4)/16,0)
|
||||||
local invis_level=max(self.fall_frame/10,4*(vanish_level-0.75))
|
local invis_level=max(self.fall_frame/10,4*(vanish_level-0.75))
|
||||||
if (invis_level>=1.0) return
|
if (invis_level>=1.0) return
|
||||||
|
|
||||||
--px+=sin(vanish_level*16)*max(vanish_level-0.1,0)*1
|
--[[
|
||||||
local HEAD=14--3
|
local HEAD=14--3
|
||||||
local BODY=12--12
|
local BODY=12--12
|
||||||
local TAIL=14--14
|
local TAIL=14--14
|
||||||
local IRIS=7--9
|
local IRIS=7--9
|
||||||
local PUPIL=0--0
|
local PUPIL=0--0
|
||||||
|
]]
|
||||||
|
|
||||||
local setpal=function()
|
-- in order: head,body,iris,pupil,body again,tail
|
||||||
-- base colors
|
local palette=split"-1,14,14,12,12,-1,-1,-1,7,0,-1,12,14,14,14"
|
||||||
pal{
|
local function setpal()
|
||||||
|
--[[
|
||||||
|
-- head
|
||||||
|
nil,14,14,
|
||||||
|
--body
|
||||||
[2]=HEAD,
|
[2]=HEAD,
|
||||||
[3]=HEAD,
|
[3]=HEAD,
|
||||||
[4]=BODY,
|
[4]=BODY,
|
||||||
@ -781,7 +748,8 @@ function player:draw()
|
|||||||
[13]=TAIL,
|
[13]=TAIL,
|
||||||
[14]=TAIL,
|
[14]=TAIL,
|
||||||
[15]=TAIL,
|
[15]=TAIL,
|
||||||
}
|
]]
|
||||||
|
pal(palette)
|
||||||
|
|
||||||
-- vanish colors
|
-- vanish colors
|
||||||
local vanish=split"13,15,14,5,4,12,2,3,9,10"
|
local vanish=split"13,15,14,5,4,12,2,3,9,10"
|
||||||
@ -789,11 +757,7 @@ function player:draw()
|
|||||||
if (vanish_level>i/#vanish) pal(ilc,1)
|
if (vanish_level>i/#vanish) pal(ilc,1)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.fall_frame>3 then
|
if (self.fall_frame>3) local zc=@0x5f00&0xf0 for i=0x5f00,0x5f0c,4 do poke4(i,0x0101.0101) end poke(0x5f00,zc|0x01)
|
||||||
local zc=@0x5f00&0xf0
|
|
||||||
for i=0x5f00,0x5f0c,4 do poke4(i,0x0101.0101) end
|
|
||||||
poke(0x5f00,zc|0x01)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local rx,ry=self.x*8+self.px+1,self.y*8+self.py+2
|
local rx,ry=self.x*8+self.px+1,self.y*8+self.py+2
|
||||||
@ -1434,12 +1398,12 @@ function rope:tug_orientxy()
|
|||||||
local a1=self.dst
|
local a1=self.dst
|
||||||
local a0=self.dst.prev
|
local a0=self.dst.prev
|
||||||
local dx=a0.ax-a1.ax
|
local dx=a0.ax-a1.ax
|
||||||
local tdx=0
|
local tdx=nil
|
||||||
if (dx>3/8) tdx=1
|
if (dx>3/8) tdx=1
|
||||||
if (dx<-3/8) tdx=-1
|
if (dx<-3/8) tdx=-1
|
||||||
|
|
||||||
local dy=a0.ay-a1.ay
|
local dy=a0.ay-a1.ay
|
||||||
local tdy=0
|
local tdy=nil
|
||||||
if abs(dy)>abs(dx)/2 then
|
if abs(dy)>abs(dx)/2 then
|
||||||
if (dy>3/8) tdy=1
|
if (dy>3/8) tdy=1
|
||||||
if (dy<-3/8) tdy=-1
|
if (dy<-3/8) tdy=-1
|
||||||
|
Loading…
Reference in New Issue
Block a user