整理代码,略微提升部分小程序的性能

This commit is contained in:
MrZ626
2021-09-21 00:27:27 +08:00
parent 1d30623222
commit 6f715a663a
17 changed files with 39 additions and 40 deletions

View File

@@ -1,7 +1,7 @@
local gc=love.graphics local gc=love.graphics
local int,rnd=math.floor,math.random local int,rnd=math.floor,math.random
local mStr=mStr local mStr=GC.mStr
local scene={} local scene={}
@@ -258,7 +258,7 @@ local backColor={
},--Black },--Black
} }
function scene.draw() function scene.draw()
setFont(40) FONT.get(40)
gc.setColor(COLOR.Z) gc.setColor(COLOR.Z)
gc.print(("%.3f"):format(time),1026,80) gc.print(("%.3f"):format(time),1026,80)
gc.setColor(1,.8,.8) gc.setColor(1,.8,.8)
@@ -282,7 +282,7 @@ function scene.draw()
gc.setLineWidth(4) gc.setLineWidth(4)
local mono=invis and state==1 local mono=invis and state==1
setFont(80) FONT.get(80)
for i=1,4 do for i=1,4 do
for j=1,4 do for j=1,4 do
if cx~=j or cy~=i then if cx~=j or cy~=i then

View File

@@ -4,8 +4,8 @@ local setColor,rectangle=gc.setColor,gc.rectangle
local int,abs=math.floor,math.abs local int,abs=math.floor,math.abs
local rnd,min=math.random,math.min local rnd,min=math.random,math.min
local ins=table.insert local ins=table.insert
local setFont=setFont local setFont=FONT.get
local mStr=mStr local mStr=GC.mStr
local scene={} local scene={}

View File

