场景&事件系统重写

This commit is contained in:
MrZ626
2020-12-04 19:35:33 +08:00
parent 0b2abf71ea
commit 8a754431cf
48 changed files with 546 additions and 352 deletions

View File

@@ -5,7 +5,9 @@ local abs=math.abs
local max,min=math.max,math.min
local rnd=math.random
function sceneInit.mg_pong()
local scene={}
function scene.sceneInit()
BG.set("none")
BGM.play("way")
sceneTemp={
@@ -35,7 +37,7 @@ local function start()
sceneTemp.vx=rnd()>.5 and 6 or -6
sceneTemp.vy=rnd()*6-3
end
function keyDown.mg_pong(key)
function scene.keyDown(key)
local S=sceneTemp
if key=="space"then
if S.state==0 then
@@ -55,21 +57,21 @@ function keyDown.mg_pong(key)
SCN.back()
end
end
function touchDown.mg_pong(id,x,y)
touchMove.mg_pong(id,x,y)
function scene.touchDown(id,x,y)
scene.touchMove(id,x,y)
if sceneTemp.state==0 then
start()
end
end
function touchMove.mg_pong(_,x,y)
function scene.touchMove(_,x,y)
sceneTemp[x<640 and"p1"or"p2"].y0=y
end
function mouseMove.mg_pong(x,y)
function scene.mouseMove(x,y)
sceneTemp[x<640 and"p1"or"p2"].y0=y
end
--Rect Area X:150~1130 Y:20~700
function Tmr.mg_pong()
function scene.Tmr()
local S=sceneTemp
--Update pads
@@ -146,7 +148,7 @@ function Tmr.mg_pong()
S.x,S.y,S.vx,S.vy,S.ry=x,y,vx,vy,ry
end
function Pnt.mg_pong()
function scene.Pnt()
local S=sceneTemp
--Draw score
@@ -174,7 +176,9 @@ function Pnt.mg_pong()
gc.rectangle("fill",1130,S.p2.y-50,20,100)
end
WIDGET.init("mg_pong",{
scene.widgetList={
WIDGET.newKey{name="reset",x=640,y=45,w=150,h=50,font=35,code=WIDGET.lnk_pressKey("r")},
WIDGET.newKey{name="back",x=640,y=675,w=150,h=50,font=35,code=WIDGET.lnk_BACK},
})
}
return scene