淘汰sceneTemp技术
This commit is contained in:
@@ -7,75 +7,71 @@ local rnd=math.random
|
||||
|
||||
local scene={}
|
||||
|
||||
local bx,by=640,360--Ball posotion
|
||||
local vx,vy=0,0--Ball velocity
|
||||
local ry=0--Rotation Y
|
||||
|
||||
local p1,p2--Player data
|
||||
|
||||
function scene.sceneInit()
|
||||
BG.set("none")
|
||||
BGM.play("way")
|
||||
sceneTemp={
|
||||
state=0,
|
||||
state=0
|
||||
|
||||
x=640,y=360,
|
||||
vx=0,vy=0,
|
||||
ry=0,
|
||||
bx,by=640,360
|
||||
vx,vy=0,0
|
||||
ry=0
|
||||
|
||||
p1={
|
||||
score=0,
|
||||
y=360,
|
||||
vy=0,
|
||||
y0=false,
|
||||
},
|
||||
p2={
|
||||
score=0,
|
||||
y=360,
|
||||
vy=0,
|
||||
y0=false,
|
||||
},
|
||||
p1={
|
||||
score=0,
|
||||
y=360,
|
||||
vy=0,
|
||||
y0=false,
|
||||
}
|
||||
p2={
|
||||
score=0,
|
||||
y=360,
|
||||
vy=0,
|
||||
y0=false,
|
||||
}
|
||||
end
|
||||
|
||||
local function start()
|
||||
sceneTemp.state=1
|
||||
sceneTemp.vx=rnd()>.5 and 6 or -6
|
||||
sceneTemp.vy=rnd()*6-3
|
||||
state=1
|
||||
vx=rnd()>.5 and 6 or -6
|
||||
vy=rnd()*6-3
|
||||
end
|
||||
function scene.keyDown(key)
|
||||
local S=sceneTemp
|
||||
if key=="space"then
|
||||
if S.state==0 then
|
||||
if state==0 then
|
||||
start()
|
||||
end
|
||||
elseif key=="r"then
|
||||
S.state=0
|
||||
S.x,S.y=640,360
|
||||
S.vx,S.vy=0,0
|
||||
S.ry=0
|
||||
S.p1.score,S.p2.score=0,0
|
||||
state=0
|
||||
bx,by=640,360
|
||||
vx,vy=0,0
|
||||
ry=0
|
||||
p1.score,p2.score=0,0
|
||||
SFX.play("hold")
|
||||
elseif key=="w"or key=="s"then
|
||||
S.p1.y0=false
|
||||
p1.y0=false
|
||||
elseif key=="up"or key=="down"then
|
||||
S.p2.y0=false
|
||||
p2.y0=false
|
||||
elseif key=="escape"then
|
||||
SCN.back()
|
||||
end
|
||||
end
|
||||
function scene.touchDown(id,x,y)
|
||||
scene.touchMove(id,x,y)
|
||||
if sceneTemp.state==0 then
|
||||
start()
|
||||
end
|
||||
end
|
||||
function scene.touchMove(_,x,y)
|
||||
sceneTemp[x<640 and"p1"or"p2"].y0=y
|
||||
end
|
||||
function scene.mouseMove(x,y)
|
||||
sceneTemp[x<640 and"p1"or"p2"].y0=y
|
||||
if state==0 then start()end
|
||||
end
|
||||
function scene.touchMove(_,x,y)(x<640 and p1 or p2).y0=y end
|
||||
function scene.mouseMove(x,y)(x<640 and p1 or p2).y0=y end
|
||||
|
||||
--Rect Area X:150~1130 Y:20~700
|
||||
function scene.update()
|
||||
local S=sceneTemp
|
||||
|
||||
--Update pads
|
||||
local P=S.p1
|
||||
local P=p1
|
||||
while P do
|
||||
if P.y0 then
|
||||
if P.y>P.y0 then
|
||||
@@ -88,8 +84,8 @@ function scene.update()
|
||||
P.vy=P.vy*.5
|
||||
end
|
||||
else
|
||||
if kb.isDown(P==S.p1 and"w"or"up")then P.vy=max(P.vy-1,-8)end
|
||||
if kb.isDown(P==S.p1 and"s"or"down")then P.vy=min(P.vy+1,8)end
|
||||
if kb.isDown(P==p1 and"w"or"up")then P.vy=max(P.vy-1,-8)end
|
||||
if kb.isDown(P==p1 and"s"or"down")then P.vy=min(P.vy+1,8)end
|
||||
P.y=P.y+P.vy
|
||||
P.vy=P.vy*.9
|
||||
if P.y>650 then
|
||||
@@ -100,12 +96,11 @@ function scene.update()
|
||||
P.y=70
|
||||
end
|
||||
end
|
||||
P=P==S.p1 and S.p2
|
||||
P=P==p1 and p2
|
||||
end
|
||||
|
||||
--Update ball
|
||||
local x,y,vx,vy,ry=S.x,S.y,S.vx,S.vy,S.ry
|
||||
x,y=x+vx,y+vy
|
||||
bx,by=bx+vx,by+vy
|
||||
if ry~=0 then
|
||||
if ry>0 then
|
||||
ry=max(ry-.1,0)
|
||||
@@ -115,47 +110,45 @@ function scene.update()
|
||||
vy=vy+.1
|
||||
end
|
||||
end
|
||||
if S.state==1 then--Playing
|
||||
if x<160 or x>1120 then
|
||||
P=x<160 and S.p1 or S.p2
|
||||
local d=y-P.y
|
||||
if state==1 then--Playing
|
||||
if bx<160 or bx>1120 then
|
||||
P=bx<160 and p1 or p2
|
||||
local d=by-P.y
|
||||
if abs(d)<60 then
|
||||
vx=-vx-(vx>0 and .05 or -.5)
|
||||
vy=vy+d*.08+P.vy*.5
|
||||
ry=P.vy
|
||||
SFX.play("collect")
|
||||
else
|
||||
S.state=2
|
||||
state=2
|
||||
end
|
||||
end
|
||||
if y<30 or y>690 then
|
||||
y=y<30 and 30 or 690
|
||||
if by<30 or by>690 then
|
||||
by=by<30 and 30 or 690
|
||||
vy,ry=-vy,-ry
|
||||
SFX.play("collect")
|
||||
end
|
||||
elseif S.state==2 then--Game over
|
||||
if x<-120 or x>1400 or y<-40 or y>760 then
|
||||
P=x>640 and S.p1 or S.p2
|
||||
elseif state==2 then--Game over
|
||||
if bx<-120 or bx>1400 or by<-40 or by>760 then
|
||||
P=bx>640 and p1 or p2
|
||||
P.score=P.score+1
|
||||
TEXT.show("+1",x>1400 and 470 or 810,226,50,"score")
|
||||
TEXT.show("+1",bx>1400 and 470 or 810,226,50,"score")
|
||||
SFX.play("reach")
|
||||
|
||||
S.state=0
|
||||
x,y=640,360
|
||||
state=0
|
||||
bx,by=640,360
|
||||
vx,vy=0,0
|
||||
end
|
||||
end
|
||||
S.x,S.y,S.vx,S.vy,S.ry=x,y,vx,vy,ry
|
||||
bx,by,vx,vy,ry=bx,by,vx,vy,ry
|
||||
end
|
||||
|
||||
function scene.draw()
|
||||
local S=sceneTemp
|
||||
|
||||
--Draw score
|
||||
setFont(100)
|
||||
gc.setColor(.4,.4,.4)
|
||||
mStr(S.p1.score,470,20)
|
||||
mStr(S.p2.score,810,20)
|
||||
mStr(p1.score,470,20)
|
||||
mStr(p2.score,810,20)
|
||||
|
||||
--Draw boundary
|
||||
gc.setColor(1,1,1)
|
||||
@@ -164,16 +157,16 @@ function scene.draw()
|
||||
gc.line(130,700,1160,700)
|
||||
|
||||
--Draw ball & speed line
|
||||
gc.setColor(1,1,1-abs(S.ry)*.16)
|
||||
gc.circle("fill",S.x,S.y,10)
|
||||
gc.setColor(1,1,1-abs(ry)*.16)
|
||||
gc.circle("fill",bx,by,10)
|
||||
gc.setColor(1,1,1,.1)
|
||||
gc.line(S.x+S.vx*22,S.y+S.vy*22,S.x+S.vx*30,S.y+S.vy*30)
|
||||
gc.line(bx+vx*22,by+vy*22,bx+vx*30,by+vy*30)
|
||||
|
||||
--Draw pads
|
||||
gc.setColor(1,.8,.8)
|
||||
gc.rectangle("fill",130,S.p1.y-50,20,100)
|
||||
gc.rectangle("fill",130,p1.y-50,20,100)
|
||||
gc.setColor(.8,.8,1)
|
||||
gc.rectangle("fill",1130,S.p2.y-50,20,100)
|
||||
gc.rectangle("fill",1130,p2.y-50,20,100)
|
||||
end
|
||||
|
||||
scene.widgetList={
|
||||
|
||||
Reference in New Issue
Block a user