forked from pyrex/chameleonic
Snappier controls
This commit is contained in:
parent
7c3cd44b9a
commit
87219678ef
@ -603,6 +603,7 @@ function player:reinit(x,y)
|
|||||||
self.x,self.y=x,y
|
self.x,self.y=x,y
|
||||||
self.px,self.py=0,0
|
self.px,self.py=0,0
|
||||||
self.todo={}
|
self.todo={}
|
||||||
|
self.cooldown=4
|
||||||
|
|
||||||
self.fall_frame=0
|
self.fall_frame=0
|
||||||
|
|
||||||
@ -636,6 +637,10 @@ function player:update()
|
|||||||
self.orienty=1
|
self.orienty=1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function btncd(x)
|
||||||
|
return (kbd:btn(x) and self.cooldown==0) or kbd:btnp(x)
|
||||||
|
end
|
||||||
|
|
||||||
if kbd:btn(4) then
|
if kbd:btn(4) then
|
||||||
if kbd:btnp(4) and self.rope then
|
if kbd:btnp(4) and self.rope then
|
||||||
self.rope:destroy()
|
self.rope:destroy()
|
||||||
@ -643,23 +648,30 @@ function player:update()
|
|||||||
end
|
end
|
||||||
-- wait for user to release it
|
-- wait for user to release it
|
||||||
else
|
else
|
||||||
|
local x,y=self.x,self.y
|
||||||
local function try_move(dx,dy,f)
|
local function try_move(dx,dy,f)
|
||||||
if (level:can_move(true,self.x,self.y,dx,dy,0,2)) self.todo=f return
|
if level:can_move(true,x,y,dx,dy,0,2) then
|
||||||
|
self.todo=f
|
||||||
|
self.cooldown=3
|
||||||
|
local t=f[#f]
|
||||||
|
t.x=x+dx
|
||||||
|
t.y=y+dy
|
||||||
|
return
|
||||||
|
end
|
||||||
wrongbleep:bleep()
|
wrongbleep:bleep()
|
||||||
end
|
end
|
||||||
if kbd:btn(0) then
|
if btncd(0) then
|
||||||
try_move(-1,0,{{orientx=-1,orienty=0,px=-2},{px=-7},{x=self.x-1,px=0}})
|
try_move(-1,0,{{orientx=-1,orienty=0,px=-2},{px=1}})
|
||||||
elseif kbd:btn(1) then
|
elseif btncd(1) then
|
||||||
try_move(1,0,{{orientx=1,orienty=0,px=2},{px=7},{x=self.x+1,px=0}})
|
try_move(1,0,{{orientx=1,orienty=0,px=2},{px=-1}})
|
||||||
elseif kbd:btn(2) then
|
elseif btncd(2) then
|
||||||
try_move(0,-1,{{orienty=-1,py=-2},{py=-7},{y=self.y-1,py=0}})
|
try_move(0,-1,{{orienty=-1,py=-2},{py=1}})
|
||||||
elseif kbd:btn(3) then
|
elseif btncd(3) then
|
||||||
try_move(0,1,{{orienty=1,py=2},{py=7},{y=self.y+1,py=0}})
|
try_move(0,1,{{orienty=1,py=2},{py=-1}})
|
||||||
elseif not self.rope and kbd:btnr(4) then
|
elseif not self.rope 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
|
||||||
|
|
||||||
local x,y=self.x,self.y
|
|
||||||
while not level:mcoll(x,y) do x+=dx y+=dy end
|
while not level:mcoll(x,y) do x+=dx y+=dy end
|
||||||
|
|
||||||
self.rope=rope:new(
|
self.rope=rope:new(
|
||||||
@ -679,7 +691,9 @@ function player:update()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (#self.todo==0) self.px=0 self.py=0
|
||||||
_apply(self,self.todo)
|
_apply(self,self.todo)
|
||||||
|
if (self.cooldown>0) self.cooldown-=1
|
||||||
|
|
||||||
if self.rope then
|
if self.rope then
|
||||||
self.rope:update()
|
self.rope:update()
|
||||||
|
Loading…
Reference in New Issue
Block a user