@@ -1,6 +1,5 @@
local gc=love.graphics local gc=love.graphics
local rnd=math.random local rnd=math.random
local mStr=mStr
local levels={ local levels={
A_Z="ABCDEFGHIJKLMNOPQRSTUVWXYZ", A_Z="ABCDEFGHIJKLMNOPQRSTUVWXYZ",
@@ -83,7 +82,7 @@ function scene.update()
end end
function scene.draw() function scene.draw()
setFont(40) FONT.get(40)
gc.setColor(COLOR.Z) gc.setColor(COLOR.Z)
gc.print(("%.3f"):format(time),1026,80) gc.print(("%.3f"):format(time),1026,80)
gc.print(mistake,1026,150) gc.print(mistake,1026,150)
@@ -100,15 +99,15 @@ function scene.draw()
gc.setColor(.2,.8,.2)--ready gc.setColor(.2,.8,.2)--ready
end end
setFont(100) FONT.get(100)
mStr(state==1 and #targetString-progress+1 or state==0 and"Ready"or state==2 and"Win",640,200) GC.mStr(state==1 and #targetString-progress+1 or state==0 and"Ready"or state==2 and"Win",640,200)
gc.setColor(COLOR.Z) gc.setColor(COLOR.Z)
gc.print(targetString:sub(progress,progress),120,280,0,2) gc.print(targetString:sub(progress,progress),120,280,0,2)
gc.print(targetString:sub(progress+1),310,380) gc.print(targetString:sub(progress+1),310,380)
gc.setColor(1,1,1,.7) gc.setColor(1,1,1,.7)
setFont(40) FONT.get(40)
gc.print(targetString,120,520) gc.print(targetString,120,520)
end end

View File

@@ -171,7 +171,7 @@ function scene.draw()
if gameover then if gameover then
--Draw result --Draw result
setFont(60) FONT.get(60)
if gameover==0 then if gameover==0 then
gc.setColor(1,.6,.6) gc.setColor(1,.6,.6)
mStr("RED\nWON",1140,200) mStr("RED\nWON",1140,200)

View File

@@ -189,17 +189,17 @@ function scene.update(dt)
end end
end end
function scene.draw() function scene.draw()
setFont(35) FONT.get(35)
gc.setColor(COLOR.Z) gc.setColor(COLOR.Z)
mStr("["..level.."]",640,30) GC.mStr("["..level.."]",640,30)
setFont(100) FONT.get(100)
if type(question)=='table'then gc.setColor(1,1,1)end if type(question)=='table'then gc.setColor(1,1,1)end
mStr(question,640,60) GC.mStr(question,640,60)
setFont(80) FONT.get(80)
gc.setColor(1,1,1,inputTime) gc.setColor(1,1,1,inputTime)
mStr(input,640,160) GC.mStr(input,640,160)
end end
scene.widgetList={ scene.widgetList={

View File

@@ -114,10 +114,10 @@ function scene.draw()
gc.setColor(COLOR.Z) gc.setColor(COLOR.Z)
gc.setLineWidth(2) gc.setLineWidth(2)
gc.rectangle('line',100,80,650,150,5) gc.rectangle('line',100,80,650,150,5)
setFont(45) FONT.get(45)
if reg then gc.printf(reg,0,100,720,'right')end if reg then gc.printf(reg,0,100,720,'right')end
if val then gc.printf(val,0,150,720,'right')end if val then gc.printf(val,0,150,720,'right')end
if sym then setFont(50)gc.print(sym,126,150)end if sym then FONT.get(50)gc.print(sym,126,150)end
end end
scene.widgetList={ scene.widgetList={

View File

@@ -103,7 +103,7 @@ function scene.draw()
end end
--Info --Info
setFont(40) FONT.get(40)
if combo>1 then if combo>1 then
gc.setColor(1,1,.6) gc.setColor(1,1,.6)
gc.print("x"..combo,300,80) gc.print("x"..combo,300,80)

View File

@@ -1,10 +1,7 @@
local gc=love.graphics local gc,kb,tc=love.graphics,love.keyboard,love.touch
local kb=love.keyboard
local tc=love.touch
local rnd,int,abs=math.random,math.floor,math.abs local rnd,int,abs=math.random,math.floor,math.abs
local max,min=math.max,math.min local max,min=math.max,math.min
local setFont=setFont local setFont,mStr=FONT.get,GC.mStr
local cubeColor={ local cubeColor={
{.88,.75,.00}, {.88,.75,.00},

View File

@@ -1,10 +1,11 @@
local gc=love.graphics local gc=love.graphics
local rnd=math.random local rnd,int,max=math.random,math.floor,math.max
local int,max=math.floor,math.max local setFont,mStr=FONT.get,GC.mStr
--This mini-game is written for TI-nSpire CX CAS many years ago. --This mini-game is written for TI-nSpire CX CAS many years ago.
--Deliberately, some grammar mistakes and typos in the 'great' list remained. --Deliberately, some grammar mistakes and typos in the 'great' list remained.
--So no need to correct them. --So no need to correct them.
local perfect={"Perfect!","Excellent!","Nice!","Good!","Great!","Just!","300"} local perfect={"Perfect!","Excellent!","Nice!","Good!","Great!","Just!","300"}
local great={"Pay attention!","Be carefully!","Teacher behind you!","Feel tired?","You are in danger!","Do your homework!","A good game!","Minecraft!","y=ax^2+bx+c!","No music?","Internet unavailable.","It's raining!","Too hard!","Shorter?","Higher!","English messages!","Hi!","^_^","Drop!","Colorful!",":)","100$","~~~wave~~~","★★★","中文!","NOW!!!!!","Also try the TEN!","I'm a programer!","Also try minesweeperZ!","This si Dropper!","Hold your calculatoor!","Look! UFO!","Bonjour!","[string]","Author:MrZ","Boom!","PvZ!","China!","TI-nspire!","I love LUA!"} local great={"Pay attention!","Be carefully!","Teacher behind you!","Feel tired?","You are in danger!","Do your homework!","A good game!","Minecraft!","y=ax^2+bx+c!","No music?","Internet unavailable.","It's raining!","Too hard!","Shorter?","Higher!","English messages!","Hi!","^_^","Drop!","Colorful!",":)","100$","~~~wave~~~","★★★","中文!","NOW!!!!!","Also try the TEN!","I'm a programer!","Also try minesweeperZ!","This si Dropper!","Hold your calculatoor!","Look! UFO!","Bonjour!","[string]","Author:MrZ","Boom!","PvZ!","China!","TI-nspire!","I love LUA!"}
local miss={"Oops!","Uh-oh","Ouch!","Oh no."} local miss={"Oops!","Uh-oh","Ouch!","Oh no."}

View File

@@ -1,4 +1,5 @@
local gc=love.graphics local gc=love.graphics
local setFont,mStr=FONT.get,GC.mStr
local int,rnd=math.floor,math.random local int,rnd=math.floor,math.random
local ins,rem=table.insert,table.remove local ins,rem=table.insert,table.remove

View File

@@ -2,7 +2,7 @@ local ms=love.mouse
local msIsDown,kbIsDown=ms.isDown,love.keyboard.isDown local msIsDown,kbIsDown=ms.isDown,love.keyboard.isDown
local gc=love.graphics local gc=love.graphics
local gc_setColor,gc_rectangle,gc_draw=gc.setColor,gc.rectangle,gc.draw local gc_setColor,gc_rectangle,gc_draw=gc.setColor,gc.rectangle,gc.draw
local setFont=setFont local setFont,mStr=FONT.get,GC.mStr
local int,rnd,abs=math.floor,math.random,math.abs local int,rnd,abs=math.floor,math.random,math.abs
local max,min=math.max,math.min local max,min=math.max,math.min

View File

@@ -1,5 +1,7 @@
local gc=love.graphics local gc=love.graphics
local rnd,sin,cos=math.random,math.sin,math.cos local rnd,sin,cos=math.random,math.sin,math.cos
local setFont,mStr=FONT.get,GC.mStr
local tau=math.pi*2 local tau=math.pi*2
local state local state

View File

@@ -151,10 +151,10 @@ end
function scene.draw() function scene.draw()
--Draw score --Draw score
setFont(100)
gc.setColor(.4,.4,.4) gc.setColor(.4,.4,.4)
mStr(p1.score,470,20) FONT.get(100)
mStr(p2.score,810,20) GC.mStr(p1.score,470,20)
GC.mStr(p2.score,810,20)
--Draw boundary --Draw boundary
gc.setColor(COLOR.Z) gc.setColor(COLOR.Z)

View File

@@ -1,5 +1,6 @@
local gc=love.graphics local gc=love.graphics
local rnd=math.random local rnd=math.random
local setFont,mStr=FONT.get,GC.mStr
local scene={} local scene={}

View File

@@ -1,10 +1,7 @@
local gc=love.graphics local gc,ms=love.graphics,love.mouse
local ms=love.mouse
local int,rnd=math.floor,math.random local int,rnd=math.floor,math.random
local rem=table.remove local rem=table.remove
local setFont=setFont local setFont,mStr=FONT.get,GC.mStr
local mStr=mStr
local scene={} local scene={}

View File

@@ -1,7 +1,7 @@
local gc=love.graphics local gc=love.graphics
local max=math.max local max=math.max
local ins=table.insert local ins=table.insert
local mStr=mStr local setFont,mStr=FONT.get,GC.mStr
local scene={} local scene={}

View File

@@ -4,11 +4,12 @@ local setColor,rectangle=gc.setColor,gc.rectangle
local int,rnd=math.floor,math.random local int,rnd=math.floor,math.random
local ins,rem=table.insert,table.remove local ins,rem=table.insert,table.remove
local mStr=mStr local setFont,mStr=FONT.get,GC.mStr
local scene={} local scene={}
local previewX={245,186,129,78,35} local previewX={245,186,129,78,35}
local previewY={435,442,449,456,463}
local tileColor={ local tileColor={
{.39, 1.0, .39}, {.39, 1.0, .39},
{.39, .39, 1.0}, {.39, .39, 1.0},
@@ -246,7 +247,7 @@ function scene.draw()
for i=1,5 do for i=1,5 do
setFont(85-10*i) setFont(85-10*i)
gc.setColor(tileColor[preview[i]]) gc.setColor(tileColor[preview[i]])
gc.print(preview[i],previewX[i],428+i*7) gc.print(preview[i],previewX[i],previewY[i])
end end
end end
@@ -257,8 +258,8 @@ function scene.draw()
end end
gc.setLineWidth(10) gc.setLineWidth(10)
setColor(COLOR[ setColor(COLOR[
state==0 and'G'or
state==1 and(fast and'R'or'W')or state==1 and(fast and'R'or'W')or
state==0 and'G'or
state==2 and'Y' state==2 and'Y'
]) ])
rectangle('line',315,35,650,650) rectangle('line',315,35,650,650)