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