更好地使用scr变量,debug用print独立,鼠标触发圆形波纹
This commit is contained in:
@@ -201,8 +201,8 @@ back.matrix={
|
|||||||
draw=function()
|
draw=function()
|
||||||
gc.scale(scr.k)
|
gc.scale(scr.k)
|
||||||
gc.clear(.15,.15,.15)
|
gc.clear(.15,.15,.15)
|
||||||
local Y=ceil(scr.h*scr.dpi/80)
|
local Y=ceil(scr.H/80)
|
||||||
for x=1,ceil(scr.w*scr.dpi/80)do
|
for x=1,ceil(scr.W/80)do
|
||||||
for y=1,Y do
|
for y=1,Y do
|
||||||
gc.setColor(1,1,1,sin(x+matrixT[x][y]*t)*.1+.1)
|
gc.setColor(1,1,1,sin(x+matrixT[x][y]*t)*.1+.1)
|
||||||
gc.rectangle("fill",80*x,80*y,-80,-80)
|
gc.rectangle("fill",80*x,80*y,-80,-80)
|
||||||
|
|||||||
@@ -616,10 +616,9 @@ function keyDown.pause(key)
|
|||||||
SCN.goto("setting_sound")
|
SCN.goto("setting_sound")
|
||||||
elseif key=="r"then
|
elseif key=="r"then
|
||||||
TASK.clear("play")
|
TASK.clear("play")
|
||||||
mergeStat(stat,players[1].stat)
|
|
||||||
resetGameData()
|
resetGameData()
|
||||||
SCN.swapTo("play","none")
|
SCN.swapTo("play","none")
|
||||||
elseif key=="p"and game.result then
|
elseif key=="p"and(game.result or game.replaying)then
|
||||||
TASK.removeTask_code(TICK.autoPause)
|
TASK.removeTask_code(TICK.autoPause)
|
||||||
resetPartGameData(true)
|
resetPartGameData(true)
|
||||||
SCN.swapTo("play","none")
|
SCN.swapTo("play","none")
|
||||||
@@ -779,11 +778,11 @@ function keyDown.history(key)
|
|||||||
end
|
end
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
local lastX,lastY=0,0--Last clickDown pos
|
local lastX,lastY=0,0--Last clickDown pos
|
||||||
function love.mousepressed(x,y,k,t,num)
|
function love.mousepressed(x,y,k,touch,num)
|
||||||
if t then return end
|
if touch then return end
|
||||||
mouseShow=true
|
mouseShow=true
|
||||||
mx,my=xOy:inverseTransformPoint(x,y)
|
mx,my=xOy:inverseTransformPoint(x,y)
|
||||||
if devMode==1 then print(mx,my)end
|
if devMode==1 then DBP(mx,my)end
|
||||||
if SCN.swapping then return end
|
if SCN.swapping then return end
|
||||||
if mouseDown[SCN.cur]then
|
if mouseDown[SCN.cur]then
|
||||||
mouseDown[SCN.cur](mx,my,k)
|
mouseDown[SCN.cur](mx,my,k)
|
||||||
@@ -810,15 +809,17 @@ function love.mousemoved(x,y,dx,dy,t)
|
|||||||
WIDGET.moveCursor(mx,my)
|
WIDGET.moveCursor(mx,my)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function love.mousereleased(x,y,k,t,num)
|
function love.mousereleased(x,y,k,touch,num)
|
||||||
if t then return end
|
if touch or SCN.swapping then return end
|
||||||
mx,my=xOy:inverseTransformPoint(x,y)
|
mx,my=xOy:inverseTransformPoint(x,y)
|
||||||
if t or SCN.swapping then return end
|
|
||||||
if mouseUp[SCN.cur]then
|
if mouseUp[SCN.cur]then
|
||||||
mouseUp[SCN.cur](mx,my,k)
|
mouseUp[SCN.cur](mx,my,k)
|
||||||
end
|
end
|
||||||
if lastX and(mx-lastX)^2+(my-lastY)^2<26 and mouseClick[SCN.cur]then
|
if lastX and(mx-lastX)^2+(my-lastY)^2<26 then
|
||||||
mouseClick[SCN.cur](mx,my,k)
|
if mouseClick[SCN.cur]then
|
||||||
|
mouseClick[SCN.cur](mx,my,k)
|
||||||
|
end
|
||||||
|
sysFX.newRipple(.3,mx,my,30)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function love.wheelmoved(x,y)
|
function love.wheelmoved(x,y)
|
||||||
@@ -888,7 +889,7 @@ function love.keypressed(i)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
if i=="f5"then
|
if i=="f5"then
|
||||||
print("DEBUG:")
|
DBP("DEBUG:")
|
||||||
elseif i=="f8"then devMode=nil TEXT.show("DEBUG OFF",640,360,80,"fly",.8)
|
elseif i=="f8"then devMode=nil TEXT.show("DEBUG OFF",640,360,80,"fly",.8)
|
||||||
elseif i=="f9"then devMode=1 TEXT.show("DEBUG 1",640,360,80,"fly",.8)
|
elseif i=="f9"then devMode=1 TEXT.show("DEBUG 1",640,360,80,"fly",.8)
|
||||||
elseif i=="f10"then devMode=2 TEXT.show("DEBUG 2",640,360,80,"fly",.8)
|
elseif i=="f10"then devMode=2 TEXT.show("DEBUG 2",640,360,80,"fly",.8)
|
||||||
@@ -910,7 +911,7 @@ function love.keypressed(i)
|
|||||||
assert(false,"Techmino:挂了")
|
assert(false,"Techmino:挂了")
|
||||||
elseif i=="e"then
|
elseif i=="e"then
|
||||||
for k,v in next,_G do
|
for k,v in next,_G do
|
||||||
print(k,v)
|
DBP(k,v)
|
||||||
end
|
end
|
||||||
elseif WIDGET.sel then
|
elseif WIDGET.sel then
|
||||||
local W=WIDGET.sel
|
local W=WIDGET.sel
|
||||||
@@ -995,10 +996,11 @@ function love.lowmemory()
|
|||||||
collectgarbage()
|
collectgarbage()
|
||||||
end
|
end
|
||||||
function love.resize(w,h)
|
function love.resize(w,h)
|
||||||
scr.w,scr.h=w,h
|
scr.w,scr.h,scr.dpi=w,h,gc.getDPIScale()
|
||||||
|
scr.W,scr.H=scr.w*scr.dpi,scr.h*scr.dpi
|
||||||
scr.r=h/w
|
scr.r=h/w
|
||||||
scr.rad=(w^2+h^2)^.5
|
scr.rad=(w^2+h^2)^.5
|
||||||
scr.dpi=gc.getDPIScale()
|
|
||||||
if scr.r>=.5625 then
|
if scr.r>=.5625 then
|
||||||
scr.k=w/1280
|
scr.k=w/1280
|
||||||
scr.x,scr.y=0,(h-w*9/16)*.5
|
scr.x,scr.y=0,(h-w*9/16)*.5
|
||||||
@@ -1014,7 +1016,6 @@ function love.resize(w,h)
|
|||||||
end
|
end
|
||||||
function love.focus(f)
|
function love.focus(f)
|
||||||
if f then
|
if f then
|
||||||
TASK.new(TICK.autoResize,{0})
|
|
||||||
love.timer.step()
|
love.timer.step()
|
||||||
elseif SCN.cur=="play"and setting.autoPause then
|
elseif SCN.cur=="play"and setting.autoPause then
|
||||||
pauseGame()
|
pauseGame()
|
||||||
@@ -1145,9 +1146,13 @@ function love.run()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Fresh power info.
|
--Fresh power info.
|
||||||
if Timer()-lastFreshPow>3 and setting.powerInfo and SCN.cur~="load"then
|
if Timer()-lastFreshPow>2 and setting.powerInfo and SCN.cur~="load"then
|
||||||
updatePowerInfo()
|
updatePowerInfo()
|
||||||
lastFreshPow=Timer()
|
lastFreshPow=Timer()
|
||||||
|
_=gc.getWidth()
|
||||||
|
if _~=scr.w then
|
||||||
|
love.resize(_,gc.getHeight())
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--Keep 60fps
|
--Keep 60fps
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ function Pnt.play()
|
|||||||
gc.origin()
|
gc.origin()
|
||||||
if restartCount>0 then
|
if restartCount>0 then
|
||||||
gc.setColor(0,0,0,restartCount*.05)
|
gc.setColor(0,0,0,restartCount*.05)
|
||||||
gc.rectangle("fill",0,0,scr.w*scr.dpi,scr.h*scr.dpi)
|
gc.rectangle("fill",0,0,scr.W,scr.H)
|
||||||
end
|
end
|
||||||
if game.warnLVL>0 then
|
if game.warnLVL>0 then
|
||||||
gc.setColor(0,0,0,0)
|
gc.setColor(0,0,0,0)
|
||||||
@@ -545,7 +545,7 @@ function Pnt.pause()
|
|||||||
gc.setColor(.15,.15,.15,_)
|
gc.setColor(.15,.15,.15,_)
|
||||||
gc.push("transform")
|
gc.push("transform")
|
||||||
gc.origin()
|
gc.origin()
|
||||||
gc.rectangle("fill",0,0,scr.w*scr.dpi,scr.h*scr.dpi)
|
gc.rectangle("fill",0,0,scr.W,scr.H)
|
||||||
gc.pop()
|
gc.pop()
|
||||||
|
|
||||||
--Pause Info
|
--Pause Info
|
||||||
|
|||||||
@@ -364,26 +364,24 @@ local swap={
|
|||||||
fade={30,15,function(t)
|
fade={30,15,function(t)
|
||||||
local t=t>15 and 2-t/15 or t/15
|
local t=t>15 and 2-t/15 or t/15
|
||||||
gc.setColor(0,0,0,t)
|
gc.setColor(0,0,0,t)
|
||||||
gc.rectangle("fill",0,0,scr.w*scr.dpi,scr.h*scr.dpi)
|
gc.rectangle("fill",0,0,scr.W,scr.H)
|
||||||
end},
|
end},
|
||||||
fade_togame={120,20,function(t)
|
fade_togame={120,20,function(t)
|
||||||
local t=t>20 and(120-t)/100 or t/20
|
local t=t>20 and(120-t)/100 or t/20
|
||||||
gc.setColor(0,0,0,t)
|
gc.setColor(0,0,0,t)
|
||||||
gc.rectangle("fill",0,0,scr.w*scr.dpi,scr.h*scr.dpi)
|
gc.rectangle("fill",0,0,scr.W,scr.H)
|
||||||
end},
|
end},
|
||||||
slowFade={180,90,function(t)
|
slowFade={180,90,function(t)
|
||||||
local t=t>90 and 2-t/90 or t/90
|
local t=t>90 and 2-t/90 or t/90
|
||||||
gc.setColor(0,0,0,t)
|
gc.setColor(0,0,0,t)
|
||||||
gc.rectangle("fill",0,0,scr.w*scr.dpi,scr.h*scr.dpi)
|
gc.rectangle("fill",0,0,scr.W,scr.H)
|
||||||
end},
|
end},
|
||||||
swipe={30,15,function(t)
|
swipe={30,15,function(t)
|
||||||
gc.setColor(0,0,0,1-abs(t-15)/15)
|
t=t/30
|
||||||
if t>15 then
|
gc.setColor(.1,.1,.1,1-abs(t-.5))
|
||||||
t=t/15-1
|
t=t*t*(3-2*t)*2-1
|
||||||
gc.rectangle("fill",scr.w*scr.dpi,0,-scr.w*scr.dpi*(1-t),scr.h*scr.dpi)
|
local w=scr.W
|
||||||
else
|
gc.rectangle("fill",t*w,0,w,scr.H)
|
||||||
gc.rectangle("fill",0,0,scr.w*scr.dpi*t/15,scr.h*scr.dpi)
|
|
||||||
end
|
|
||||||
end},
|
end},
|
||||||
}--Scene swapping animations
|
}--Scene swapping animations
|
||||||
function SCN.swapTo(tar,style)--Parallel scene swapping, cannot back
|
function SCN.swapTo(tar,style)--Parallel scene swapping, cannot back
|
||||||
|
|||||||
@@ -1,31 +1,47 @@
|
|||||||
local gc=love.graphics
|
local gc=love.graphics
|
||||||
local setColor=gc.setColor
|
local setColor=gc.setColor
|
||||||
local setWidth=gc.setLineWidth
|
local setWidth=gc.setLineWidth
|
||||||
local rect=gc.rectangle
|
local ins,rem=table.insert,table.remove
|
||||||
|
|
||||||
local fx={}
|
local fx={}
|
||||||
|
|
||||||
|
local FXupdate={}
|
||||||
|
function FXupdate.ripple(S,dt)
|
||||||
|
S.t=S.t+dt*S.rate
|
||||||
|
return S.t>=1
|
||||||
|
end
|
||||||
|
function FXupdate.rectRipple(S,dt)
|
||||||
|
S.t=S.t+dt*S.rate
|
||||||
|
return S.t>=1
|
||||||
|
end
|
||||||
|
function FXupdate.shade(S,dt)
|
||||||
|
S.t=S.t+dt*S.rate
|
||||||
|
return S.t>=1
|
||||||
|
end
|
||||||
|
|
||||||
local FXdraw={}
|
local FXdraw={}
|
||||||
function FXdraw.ripple(S)
|
function FXdraw.ripple(S)
|
||||||
|
setWidth(2)
|
||||||
|
local t=S.t
|
||||||
|
setColor(1,1,1,1-t)
|
||||||
|
gc.circle("line",S.x,S.y,t*(2-t)*S.r)
|
||||||
|
end
|
||||||
|
function FXdraw.rectRipple(S)
|
||||||
setWidth(6)
|
setWidth(6)
|
||||||
setColor(1,1,1,1-S.t)
|
setColor(1,1,1,1-S.t)
|
||||||
local r=(10*S.t)^1.2
|
local r=(10*S.t)^1.2
|
||||||
rect("line",S[1]-r,S[2]-r,S[3]+2*r,S[4]+2*r)
|
gc.rectangle("line",S.x-r,S.y-r,S.w+2*r,S.h+2*r)
|
||||||
end
|
end
|
||||||
function FXdraw.shade(S)
|
function FXdraw.shade(S)
|
||||||
setColor(S[1],S[2],S[3],1-S.t)
|
setColor(S.r,S.g,S.b,1-S.t)
|
||||||
rect("fill",S[4],S[5],S[6],S[7],2)
|
gc.rectangle("fill",S.x,S.y,S.w,S.h,2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local sysFX={}
|
local sysFX={}
|
||||||
function sysFX.update(dt)
|
function sysFX.update(dt)
|
||||||
for i=#fx,1,-1 do
|
for i=#fx,1,-1 do
|
||||||
local S=fx[i]
|
if fx[i]:update(dt) then
|
||||||
S.t=S.t+dt*S.rate
|
rem(fx,i)
|
||||||
if S.t>=1 then
|
|
||||||
for i=i,#fx do
|
|
||||||
fx[i]=fx[i+1]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -34,9 +50,33 @@ function sysFX.draw()
|
|||||||
fx[i]:draw()
|
fx[i]:draw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--0=ripple,x,y,w,h
|
|
||||||
--1=shade,r,g,b,x,y,w,h
|
function sysFX.newRipple(duration,x,y,r)
|
||||||
function sysFX.new(type,duration,...)
|
fx[#fx+1]={
|
||||||
fx[#fx+1]={draw=FXdraw[type],t=0,rate=1/duration,...}
|
update=FXupdate.ripple,
|
||||||
|
draw=FXdraw.ripple,
|
||||||
|
t=0,
|
||||||
|
rate=1/duration,
|
||||||
|
x=x,y=y,r=r,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
function sysFX.newRectRipple(duration,x,y,w,h)
|
||||||
|
fx[#fx+1]={
|
||||||
|
update=FXupdate.rectRipple,
|
||||||
|
draw=FXdraw.rectRipple,
|
||||||
|
t=0,
|
||||||
|
rate=1/duration,
|
||||||
|
x=x,y=y,w=w,h=h,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
function sysFX.newShade(duration,r,g,b,x,y,w,h)
|
||||||
|
fx[#fx+1]={
|
||||||
|
update=FXupdate.shade,
|
||||||
|
draw=FXdraw.shade,
|
||||||
|
t=0,
|
||||||
|
rate=1/duration,
|
||||||
|
r=r,g=g,b=b,
|
||||||
|
x=x,y=y,w=w,h=h,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
return sysFX
|
return sysFX
|
||||||
@@ -121,7 +121,7 @@ function VOC.play(s,chn)
|
|||||||
if chn then
|
if chn then
|
||||||
local L=voiceQueue[chn]
|
local L=voiceQueue[chn]
|
||||||
local _=VOC.list[s]
|
local _=VOC.list[s]
|
||||||
if not _ then print("no VOC called:"..s)return end
|
if not _ then DBP("no VOC called:"..s)return end
|
||||||
L[#L+1]=_[rnd(#_)]
|
L[#L+1]=_[rnd(#_)]
|
||||||
L.s=1
|
L.s=1
|
||||||
--Add to queue[chn]
|
--Add to queue[chn]
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ function button:getCenter()
|
|||||||
end
|
end
|
||||||
function button:FX()
|
function button:FX()
|
||||||
local ATV=self.ATV
|
local ATV=self.ATV
|
||||||
sysFX.new(
|
sysFX.newRectRipple(
|
||||||
"ripple",
|
|
||||||
.16,
|
.16,
|
||||||
self.x-ATV,
|
self.x-ATV,
|
||||||
self.y-ATV,
|
self.y-ATV,
|
||||||
self.w+2*ATV,
|
self.w+2*ATV,
|
||||||
self.h+2*ATV
|
self.h+2*ATV
|
||||||
|
,5
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
function button:update()
|
function button:update()
|
||||||
@@ -68,7 +68,7 @@ function button:draw()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function button:getInfo()
|
function button:getInfo()
|
||||||
print(format("x=%d,y=%d,w=%d,h=%d,font=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h,self.font))
|
DBP(format("x=%d,y=%d,w=%d,h=%d,font=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h,self.font))
|
||||||
end
|
end
|
||||||
|
|
||||||
local key={
|
local key={
|
||||||
@@ -118,7 +118,7 @@ function key:draw()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function key:getInfo()
|
function key:getInfo()
|
||||||
print(format("x=%d,y=%d,w=%d,h=%d,font=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h,self.font))
|
DBP(format("x=%d,y=%d,w=%d,h=%d,font=%d",self.x+self.w*.5,self.y+self.h*.5,self.w,self.h,self.font))
|
||||||
end
|
end
|
||||||
|
|
||||||
local switch={
|
local switch={
|
||||||
@@ -171,11 +171,11 @@ function switch:draw()
|
|||||||
if t then
|
if t then
|
||||||
gc.setColor(1,1,1)
|
gc.setColor(1,1,1)
|
||||||
setFont(self.font)
|
setFont(self.font)
|
||||||
gc.printf(t,x-412-ATV,y+20-self.font*.7-ATV*.5,400,"right")
|
gc.printf(t,x-412-ATV,y+20-self.font*.7,400,"right")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function switch:getInfo()
|
function switch:getInfo()
|
||||||
print(format("x=%d,y=%d,font=%d",self.x,self.y,self.font))
|
DBP(format("x=%d,y=%d,font=%d",self.x,self.y,self.font))
|
||||||
end
|
end
|
||||||
|
|
||||||
local slider={
|
local slider={
|
||||||
@@ -236,11 +236,11 @@ function slider:draw()
|
|||||||
if t then
|
if t then
|
||||||
gc.setColor(1,1,1)
|
gc.setColor(1,1,1)
|
||||||
setFont(self.font)
|
setFont(self.font)
|
||||||
gc.printf(t,x-312-ATV,y-self.font*.7-ATV*.5,300,"right")
|
gc.printf(t,x-312-ATV,y-self.font*.7,300,"right")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function slider:getInfo()
|
function slider:getInfo()
|
||||||
print(format("x=%d,y=%d,w=%d",self.x,self.y,self.w))
|
DBP(format("x=%d,y=%d,w=%d",self.x,self.y,self.w))
|
||||||
end
|
end
|
||||||
|
|
||||||
local WIDGET={}
|
local WIDGET={}
|
||||||
|
|||||||
15
main.lua
15
main.lua
@@ -8,13 +8,16 @@ Techmino is my first "huge project"
|
|||||||
optimization is welcomed if you also love tetromino game
|
optimization is welcomed if you also love tetromino game
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
|
--?
|
||||||
|
function NULL()end
|
||||||
|
DBP=print--use this if need debugging print
|
||||||
|
|
||||||
--Global Setting & Vars
|
--Global Setting & Vars
|
||||||
math.randomseed(os.time()*626)
|
math.randomseed(os.time()*626)
|
||||||
love.keyboard.setKeyRepeat(true)
|
love.keyboard.setKeyRepeat(true)
|
||||||
love.keyboard.setTextInput(false)
|
love.keyboard.setTextInput(false)
|
||||||
love.mouse.setVisible(false)
|
love.mouse.setVisible(false)
|
||||||
|
|
||||||
function NULL()end
|
|
||||||
system=love.system.getOS()
|
system=love.system.getOS()
|
||||||
game={}
|
game={}
|
||||||
mapCam={
|
mapCam={
|
||||||
@@ -122,16 +125,8 @@ if S.version~=gameVersion then
|
|||||||
TEXT.show(text.newBigVersion,640,200,30,"fly",.3)
|
TEXT.show(text.newBigVersion,640,200,30,"fly",.3)
|
||||||
newVersionLaunch=true
|
newVersionLaunch=true
|
||||||
|
|
||||||
|
fs.remove("sprintPenta.dat")
|
||||||
fs.remove("master_adavnce.dat")
|
fs.remove("master_adavnce.dat")
|
||||||
fs.remove("master_beginner.dat")
|
fs.remove("master_beginner.dat")
|
||||||
for name,M in next,Modes do
|
|
||||||
if M.score then
|
|
||||||
if modeRanks[name]==6 then
|
|
||||||
modeRanks[name]=0
|
|
||||||
end
|
|
||||||
else
|
|
||||||
modeRanks[name]=6
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
R,S=nil
|
R,S=nil
|
||||||
Reference in New Issue
Block a user