联网对战(初版,不可用)
This commit is contained in:
@@ -477,18 +477,23 @@ function applyCustomGame()--Apply CUSTOMENV, BAG, MISSION
|
|||||||
GAME.modeEnv.mission=nil
|
GAME.modeEnv.mission=nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function loadGame(M,ifQuickPlay)--Load a mode and go to game scene
|
function loadGame(M,ifQuickPlay,ifNet)--Load a mode and go to game scene
|
||||||
freshDate()
|
freshDate()
|
||||||
if legalGameTime()then
|
if legalGameTime()then
|
||||||
if MODES[M].score then STAT.lastPlay=M end
|
if MODES[M].score then STAT.lastPlay=M end
|
||||||
GAME.curModeName=M
|
GAME.curModeName=M
|
||||||
GAME.curMode=MODES[M]
|
GAME.curMode=MODES[M]
|
||||||
GAME.modeEnv=GAME.curMode.env
|
GAME.modeEnv=GAME.curMode.env
|
||||||
drawableText.modeName:set(text.modes[M][1])
|
|
||||||
drawableText.levelName:set(text.modes[M][2])
|
|
||||||
GAME.init=true
|
GAME.init=true
|
||||||
SCN.go("play",ifQuickPlay and"swipeD"or"fade_togame")
|
GAME.net=ifNet
|
||||||
SFX.play("enter")
|
if ifNet then
|
||||||
|
SCN.go("net_game","swipeD")
|
||||||
|
else
|
||||||
|
drawableText.modeName:set(text.modes[M][1])
|
||||||
|
drawableText.levelName:set(text.modes[M][2])
|
||||||
|
SCN.go("play",ifQuickPlay and"swipeD"or"fade_togame")
|
||||||
|
SFX.play("enter")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function initPlayerPosition(sudden)--Set initial position for every player
|
function initPlayerPosition(sudden)--Set initial position for every player
|
||||||
@@ -506,26 +511,32 @@ function initPlayerPosition(sudden)--Set initial position for every player
|
|||||||
if L[3]then L[3][method](L[3],965,30,.5)end
|
if L[3]then L[3][method](L[3],965,30,.5)end
|
||||||
if L[4]then L[4][method](L[4],20,390,.5)end
|
if L[4]then L[4][method](L[4],20,390,.5)end
|
||||||
if L[5]then L[5][method](L[5],20,30,.5)end
|
if L[5]then L[5][method](L[5],20,30,.5)end
|
||||||
elseif #L==49 then
|
elseif #L<=49 then
|
||||||
local n=2
|
local n=2
|
||||||
for i=1,4 do for j=1,6 do
|
for i=1,4 do for j=1,6 do
|
||||||
|
if not L[n]then return end
|
||||||
L[n][method](L[n],78*i-54,115*j-98,.09)
|
L[n][method](L[n],78*i-54,115*j-98,.09)
|
||||||
n=n+1
|
n=n+1
|
||||||
end end
|
end end
|
||||||
for i=9,12 do for j=1,6 do
|
for i=9,12 do for j=1,6 do
|
||||||
|
if not L[n]then return end
|
||||||
L[n][method](L[n],78*i+267,115*j-98,.09)
|
L[n][method](L[n],78*i+267,115*j-98,.09)
|
||||||
n=n+1
|
n=n+1
|
||||||
end end
|
end end
|
||||||
elseif #L==99 then
|
elseif #L<=99 then
|
||||||
local n=2
|
local n=2
|
||||||
for i=1,7 do for j=1,7 do
|
for i=1,7 do for j=1,7 do
|
||||||
|
if not L[n]then return end
|
||||||
L[n][method](L[n],46*i-36,97*j-72,.068)
|
L[n][method](L[n],46*i-36,97*j-72,.068)
|
||||||
n=n+1
|
n=n+1
|
||||||
end end
|
end end
|
||||||
for i=15,21 do for j=1,7 do
|
for i=15,21 do for j=1,7 do
|
||||||
|
if not L[n]then return end
|
||||||
L[n][method](L[n],46*i+264,97*j-72,.068)
|
L[n][method](L[n],46*i+264,97*j-72,.068)
|
||||||
n=n+1
|
n=n+1
|
||||||
end end
|
end end
|
||||||
|
else
|
||||||
|
error("TOO MANY PLAYERS!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
do--function resetGameData(args)
|
do--function resetGameData(args)
|
||||||
@@ -568,7 +579,7 @@ do--function resetGameData(args)
|
|||||||
end
|
end
|
||||||
return S
|
return S
|
||||||
end
|
end
|
||||||
function resetGameData(args)
|
function resetGameData(args,playerData)
|
||||||
if not args then args=""end
|
if not args then args=""end
|
||||||
if PLAYERS[1]and not GAME.replaying and(GAME.frame>400 or GAME.result)then
|
if PLAYERS[1]and not GAME.replaying and(GAME.frame>400 or GAME.result)then
|
||||||
mergeStat(STAT,PLAYERS[1].stat)
|
mergeStat(STAT,PLAYERS[1].stat)
|
||||||
@@ -583,7 +594,7 @@ do--function resetGameData(args)
|
|||||||
GAME.recording=false
|
GAME.recording=false
|
||||||
GAME.replaying=1
|
GAME.replaying=1
|
||||||
else
|
else
|
||||||
GAME.frame=150-SETTING.reTime*15
|
GAME.frame=args:find("n")and 0 or 150-SETTING.reTime*15
|
||||||
GAME.seed=rnd(1046101471,2662622626)
|
GAME.seed=rnd(1046101471,2662622626)
|
||||||
GAME.pauseTime=0
|
GAME.pauseTime=0
|
||||||
GAME.pauseCount=0
|
GAME.pauseCount=0
|
||||||
@@ -597,7 +608,7 @@ do--function resetGameData(args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
destroyPlayers()
|
destroyPlayers()
|
||||||
GAME.curMode.load()
|
GAME.curMode.load(playerData)
|
||||||
initPlayerPosition(args:find("q"))
|
initPlayerPosition(args:find("q"))
|
||||||
restoreVirtualKey()
|
restoreVirtualKey()
|
||||||
if GAME.modeEnv.task then
|
if GAME.modeEnv.task then
|
||||||
@@ -685,19 +696,11 @@ function dumpRecording(list,ptr)
|
|||||||
return out..buffer
|
return out..buffer
|
||||||
end
|
end
|
||||||
function pumpRecording(str,L)
|
function pumpRecording(str,L)
|
||||||
-- str=data.decode("string","base64",str)
|
str=data.decode("string","base64",str)
|
||||||
local len=#str
|
local len=#str
|
||||||
local p=1
|
local p=1
|
||||||
|
|
||||||
local list,curFrm
|
local curFrm=L[#L-1]or 0
|
||||||
if L then
|
|
||||||
list=L
|
|
||||||
curFrm=L[#L-1]or 0
|
|
||||||
else
|
|
||||||
list={}
|
|
||||||
curFrm=0
|
|
||||||
end
|
|
||||||
|
|
||||||
while p<=len do
|
while p<=len do
|
||||||
--Read delta time
|
--Read delta time
|
||||||
::nextByte::
|
::nextByte::
|
||||||
@@ -708,17 +711,16 @@ function pumpRecording(str,L)
|
|||||||
goto nextByte
|
goto nextByte
|
||||||
end
|
end
|
||||||
curFrm=curFrm+b
|
curFrm=curFrm+b
|
||||||
list[#list+1]=curFrm
|
L[#L+1]=curFrm
|
||||||
p=p+1
|
p=p+1
|
||||||
|
|
||||||
b=byte(str,p)
|
b=byte(str,p)
|
||||||
if b>127 then
|
if b>127 then
|
||||||
b=b-256
|
b=b-256
|
||||||
end
|
end
|
||||||
list[#list+1]=b
|
L[#L+1]=b
|
||||||
p=p+1
|
p=p+1
|
||||||
end
|
end
|
||||||
return list
|
|
||||||
end
|
end
|
||||||
do--function saveRecording()
|
do--function saveRecording()
|
||||||
local noRecList={"custom","solo","round","techmino"}
|
local noRecList={"custom","solo","round","techmino"}
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ CUSTOMENV={--gameEnv for cutsom game
|
|||||||
}
|
}
|
||||||
GAME={--Global game data
|
GAME={--Global game data
|
||||||
init=false, --If need initializing game when enter scene-play
|
init=false, --If need initializing game when enter scene-play
|
||||||
|
net=false, --If play net game
|
||||||
|
|
||||||
frame=0, --Frame count
|
frame=0, --Frame count
|
||||||
result=false, --Game result (string)
|
result=false, --Game result (string)
|
||||||
|
|||||||
@@ -105,4 +105,6 @@ return{
|
|||||||
|
|
||||||
{name="custom_puzzle"},
|
{name="custom_puzzle"},
|
||||||
{name="custom_clear"},
|
{name="custom_clear"},
|
||||||
|
|
||||||
|
{name="netBattle"},
|
||||||
}
|
}
|
||||||
16
parts/modes/netBattle.lua
Normal file
16
parts/modes/netBattle.lua
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
return{
|
||||||
|
color=COLOR.white,
|
||||||
|
env={
|
||||||
|
--TODO: ?
|
||||||
|
},
|
||||||
|
load=function(playerData)
|
||||||
|
PLY.newPlayer(1)
|
||||||
|
local N=2
|
||||||
|
for i=1,#playerData do
|
||||||
|
if playerData[i].id~=USER.id then
|
||||||
|
PLY.newRemotePlayer(N,false,playerData[i])
|
||||||
|
N=N+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
@@ -332,10 +332,12 @@ function PLY.newDemoPlayer(id)
|
|||||||
}
|
}
|
||||||
P:popNext()
|
P:popNext()
|
||||||
end
|
end
|
||||||
function PLY.newRemotePlayer(id,mini)
|
function PLY.newRemotePlayer(id,mini,userInfo)
|
||||||
local P=newEmptyPlayer(id,mini)
|
local P=newEmptyPlayer(id,mini)
|
||||||
P.type="remote"
|
P.type="remote"
|
||||||
P.update=PLY.update.remote_alive
|
P.update=PLY.update.remote_alive
|
||||||
|
P.userName=userInfo.name
|
||||||
|
P.userID=userInfo.id
|
||||||
P.stream={}
|
P.stream={}
|
||||||
P.streamProgress=1
|
P.streamProgress=1
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ local gc=love.graphics
|
|||||||
local gc_setColor,gc_circle=gc.setColor,gc.circle
|
local gc_setColor,gc_circle=gc.setColor,gc.circle
|
||||||
local tc=love.touch
|
local tc=love.touch
|
||||||
|
|
||||||
|
local playerData
|
||||||
|
local ins,rem=table.insert,table.remove
|
||||||
local max,sin=math.max,math.sin
|
local max,sin=math.max,math.sin
|
||||||
|
|
||||||
local SCR=SCR
|
local SCR=SCR
|
||||||
@@ -22,19 +24,29 @@ local function onVirtualkey(x,y)
|
|||||||
return nearest
|
return nearest
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local hideChatBox=false
|
||||||
|
local textBox=WIDGET.newTextBox{name="texts",x=980,y=20,w=290,h=300,hide=function()return hideChatBox end}
|
||||||
|
|
||||||
|
local playing
|
||||||
local lastBackTime=0
|
local lastBackTime=0
|
||||||
local noTouch=false
|
local noTouch,noKey=false,false
|
||||||
local touchMoveLastFrame=false
|
local touchMoveLastFrame=false
|
||||||
|
|
||||||
local scene={}
|
local scene={}
|
||||||
|
|
||||||
|
function scene.sceneBack()
|
||||||
|
wsWrite("Q")
|
||||||
|
WSCONN=false
|
||||||
|
LOG.print(text.wsDisconnected,"warn")
|
||||||
|
end
|
||||||
function scene.sceneInit()
|
function scene.sceneInit()
|
||||||
love.keyboard.setKeyRepeat(false)
|
love.keyboard.setKeyRepeat(false)
|
||||||
if GAME.init then
|
TASK.new(TICK_wsRead)
|
||||||
resetGameData()
|
textBox:clear()
|
||||||
GAME.init=false
|
|
||||||
end
|
playerData={}
|
||||||
noTouch=not SETTING.VKSwitch
|
noTouch=not SETTING.VKSwitch
|
||||||
|
playing=false
|
||||||
end
|
end
|
||||||
|
|
||||||
function scene.touchDown(_,x,y)
|
function scene.touchDown(_,x,y)
|
||||||
@@ -102,54 +114,119 @@ end
|
|||||||
function scene.keyDown(key)
|
function scene.keyDown(key)
|
||||||
if key=="escape"then
|
if key=="escape"then
|
||||||
if TIME()-lastBackTime<1 then
|
if TIME()-lastBackTime<1 then
|
||||||
WSCONN=false
|
|
||||||
SCN.back()
|
SCN.back()
|
||||||
else
|
else
|
||||||
lastBackTime=TIME()
|
lastBackTime=TIME()
|
||||||
|
LOG.print(text.sureQuit,COLOR.orange)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local m=keyMap
|
if noKey then return end
|
||||||
for k=1,20 do
|
local k=keyMap.keyboard[key]
|
||||||
if key==m[1][k]or key==m[2][k]then
|
if k and k>0 then
|
||||||
PLAYERS[1]:pressKey(k)
|
PLAYERS[1]:pressKey(k)
|
||||||
VK[k].isDown=true
|
VK[k].isDown=true
|
||||||
VK[k].pressTime=10
|
VK[k].pressTime=10
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scene.keyUp(key)
|
function scene.keyUp(key)
|
||||||
local m=keyMap
|
if noKey then return end
|
||||||
for k=1,20 do
|
local k=keyMap.keyboard[key]
|
||||||
if key==m[1][k]or key==m[2][k]then
|
if k and k>0 then
|
||||||
PLAYERS[1]:releaseKey(k)
|
PLAYERS[1]:releaseKey(k)
|
||||||
VK[k].isDown=false
|
VK[k].isDown=false
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scene.gamepadDown(key)
|
function scene.gamepadDown(key)
|
||||||
local m=keyMap
|
if key=="back"then
|
||||||
for k=1,20 do
|
if TIME()-lastBackTime<1 then
|
||||||
if key==m[3][k]or key==m[4][k]then
|
WSCONN=false
|
||||||
|
SCN.back()
|
||||||
|
else
|
||||||
|
lastBackTime=TIME()
|
||||||
|
LOG.print(text.sureQuit,COLOR.orange)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if noKey then return end
|
||||||
|
local k=keyMap.joystick[key]
|
||||||
|
if k and k>0 then
|
||||||
PLAYERS[1]:pressKey(k)
|
PLAYERS[1]:pressKey(k)
|
||||||
VK[k].isDown=true
|
VK[k].isDown=true
|
||||||
VK[k].pressTime=10
|
VK[k].pressTime=10
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if key=="back"then pauseGame()end
|
|
||||||
end
|
end
|
||||||
function scene.gamepadUp(key)
|
function scene.gamepadUp(key)
|
||||||
local m=keyMap
|
if noKey then return end
|
||||||
for k=1,20 do
|
local k=keyMap.joystick[key]
|
||||||
if key==m[3][k]or key==m[4][k]then
|
if k and k>0 then
|
||||||
PLAYERS[1]:releaseKey(k)
|
PLAYERS[1]:releaseKey(k)
|
||||||
VK[k].isDown=false
|
VK[k].isDown=false
|
||||||
return
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function scene.socketRead(mes)
|
||||||
|
local cmd=mes:sub(1,1)
|
||||||
|
local args=splitStr(mes:sub(2),":")
|
||||||
|
LOG.print(cmd,table.concat(args, " ; "))-------DEBUG PRINT
|
||||||
|
if cmd=="J"or cmd=="L"then
|
||||||
|
textBox:push{
|
||||||
|
COLOR.lR,args[1],
|
||||||
|
COLOR.dY,args[2].." ",
|
||||||
|
COLOR.Y,text[cmd=="J"and"chatJoin"or"chatLeave"]
|
||||||
|
}
|
||||||
|
if cmd=="J"then
|
||||||
|
ins(playerData,{name=args[1],id=args[2],conf=false})
|
||||||
|
if not playing then
|
||||||
|
resetGameData("n",playerData)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for i=1,#playerData do
|
||||||
|
if playerData[i].id==args[2]then
|
||||||
|
rem(playerData,i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i=1,#PLAYERS do
|
||||||
|
if PLAYERS[i].userID==args[2]then
|
||||||
|
rem(PLAYERS,i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i=1,#PLAYERS.alive do
|
||||||
|
if PLAYERS.alive[i].userID==args[2]then
|
||||||
|
rem(PLAYERS,i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
elseif cmd=="T"then
|
||||||
|
textBox:push{
|
||||||
|
COLOR.W,args[1],
|
||||||
|
COLOR.dY,args[2].." ",
|
||||||
|
COLOR.sky,args[3]
|
||||||
|
}
|
||||||
|
elseif cmd=="C"then
|
||||||
|
for i=1,#playerData do
|
||||||
|
if playerData[i].id==args[1]then
|
||||||
|
playerData[i].conf=args[2]
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif cmd=="S"then
|
||||||
|
for _,P in next,PLAYERS do
|
||||||
|
if P.userID==args[1]then
|
||||||
|
pumpRecording(args[2],P.stream)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif cmd=="B"then
|
||||||
|
playing=true
|
||||||
|
resetGameData("n",playerData)
|
||||||
|
elseif cmd=="F"then
|
||||||
|
playing=false
|
||||||
|
else
|
||||||
|
LOG.print("Illegal message: ["..mes.."]",30,COLOR.green)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -157,7 +234,6 @@ function scene.update(dt)
|
|||||||
local _
|
local _
|
||||||
local P1=PLAYERS[1]
|
local P1=PLAYERS[1]
|
||||||
local GAME=GAME
|
local GAME=GAME
|
||||||
GAME.frame=GAME.frame+1
|
|
||||||
|
|
||||||
touchMoveLastFrame=false
|
touchMoveLastFrame=false
|
||||||
|
|
||||||
@@ -171,26 +247,10 @@ function scene.update(dt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--Replay
|
if not playing then return end
|
||||||
if GAME.replaying then
|
|
||||||
_=GAME.replaying
|
|
||||||
local L=GAME.rep
|
|
||||||
while GAME.frame==L[_]do
|
|
||||||
local k=L[_+1]
|
|
||||||
if k>0 then
|
|
||||||
P1:pressKey(k)
|
|
||||||
VK[k].isDown=true
|
|
||||||
VK[k].pressTime=10
|
|
||||||
else
|
|
||||||
VK[-k].isDown=false
|
|
||||||
P1:releaseKey(-k)
|
|
||||||
end
|
|
||||||
_=_+2
|
|
||||||
end
|
|
||||||
GAME.replaying=_
|
|
||||||
end
|
|
||||||
|
|
||||||
--Counting,include pre-das,directy RETURN,or restart counting
|
--Counting,include pre-das,directy RETURN,or restart counting
|
||||||
|
GAME.frame=GAME.frame+1
|
||||||
if GAME.frame<180 then
|
if GAME.frame<180 then
|
||||||
if GAME.frame==179 then
|
if GAME.frame==179 then
|
||||||
gameStart()
|
gameStart()
|
||||||
@@ -297,11 +357,6 @@ function scene.draw()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--Mode info
|
|
||||||
gc_setColor(1,1,1,.8)
|
|
||||||
gc.draw(drawableText.modeName,485,10)
|
|
||||||
gc.draw(drawableText.levelName,511+drawableText.modeName:getWidth(),10)
|
|
||||||
|
|
||||||
--Warning
|
--Warning
|
||||||
gc.push("transform")
|
gc.push("transform")
|
||||||
gc.origin()
|
gc.origin()
|
||||||
@@ -314,7 +369,9 @@ function scene.draw()
|
|||||||
gc.pop()
|
gc.pop()
|
||||||
end
|
end
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
WIDGET.newKey{name="quit",x=1235,y=45,w=80,font=20,code=pressKey"escape"},
|
textBox,
|
||||||
|
WIDGET.newKey{name="hideChat",fText="[..]",x=410,y=40,w=60,font=35,code=function()hideChatBox=not hideChatBox end},
|
||||||
|
WIDGET.newKey{name="quit",fText="X",x=870,y=40,w=60,font=40,code=pressKey"escape"},
|
||||||
}
|
}
|
||||||
|
|
||||||
return scene
|
return scene
|
||||||
@@ -38,8 +38,7 @@ local function task_enterRoom(task)
|
|||||||
local wsconn,connErr=client.poll(task)
|
local wsconn,connErr=client.poll(task)
|
||||||
if wsconn then
|
if wsconn then
|
||||||
WSCONN=wsconn
|
WSCONN=wsconn
|
||||||
SCN.go("net_game")
|
loadGame("netBattle",true,true)
|
||||||
loadGame("sprint_40l")
|
|
||||||
LOG.print(text.wsSuccessed,"warn")
|
LOG.print(text.wsSuccessed,"warn")
|
||||||
return
|
return
|
||||||
elseif connErr then
|
elseif connErr then
|
||||||
@@ -103,6 +102,10 @@ function scene.keyDown(k)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif k=="return"then
|
elseif k=="return"then
|
||||||
|
if rooms[selected].private then
|
||||||
|
LOG.print("Can't enter private room now")
|
||||||
|
return
|
||||||
|
end
|
||||||
wsConnect(
|
wsConnect(
|
||||||
task_enterRoom,
|
task_enterRoom,
|
||||||
PATH.socket..PATH.play_room..
|
PATH.socket..PATH.play_room..
|
||||||
|
|||||||
Reference in New Issue
Block a user