整理代码,Zframework添加数学扩展模块

This commit is contained in:
MrZ626
2021-11-15 15:46:57 +08:00
parent 7710f0b70f
commit fa0bc3805f
6 changed files with 26 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ LOADED=false
ERRDATA={}
--Pure lua modules (basic)
MATH= require'Zframework.mathExtend'
COLOR= require'Zframework.color'
TABLE= require'Zframework.tableExtend'
STRING= require'Zframework.stringExtend'

19
Zframework/mathExtend.lua Normal file
View File

@@ -0,0 +1,19 @@
local MATH={}for k,v in next,math do MATH[k]=v end
local rnd=math.random
MATH.tau=2*math.pi
function MATH.sign(a)
return a>0 and 1 or a<0 and -1 or 0
end
function MATH.coin(a,b)
if rnd()<.5 then
return a
else
return b
end
end
return MATH

View File

@@ -231,13 +231,6 @@ end
function getItem(itemName,amount)
STAT.item[itemName]=STAT.item[itemName]+(amount or 1)
end
function coin(a,b)
if rnd()<.5 then
return a
else
return b
end
end
function generateLine(hole)
return 1023-2^(hole-1)
end

View File

@@ -7,7 +7,6 @@ local setFont,mStr=FONT.set,GC.mStr
local int,rnd,abs=math.floor,math.random,math.abs
local max,min=math.max,math.min
local ins,rem=table.insert,table.remove
local function sign(a)return a>0 and 1 or a<0 and -1 or 0 end
local levels={
{c=6,r=3,color=3},
@@ -289,7 +288,7 @@ function scene.update(dt)
if state==1 then
time=TIME()-startTime
comboTime=max(comboTime-dt,0)
score1=score1+sign(score-score1)+int((score-score1)*.1+.5)
score1=score1+MATH.sign(score-score1)+int((score-score1)*.1+.5)
end
if sure>0 then sure=sure-dt end

View File

@@ -19,7 +19,7 @@ function scene.sceneInit()
end
function scene.touchDown(x,y,k)
--TODO
end
scene.mouseDown=scene.touchDown
@@ -41,10 +41,6 @@ function scene.keyDown(key,isRep)
end
end
function scene.update(dt)
end
function scene.draw()
setFont(30)
gc.print(inst,40,60)
@@ -52,6 +48,6 @@ function scene.draw()
end
scene.widgetList={
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,fText=CHAR.icon.back,code=backScene},
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,font=60,fText=CHAR.icon.back,code=backScene},
}
return scene

View File

@@ -14,9 +14,9 @@ local widgetX0={
}
local enterConsole=coroutine.wrap(function()
while true do
Snd('bell',.6,'A4',.7,'E5',1,coin('A5','B5'))YIELD()
Snd('bell',.6,'A4',.7,'F5',1,coin('C6','D6'))YIELD()
Snd('bell',.6,'A4',.7,'G5',1,coin('E6','G6'))YIELD()
Snd('bell',.6,'A4',.7,'E5',1,MATH.coin('A5','B5'))YIELD()
Snd('bell',.6,'A4',.7,'F5',1,MATH.coin('C6','D6'))YIELD()
Snd('bell',.6,'A4',.7,'G5',1,MATH.coin('E6','G6'))YIELD()
Snd('bell',.6,'A4',.7,'A5',1,'A6')SFX.play('ren_mega')SCN.go('app_console')YIELD()
end
end)