整理代码,网战和普通游戏复用几个函数
This commit is contained in:
@@ -132,10 +132,10 @@ local swap={
|
|||||||
}--Scene swapping animations
|
}--Scene swapping animations
|
||||||
function SCN.swapTo(tar,style)--Parallel scene swapping, cannot back
|
function SCN.swapTo(tar,style)--Parallel scene swapping, cannot back
|
||||||
if scenes[tar]then
|
if scenes[tar]then
|
||||||
local S=SCN.stat
|
|
||||||
if not SCN.swapping and tar~=SCN.cur then
|
if not SCN.swapping and tar~=SCN.cur then
|
||||||
if not style then style="fade"end
|
if not style then style="fade"end
|
||||||
SCN.swapping=true
|
SCN.swapping=true
|
||||||
|
local S=SCN.stat
|
||||||
S.tar,S.style=tar,style
|
S.tar,S.style=tar,style
|
||||||
S.time,S.mid,S.draw=unpack(swap[style])
|
S.time,S.mid,S.draw=unpack(swap[style])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ local fs=love.filesystem
|
|||||||
local gc=love.graphics
|
local gc=love.graphics
|
||||||
local gc_setColor,gc_circle=gc.setColor,gc.circle
|
local gc_setColor,gc_circle=gc.setColor,gc.circle
|
||||||
|
|
||||||
local int,rnd=math.floor,math.random
|
local max,int,rnd=math.max,math.floor,math.random
|
||||||
local sub=string.sub
|
local sub=string.sub
|
||||||
local char,byte=string.char,string.byte
|
local char,byte=string.char,string.byte
|
||||||
local ins,rem=table.insert,table.remove
|
local ins,rem=table.insert,table.remove
|
||||||
@@ -772,6 +772,58 @@ function gameStart()--Call when countdown finish (GAME.frame==180)
|
|||||||
P:popNext()
|
P:popNext()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function checkStart()
|
||||||
|
if GAME.frame<=180 then
|
||||||
|
if GAME.frame==180 then
|
||||||
|
gameStart()
|
||||||
|
elseif GAME.frame==60 or GAME.frame==120 then
|
||||||
|
SFX.play("ready")
|
||||||
|
end
|
||||||
|
for p=1,#PLAYERS do
|
||||||
|
local P=PLAYERS[p]
|
||||||
|
if P.movDir~=0 then
|
||||||
|
if P.moving<P.gameEnv.das then
|
||||||
|
P.moving=P.moving+1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
P.moving=0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function checkWarning()
|
||||||
|
local P1=PLAYERS[1]
|
||||||
|
if P1.alive then
|
||||||
|
if GAME.frame%26==0 and SETTING.warn then
|
||||||
|
local F=P1.field
|
||||||
|
local height=0--Max height of row 4~7
|
||||||
|
for x=4,7 do
|
||||||
|
for y=#F,1,-1 do
|
||||||
|
if F[y][x]>0 then
|
||||||
|
if y>height then
|
||||||
|
height=y
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
GAME.warnLVL0=math.log(height-15+P1.atkBuffer.sum*.8)
|
||||||
|
end
|
||||||
|
_=GAME.warnLVL
|
||||||
|
if _<GAME.warnLVL0 then
|
||||||
|
_=_*.95+GAME.warnLVL0*.05
|
||||||
|
elseif _>0 then
|
||||||
|
_=max(_-.026,0)
|
||||||
|
end
|
||||||
|
GAME.warnLVL=_
|
||||||
|
elseif GAME.warnLVL>0 then
|
||||||
|
GAME.warnLVL=max(GAME.warnLVL-.026,0)
|
||||||
|
end
|
||||||
|
if GAME.warnLVL>1.126 and GAME.frame%30==0 then
|
||||||
|
SFX.fplay("warning",SETTING.sfx_warn)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Table data format:
|
Table data format:
|
||||||
@@ -1033,10 +1085,11 @@ function TICK_wsRead()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
elseif readErr then
|
elseif readErr then
|
||||||
wsWrite("/quit")
|
|
||||||
WSCONN=false
|
WSCONN=false
|
||||||
LOG.print(text.wsError..tostring(readErr),"warn")
|
LOG.print(text.wsError..tostring(readErr),"warn")
|
||||||
SCN.back()
|
while #SCN.stack>4 do
|
||||||
|
SCN.pop()
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ local tc=love.touch
|
|||||||
|
|
||||||
local playerData
|
local playerData
|
||||||
local ins,rem=table.insert,table.remove
|
local ins,rem=table.insert,table.remove
|
||||||
local max,sin=math.max,math.sin
|
local sin=math.sin
|
||||||
|
|
||||||
local SCR=SCR
|
local SCR=SCR
|
||||||
local VK=virtualkey
|
local VK=virtualkey
|
||||||
@@ -261,14 +261,8 @@ end
|
|||||||
|
|
||||||
function scene.update(dt)
|
function scene.update(dt)
|
||||||
local _
|
local _
|
||||||
local P1=PLAYERS[1]
|
|
||||||
local GAME=GAME
|
local GAME=GAME
|
||||||
|
|
||||||
touchMoveLastFrame=false
|
|
||||||
|
|
||||||
--Update virtualkey animation
|
|
||||||
updateVirtualkey()
|
|
||||||
|
|
||||||
if not playing then
|
if not playing then
|
||||||
heartBeatTimer=heartBeatTimer+dt
|
heartBeatTimer=heartBeatTimer+dt
|
||||||
if heartBeatTimer>42 then
|
if heartBeatTimer>42 then
|
||||||
@@ -278,9 +272,11 @@ function scene.update(dt)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
GAME.frame=GAME.frame+1
|
touchMoveLastFrame=false
|
||||||
|
updateVirtualkey()
|
||||||
|
|
||||||
if GAME.frame-lastUpstreamTime>10 then
|
GAME.frame=GAME.frame+1
|
||||||
|
if GAME.frame-lastUpstreamTime>8 then
|
||||||
local stream
|
local stream
|
||||||
stream,upstreamProgress=dumpRecording(GAME.rep,upstreamProgress)
|
stream,upstreamProgress=dumpRecording(GAME.rep,upstreamProgress)
|
||||||
if #stream>0 then
|
if #stream>0 then
|
||||||
@@ -289,25 +285,8 @@ function scene.update(dt)
|
|||||||
lastUpstreamTime=PLAYERS[1].alive and GAME.frame or 1e99
|
lastUpstreamTime=PLAYERS[1].alive and GAME.frame or 1e99
|
||||||
end
|
end
|
||||||
|
|
||||||
--Counting,include pre-das,directy RETURN,or restart counting
|
--Counting, include pre-das
|
||||||
if GAME.frame<180 then
|
if checkStart()then return end
|
||||||
if GAME.frame==179 then
|
|
||||||
gameStart()
|
|
||||||
elseif GAME.frame==60 or GAME.frame==120 then
|
|
||||||
SFX.play("ready")
|
|
||||||
end
|
|
||||||
for p=1,#PLAYERS do
|
|
||||||
local P=PLAYERS[p]
|
|
||||||
if P.movDir~=0 then
|
|
||||||
if P.moving<P.gameEnv.das then
|
|
||||||
P.moving=P.moving+1
|
|
||||||
end
|
|
||||||
else
|
|
||||||
P.moving=0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
--Update players
|
--Update players
|
||||||
for p=1,#PLAYERS do
|
for p=1,#PLAYERS do
|
||||||
@@ -315,35 +294,7 @@ function scene.update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Warning check
|
--Warning check
|
||||||
if P1.alive then
|
checkWarning()
|
||||||
if GAME.frame%26==0 and SETTING.warn then
|
|
||||||
local F=P1.field
|
|
||||||
local height=0--Max height of row 4~7
|
|
||||||
for x=4,7 do
|
|
||||||
for y=#F,1,-1 do
|
|
||||||
if F[y][x]>0 then
|
|
||||||
if y>height then
|
|
||||||
height=y
|
|
||||||
end
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
GAME.warnLVL0=math.log(height-15+P1.atkBuffer.sum*.8)
|
|
||||||
end
|
|
||||||
_=GAME.warnLVL
|
|
||||||
if _<GAME.warnLVL0 then
|
|
||||||
_=_*.95+GAME.warnLVL0*.05
|
|
||||||
elseif _>0 then
|
|
||||||
_=max(_-.026,0)
|
|
||||||
end
|
|
||||||
GAME.warnLVL=_
|
|
||||||
elseif GAME.warnLVL>0 then
|
|
||||||
GAME.warnLVL=max(GAME.warnLVL-.026,0)
|
|
||||||
end
|
|
||||||
if GAME.warnLVL>1.126 and GAME.frame%30==0 then
|
|
||||||
SFX.fplay("warning",SETTING.sfx_warn)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function scene.draw()
|
function scene.draw()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local gc=love.graphics
|
|||||||
local gc_setColor=gc.setColor
|
local gc_setColor=gc.setColor
|
||||||
local tc=love.touch
|
local tc=love.touch
|
||||||
|
|
||||||
local max,sin=math.max,math.sin
|
local sin=math.sin
|
||||||
|
|
||||||
local SCR=SCR
|
local SCR=SCR
|
||||||
local VK=virtualkey
|
local VK=virtualkey
|
||||||
@@ -127,12 +127,10 @@ 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
|
||||||
|
|
||||||
--Update virtualkey animation
|
|
||||||
updateVirtualkey()
|
updateVirtualkey()
|
||||||
|
GAME.frame=GAME.frame+1
|
||||||
|
|
||||||
--Replay
|
--Replay
|
||||||
if GAME.replaying then
|
if GAME.replaying then
|
||||||
@@ -153,25 +151,8 @@ function scene.update(dt)
|
|||||||
GAME.replaying=_
|
GAME.replaying=_
|
||||||
end
|
end
|
||||||
|
|
||||||
--Counting,include pre-das,directy RETURN,or restart counting
|
--Counting, include pre-das
|
||||||
if GAME.frame<=180 then
|
if checkStart()then return end
|
||||||
if GAME.frame==180 then
|
|
||||||
gameStart()
|
|
||||||
elseif GAME.frame==60 or GAME.frame==120 then
|
|
||||||
SFX.play("ready")
|
|
||||||
end
|
|
||||||
for p=1,#PLAYERS do
|
|
||||||
local P=PLAYERS[p]
|
|
||||||
if P.movDir~=0 then
|
|
||||||
if P.moving<P.gameEnv.das then
|
|
||||||
P.moving=P.moving+1
|
|
||||||
end
|
|
||||||
else
|
|
||||||
P.moving=0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
--Update players
|
--Update players
|
||||||
for p=1,#PLAYERS do
|
for p=1,#PLAYERS do
|
||||||
@@ -184,35 +165,7 @@ function scene.update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Warning check
|
--Warning check
|
||||||
if P1.alive then
|
checkWarning()
|
||||||
if GAME.frame%26==0 and SETTING.warn then
|
|
||||||
local F=P1.field
|
|
||||||
local height=0--Max height of row 4~7
|
|
||||||
for x=4,7 do
|
|
||||||
for y=#F,1,-1 do
|
|
||||||
if F[y][x]>0 then
|
|
||||||
if y>height then
|
|
||||||
height=y
|
|
||||||
end
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
GAME.warnLVL0=math.log(height-15+P1.atkBuffer.sum*.8)
|
|
||||||
end
|
|
||||||
_=GAME.warnLVL
|
|
||||||
if _<GAME.warnLVL0 then
|
|
||||||
_=_*.95+GAME.warnLVL0*.05
|
|
||||||
elseif _>0 then
|
|
||||||
_=max(_-.026,0)
|
|
||||||
end
|
|
||||||
GAME.warnLVL=_
|
|
||||||
elseif GAME.warnLVL>0 then
|
|
||||||
GAME.warnLVL=max(GAME.warnLVL-.026,0)
|
|
||||||
end
|
|
||||||
if GAME.warnLVL>1.126 and GAME.frame%30==0 then
|
|
||||||
SFX.fplay("warning",SETTING.sfx_warn)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drawAtkPointer(x,y)
|
local function drawAtkPointer(x,y)
|
||||||
|
|||||||
Reference in New Issue
Block a user