fix cringe mouse handling

This commit is contained in:
Kimapr 2023-03-29 15:19:08 +05:00
parent 00b0f9361d
commit dbe5287272

View file

@ -661,6 +661,30 @@ local speeds={1,0.05,10}
local plchint=1
local toplchi=plchint
function love.mousemoved()
if grabbed then
local x,y,ox,oy,px,py=unpack(grabbed)
local mx,my=love.mouse.getPosition()
mx,my=trans:inverseTransformPoint(mx,my)
mx,my=mx+1-0.5+ox,my+1-0.5+oy
mx,my=math.floor(mx+.5),math.floor(my+.5)
if math.abs(x-mx)>math.abs(y-my) then
mx,my=math.min(bw,math.max(1,x+sign(mx-x))),y
elseif math.abs(y-my)>0 then
my,mx=math.min(bh,math.max(1,y+sign(my-y))),x
end
if px then
smtar(px,py,px,py)
end
grabbed[5],grabbed[6]=mx,my
if not board[x][y] then
elseif board[mx][my] then
smtar(mx,my,x,y)
smtar(x,y,mx,my)
end
end
end
function love.update(dt)
dt=math.min(dt,0.2)*(speeds[slow])
accumdt=math.min(1,accumdt+dt)
@ -671,7 +695,7 @@ function love.update(dt)
accumdt=accumdt-dt
if fcc>10 then return end
if running and playdbg then
for _=1,10 do
for _=1,100 do
local ix,iy=math.random(1,bw),math.random(1,bh)
local px,py=0,0
while px<1 or py<1 or px>bw or py>bh do
@ -684,7 +708,6 @@ function love.update(dt)
if kills and board[ix][iy] and board[px][py] then
megascan(ix,iy,board[ix][iy],megascan(px,py,board[px][py],kills))
killall(kills)
break
else
board[ix][iy],board[px][py]=
board[px][py],board[ix][iy]
@ -700,27 +723,6 @@ function love.update(dt)
dying=true
dropall(0,true)
end
if grabbed then
local x,y,ox,oy,px,py=unpack(grabbed)
local mx,my=love.mouse.getPosition()
mx,my=trans:inverseTransformPoint(mx,my)
mx,my=mx+1-0.5+ox,my+1-0.5+oy
mx,my=math.floor(mx+.5),math.floor(my+.5)
if math.abs(x-mx)>math.abs(y-my) then
mx,my=math.min(bw,math.max(1,x+sign(mx-x))),y
elseif math.abs(y-my)>0 then
my,mx=math.min(bh,math.max(1,y+sign(my-y))),x
end
if px then
smtar(px,py,px,py)
end
grabbed[5],grabbed[6]=mx,my
if not board[x][y] then
elseif board[mx][my] then
smtar(mx,my,x,y)
smtar(x,y,mx,my)
end
end
animc=0
entc=0
boomc=0