整理代码

This commit is contained in:
MrZ626
2020-12-15 23:55:32 +08:00
parent cf3ca2e9e0
commit e732aae87b
30 changed files with 149 additions and 168 deletions

View File

@@ -1,12 +1,11 @@
local gc=love.graphics
local Timer=love.timer.getTime
local ins,rem=table.insert,table.remove
local max,min=math.max,math.min
local texts={}
local remain--People in chat room
local scroll--Bottom message no.
local scrollPos--Scroll up length
local newMessage=false--If there is a new message
local heartBeatTimer
local escapeTimer=0
@@ -23,7 +22,7 @@ local function sendMessage()
end
local function clearHistory()
while #texts>1 do rem(texts)end
scroll=1
scrollPos=1
SFX.play("fall")
collectgarbage()
end
@@ -39,7 +38,7 @@ function scene.sceneInit()
elseif #texts>1 and texts[#texts][1]~=COLOR.dG then
ins(texts,{COLOR.dG,text.chatHistory})
end
scroll=#texts
scrollPos=#texts
TASK.new(focusAtTextbox)--Widgets are not initialized, so active after 1 frame
BG.set("none")
wsConnect(
@@ -58,19 +57,19 @@ function scene.wheelMoved(_,y)
end
function scene.keyDown(k)
if k=="up"then
scroll=max(scroll-1,min(#texts,12))
scrollPos=max(scrollPos-1,min(#texts,12))
elseif k=="down"then
scroll=min(scroll+1,#texts)
if scroll==#texts then
scrollPos=min(scrollPos+1,#texts)
if scrollPos==#texts then
newMessage=false
end
elseif k=="return"then
sendMessage()
elseif k=="escape"then
if Timer()-escapeTimer<.6 then
if TIME()-escapeTimer<.6 then
SCN.back()
else
escapeTimer=Timer()
escapeTimer=TIME()
LOG.print(text.chatQuit,COLOR.orange)
end
else
@@ -102,8 +101,8 @@ function scene.socketRead(mes)
COLOR.sky,mes:sub(sep+1),
})
end
if scroll==#texts-1 then
scroll=scroll+1
if scrollPos==#texts-1 then
scrollPos=scrollPos+1
else
SFX.play("spin_0",.8)
newMessage=true
@@ -124,8 +123,8 @@ function scene.draw()
gc.print(remain or"?",1205,10)
setFont(30)
for i=max(scroll-11,1),scroll do
gc.printf(texts[i],40,416-36*(scroll-i),1240)
for i=max(scrollPos-11,1),scrollPos do
gc.printf(texts[i],40,416-36*(scrollPos-i),1240)
end
--Slider
@@ -133,13 +132,13 @@ function scene.draw()
gc.setLineWidth(2)
gc.rectangle("line",10,30,20,420)
local len=420*12/#texts
gc.rectangle("fill",13,33+(414-len)*(scroll-12)/(#texts-12),14,len)
gc.rectangle("fill",13,33+(414-len)*(scrollPos-12)/(#texts-12),14,len)
end
--Draw
if newMessage and scroll~=#texts then
if newMessage and scrollPos~=#texts then
setFont(40)
gc.setColor(1,Timer()%.4<.2 and 1 or 0,0)
gc.setColor(1,TIME()%.4<.2 and 1 or 0,0)
gc.print("v",8,480)
end
end

View File

@@ -1,6 +1,5 @@
local gc,sys=love.graphics,love.system
local kb=love.keyboard
local Timer=love.timer.getTime
local int=math.floor
local find,sub=string.find,string.sub
@@ -132,14 +131,14 @@ function scene.draw()
--Field
setFont(40)
if initField and #FIELD>1 then
gc.setColor(1,1,int(Timer()*6.26)%2)
gc.setColor(1,1,int(TIME()*6.26)%2)
gc.print("+",275,300)
gc.print(#FIELD-1,300,300)
end
--Sequence
if #BAG>0 then
gc.setColor(1,1,int(Timer()*6.26)%2)
gc.setColor(1,1,int(TIME()*6.26)%2)
gc.print("#",330,545)
gc.print(#BAG,360,545)
end
@@ -149,7 +148,7 @@ function scene.draw()
--Sequence
if #MISSION>0 then
gc.setColor(1,CUSTOMENV.missionKill and 0 or 1,int(Timer()*6.26)%2)
gc.setColor(1,CUSTOMENV.missionKill and 0 or 1,int(TIME()*6.26)%2)
gc.print("#",610,545)
gc.print(#MISSION,640,545)
end

View File

@@ -1,6 +1,5 @@
local gc,sys=love.graphics,love.system
local kb=love.keyboard
local Timer=love.timer.getTime
local int,sin=math.floor,math.sin
local ins,rem=table.insert,table.remove
@@ -160,7 +159,7 @@ function scene.draw()
if N>0 then
gc.setColor(libColor[set[N]])
elseif L[i]>4 then
gc.setColor(COLOR.rainbow(i+Timer()*6.26))
gc.setColor(COLOR.rainbow(i+TIME()*6.26))
else
gc.setColor(COLOR.grey)
end
@@ -175,7 +174,7 @@ function scene.draw()
until i>j+1
--Draw cursor
gc.setColor(1,1,.4,.6+.4*sin(Timer()*6.26))
gc.setColor(1,1,.4,.6+.4*sin(TIME()*6.26))
gc.line(cx-5,cy-20,cx-5,cy+20)
--Confirm reset

View File

@@ -1,6 +1,5 @@
local gc,sys=love.graphics,love.system
local kb=love.keyboard
local Timer=love.timer.getTime
local sin=math.sin
local ins,rem=table.insert,table.remove
@@ -171,7 +170,7 @@ function scene.draw()
gc.print(#L,120,310)
--Draw cursor
gc.setColor(.5,1,.5,.6+.4*sin(Timer()*6.26))
gc.setColor(.5,1,.5,.6+.4*sin(TIME()*6.26))
gc.line(cx-5,cy-20,cx-5,cy+20)
--Confirm reset

View File

@@ -1,5 +1,4 @@
local gc=love.graphics
local Timer=love.timer.getTime
local int,abs=math.floor,math.abs
local min,sin=math.min,math.sin
@@ -158,20 +157,20 @@ function scene.draw()
local list=result[1]and result or dict
gc.setColor(1,1,1)
local text=list[selected][4]
if #text>900 then
local t=list[selected][4]
if #t>900 then
setFont(15)
elseif #text>600 then
elseif #t>600 then
setFont(20)
elseif #text>400 then
elseif #t>400 then
setFont(25)
else
setFont(30)
end
gc.printf(text,306,180,950)
gc.printf(t,306,180,950)
setFont(30)
gc.setColor(1,1,1,.4+.2*sin(Timer()*4))
gc.setColor(1,1,1,.4+.2*sin(TIME()*4))
gc.rectangle("fill",20,143+35*(selected-scrollPos),280,35)
setFont(30)
@@ -193,10 +192,10 @@ function scene.draw()
gc.rectangle("line",20,180,280,526)
if waiting>0 then
local r=Timer()*2
local r=TIME()*2
local R=int(r)%7+1
gc.setColor(1,1,1,1-abs(r%1*2-1))
gc.draw(TEXTURE.miniBlock[R],785,140,Timer()*10%6.2832,15,15,spinCenters[R][0][2]+.5,#BLOCKS[R][0]-spinCenters[R][0][1]-.5)
gc.draw(TEXTURE.miniBlock[R],785,140,TIME()*10%6.2832,15,15,spinCenters[R][0][2]+.5,#BLOCKS[R][0]-spinCenters[R][0][1]-.5)
end
end

View File

@@ -1,5 +1,4 @@
local gc=love.graphics
local Timer=love.timer.getTime
local sin=math.sin
@@ -10,23 +9,33 @@ function scene.sceneInit()
end
function scene.draw()
--Draw all texts
setFont(20)
gc.setColor(1,1,1)
for i=1,#text.help do
gc.printf(text.help[i],150,35*i+40,1000,"center")
end
--Lib used
setFont(15)
gc.print(text.used,30,330)
gc.draw(IMG.title,280,610,.1,1+.05*sin(Timer()*2.6),nil,206,35)
local t=TIME()
--Sponsor code
gc.draw(IMG.title,280,610,.1,1+.05*sin(t*2.6),nil,206,35)
gc.setLineWidth(3)
gc.rectangle("line",18,18,263,263)
gc.rectangle("line",1012,18,250,250)
--Group code
setFont(20)
mStr(text.group,640,490)
gc.setColor(1,1,1,sin(Timer()*20)*.3+.6)
--Support text
gc.setColor(1,1,1,sin(t*20)*.3+.6)
setFont(30)
mStr(text.support,150+sin(Timer()*4)*20,283)
mStr(text.support,1138-sin(Timer()*4)*20,270)
mStr(text.support,150+sin(t*4)*20,283)
mStr(text.support,1138-sin(t*4)*20,270)
end
scene.widgetList={

View File

@@ -1,5 +1,4 @@
local gc=love.graphics
local Timer=love.timer.getTime
local abs=math.abs
local max,min,sin,cos=math.max,math.min,math.sin,math.cos
@@ -59,11 +58,11 @@ local titleTransform={
end,
function(t,i)
local d=max(50-t,0)
gc.translate(sin(Timer()*3+626*i)*d,cos(Timer()*3+626*i)*d)
gc.translate(sin(TIME()*3+626*i)*d,cos(TIME()*3+626*i)*d)
end,
function(t,i)
local d=max(50-t,0)
gc.translate(sin(Timer()*3+626*i)*d,-cos(Timer()*3+626*i)*d)
gc.translate(sin(TIME()*3+626*i)*d,-cos(TIME()*3+626*i)*d)
end,
function(t)
gc.setColor(1,1,1,min(t*.02,1)+rnd()*.2)
@@ -96,7 +95,7 @@ function scene.draw()
gc.pop()
if t2>=80 then
gc.setColor(1,1,1,.6+sin((t2-80)*.0626)*.3)
mText(drawableText.anykey,640,615+sin(Timer()*3)*5)
mText(drawableText.anykey,640,615+sin(TIME()*3)*5)
end
end

View File

@@ -1,6 +1,5 @@
local gc=love.graphics
local tc=love.touch
local Timer=love.timer.getTime
local max,min,sin=math.max,math.min,math.sin
@@ -224,14 +223,14 @@ function scene.draw()
gc.setColor(.4,.4,.4)
gc.rectangle("fill",0,0,440,260)
local T=Timer()
local t=TIME()
gc.setColor(COLOR.dCyan)
mDraw(studioLogo,220,Y*.2-1204)
mDraw(studioLogo,220,-Y*.2+1476)
gc.setColor(COLOR.cyan)
mDraw(studioLogo,220+4*sin(T*10),136+4*sin(T*6))
mDraw(studioLogo,220+4*sin(T*12),136+4*sin(T*8))
mDraw(studioLogo,220+4*sin(t*10),136+4*sin(t*6))
mDraw(studioLogo,220+4*sin(t*12),136+4*sin(t*8))
gc.setColor(COLOR.dCyan)
mDraw(studioLogo,219,137)

View File

@@ -1,11 +1,8 @@
local gc=love.graphics
local Timer=love.timer.getTime
local mStr=mStr
local int=math.floor
local rnd=math.random
local int,rnd=math.floor,math.random
local format=string.format
local mStr=mStr
local scene={}
@@ -120,11 +117,11 @@ local function tapBoard(x,y,key)
move=move+moves
if state==0 then
state=1
startTime=Timer()
startTime=TIME()
end
if checkBoard(b)then
state=2
time=Timer()-startTime
time=TIME()-startTime
if time<1 then LOG.print("不是人",COLOR.lBlue)
elseif time<2 then LOG.print("还是人",COLOR.lBlue)
elseif time<3 then LOG.print("神仙",COLOR.lBlue)
@@ -203,7 +200,7 @@ end
function scene.update()
if state==1 then
time=Timer()-startTime
time=TIME()-startTime
end
end

View File

@@ -1,8 +1,6 @@
local gc=love.graphics
local Timer=love.timer.getTime
local rnd=math.random
local format=string.format
local mStr=mStr
local levels={
@@ -63,9 +61,9 @@ function scene.keyDown(key)
SFX.play("move")
if progress==2 then
state=1
startTime=Timer()
startTime=TIME()
elseif progress>#targetString then
time=Timer()-startTime
time=TIME()-startTime
state=2
SFX.play("reach")
end
@@ -87,7 +85,7 @@ end
function scene.update()
if state==1 then
frameKeyCount=0
time=Timer()-startTime
time=TIME()-startTime
end
end

View File

@@ -1,6 +1,5 @@
local gc=love.graphics
local int=math.floor
local Timer=love.timer.getTime
local lines={
{1,2,3},
@@ -28,7 +27,7 @@ local function restart()
curX,curx=nil
round=0
target=false
placeTime=Timer()
placeTime=TIME()
gameover=false
for X=1,9 do
score[X]=false
@@ -61,7 +60,7 @@ local function place(X,x)
SFX.play("move")
lastX,lastx=X,x
curX,curx=nil
placeTime=Timer()
placeTime=TIME()
if checkBoard(board[X],round)then
score[X]=round
if checkBoard(score,round)then
@@ -112,7 +111,7 @@ function scene.draw()
gc.rectangle("fill",0,0,90,90)
--Draw target area
gc.setColor(1,1,1,math.sin((Timer()-placeTime)*5)/5+.2)
gc.setColor(1,1,1,math.sin((TIME()-placeTime)*5)/5+.2)
if target then
gc.rectangle("fill",(target-1)%3*30,int((target-1)/3)*30,30,30)
elseif not gameover then
@@ -165,7 +164,7 @@ function scene.draw()
--Draw last pos
if lastX then
gc.setColor(.5,1,.4,.8)
local r=.5+.5*math.sin(Timer()*6.26)
local r=.5+.5*math.sin(TIME()*6.26)
gc.rectangle("line",(lastX-1)%3*30+(lastx-1)%3*10-r,int((lastX-1)/3)*30+int((lastx-1)/3)*10-r,10+2*r,10+2*r)
end
gc.pop()

View File

@@ -1,14 +1,11 @@
local gc=love.graphics
local ms=love.mouse
local Timer=love.timer.getTime
local setFont=setFont
local mStr=mStr
local int=math.floor
local rnd=math.random
local int,rnd=math.floor,math.random
local format=string.format
local rem=table.remove
local setFont=setFont
local mStr=mStr
local scene={}
@@ -52,7 +49,7 @@ local function tapBoard(x,y)
if state==0 then
newBoard()
state=1
startTime=Timer()
startTime=TIME()
progress=0
elseif state==1 then
local X=int((x-320)/640*R)
@@ -63,7 +60,7 @@ local function tapBoard(x,y)
if progress<R^2 then
SFX.play("lock")
else
time=Timer()-startTime+mistake
time=TIME()-startTime+mistake
state=2
SFX.play("reach")
end
@@ -121,7 +118,7 @@ end
function scene.update()
if state==1 then
time=Timer()-startTime+mistake
time=TIME()-startTime+mistake
end
end

View File

@@ -1,7 +1,6 @@
local mt=love.math
local gc=love.graphics
local ms,kb,tc=love.mouse,love.keyboard,love.touch
local Timer=love.timer.getTime
local max,min=math.max,math.min
local int,abs=math.floor,math.abs
@@ -217,7 +216,7 @@ function scene.draw()
if c then
gc.setColor(c)
else
c=.5+sin(Timer()*6.26)*.2
c=.5+sin(TIME()*6.26)*.2
gc.setColor(c,c,c)
end

View File

@@ -1,5 +1,4 @@
local gc=love.graphics
local Timer=love.timer.getTime
local sin=math.sin
@@ -63,13 +62,14 @@ function scene.draw()
gc.draw(IMG.title,840,220,nil,1.5,nil,206,35)
if BGM.nowPlay then
setFont(50)
gc.setColor(sin(Timer()*.5)*.2+.8,sin(Timer()*.7)*.2+.8,sin(Timer())*.2+.8)
local t=TIME()
gc.setColor(sin(t*.5)*.2+.8,sin(t*.7)*.2+.8,sin(t)*.2+.8)
gc.print(BGM.nowPlay,710,500)
local t=-Timer()%2.3/2
if t<1 then
gc.setColor(1,1,1,t)
gc.draw(IMG.title_color,840,220,nil,1.5+.1-.1*t,1.5+.3-.3*t,206,35)
local a=-t%2.3/2
if a<1 then
gc.setColor(1,1,1,a)
gc.draw(IMG.title_color,840,220,nil,1.5+.1-.1*a,1.5+.3-.3*a,206,35)
end
end
end

View File

@@ -1,5 +1,4 @@
local gc=love.graphics
local Timer=love.timer.getTime
local int=math.floor
local sin,log=math.sin,math.log10
@@ -269,7 +268,7 @@ function scene.draw()
--Polygon
gc.push("transform")
gc.scale((3-2*T)*T)
gc.setColor(1,1,1,T*(.5+.3*sin(Timer()*6.26)))gc.polygon("line",standard)
gc.setColor(1,1,1,T*(.5+.3*sin(TIME()*6.26)))gc.polygon("line",standard)
gc.setColor(chartColor[1],chartColor[2],chartColor[3],T*.626)
for i=1,9,2 do
gc.polygon("fill",0,0,val[i],val[i+1],val[i+2],val[i+3])
@@ -287,7 +286,7 @@ function scene.draw()
--Texts
local C
_=Timer()%6.2832
_=TIME()%6.2832
if _>3.1416 then
gc.setColor(1,1,1,-T*sin(_))
setFont(35)

View File

@@ -1,6 +1,6 @@
local gc=love.graphics
local tc=love.touch
local Timer=love.timer.getTime
local TIME=TIME
local max,sin=math.max,math.sin
local log=math.log
@@ -254,10 +254,10 @@ function scene.update(dt)
end
local function drawAtkPointer(x,y)
local t=sin(Timer()*20)
local t=sin(TIME()*20)
gc.setColor(.2,.7+t*.2,1,.6+t*.4)
gc.circle("fill",x,y,25,6)
local a=Timer()*3%1*.8
local a=TIME()*3%1*.8
gc.setColor(0,.6,1,.8-a)
gc.circle("line",x,y,30*(1+a),6)
end
@@ -299,9 +299,9 @@ local function drawVirtualkey()
end
end
function scene.draw()
local t=TIME()
if MARKING then
setFont(25)
local t=Timer()
gc.setColor(1,1,1,.2+.1*(sin(3*t)+sin(2.6*t)))
mStr(text.marking,190,60+26*sin(t))
end
@@ -337,7 +337,7 @@ function scene.draw()
--Replaying
if GAME.replaying then
gc.setColor(1,1,Timer()%1>.5 and 1 or 0)
gc.setColor(1,1,t%1>.5 and 1 or 0)
mText(drawableText.replaying,410,17)
end

View File

@@ -1,6 +1,4 @@
local gc=love.graphics
local Timer=love.timer.getTime
local int=math.floor
local scene={}
@@ -14,7 +12,7 @@ end
function scene.draw()
gc.setColor(1,1,1)
gc.draw(SKIN.curText[int(Timer()*2)%16+1],740,540,Timer()%6.28319,2,nil,15,15)
gc.draw(SKIN.curText[int(TIME()*2)%16+1],740,540,TIME()%6.28319,2,nil,15,15)
end
scene.widgetList={

View File

@@ -1,9 +1,6 @@
local gc=love.graphics
local Timer=love.timer.getTime
local mStr=mStr
local int,sin=math.floor,math.sin
local mStr=mStr
local scene={}
@@ -92,7 +89,7 @@ function scene.gamepadDown(key)
end
function scene.draw()
local a=.3+sin(Timer()*15)*.1
local a=.3+sin(TIME()*15)*.1
if kS then gc.setColor(1,.3,.3,a)else gc.setColor(1,.7,.7,a)end
gc.rectangle("fill",
kb<11 and 240 or 840,

View File

@@ -1,5 +1,4 @@
local gc=love.graphics
local Timer=love.timer.getTime
local sin=math.sin
local scene={}
@@ -18,7 +17,7 @@ function scene.draw()
gc.draw(texture[color],x+30*j,y-30*i)
end
end end
gc.circle("fill",-10+140*N,340,sin(Timer()*10)+5)
gc.circle("fill",-10+140*N,340,sin(TIME()*10)+5)
end
gc.draw(texture[17],930,610,nil,2)
for i=1,5 do

View File

@@ -1,5 +1,4 @@
local gc=love.graphics
local Timer=love.timer.getTime
local sin=math.sin
local rnd=math.random
@@ -23,10 +22,10 @@ end
function scene.mouseDown(x,y)
if x>780 and x<980 and y>470 and jump==0 then
jump=10
local t=Timer()-last
local t=TIME()-last
if t>1 then
VOC.play((t<1.5 or t>15)and"doubt"or rnd()<.8 and"happy"or"egg")
last=Timer()
last=TIME()
end
end
end
@@ -43,7 +42,7 @@ end
function scene.draw()
gc.setColor(1,1,1)
local t=Timer()
local t=TIME()
local _=jump
local x,y=800,340+10*sin(t*.5)+(_-10)*_*.3
gc.translate(x,y)

View File

@@ -1,6 +1,5 @@
local gc=love.graphics
local ms=love.mouse
local Timer=love.timer.getTime
local int,sin=math.floor,math.sin
@@ -91,7 +90,7 @@ function scene.draw()
local d=snapUnit
if d>=10 then
gc.setLineWidth(3)
gc.setColor(1,1,1,sin(Timer()*4)*.1+.1)
gc.setColor(1,1,1,sin(TIME()*4)*.1+.1)
for i=1,1280/d-1 do
gc.line(d*i,0,d*i,720)
end

View File

@@ -1,9 +1,7 @@
local gc=love.graphics
local Timer=love.timer.getTime
local abs,int,sin=math.abs,math.floor,math.sin
local format=string.format
local mStr=mStr
local scene={}
@@ -88,12 +86,13 @@ function scene.draw()
gc.line(40,240+40*y,600,240+40*y)
end
gc.draw(IMG.title,260,615,.2+.04*sin(Timer()*3),nil,nil,206,35)
local t=TIME()
gc.draw(IMG.title,260,615,.2+.04*sin(t*3),nil,nil,206,35)
local r=Timer()*2
local r=t*2
local R=int(r)%7+1
gc.setColor(1,1,1,1-abs(r%1*2-1))
gc.draw(TEXTURE.miniBlock[R],680,50,Timer()*10%6.2832,15,15,spinCenters[R][0][2]+.5,#BLOCKS[R][0]-spinCenters[R][0][1]-.5)
gc.draw(TEXTURE.miniBlock[R],680,50,t*10%6.2832,15,15,spinCenters[R][0][2]+.5,#BLOCKS[R][0]-spinCenters[R][0][1]-.5)
gc.draw(TEXTURE.miniBlock[R],680,300,0,15,15,spinCenters[R][0][2]+.5,#BLOCKS[R][0]-spinCenters[R][0][1]-.5)
end