Files
Techmino/timer.lua
MrZ_26 b8f57f5a1c 0.8.9
2020-02-19 17:41:23 +08:00

287 lines
6.7 KiB
Lua

local wd=love.window
local gc=love.graphics
local kb=love.keyboard
local Timer=love.timer.getTime
local int,abs,rnd,max,min,sin=math.floor,math.abs,math.random,math.max,math.min,math.sin
local ins,rem=table.insert,table.remove
local Tmr={}
function Tmr.load()
local t=Timer()
local L=loading
::R::
--L={stage,curPos,curLen}
if L[1]==1 then
local N=voiceName[L[2]]
for i=1,#voiceList[N]do
local V=voiceList[N][i]
voiceBank[V]={love.audio.newSource("VOICE/"..V..".ogg","static")}
end
L[2]=L[2]+1
if L[2]>L[3]then
L[1],L[2],L[3]=2,1,#bgm
end
elseif L[1]==2 then
local N=bgm[L[2]]
bgm[N]=love.audio.newSource("/BGM/"..N..".ogg","stream")
bgm[N]:setLooping(true)
bgm[N]:setVolume(0)
L[2]=L[2]+1
if L[2]>L[3]then
for i=1,L[3]do bgm[i]=nil end
L[1],L[2],L[3]=3,1,#sfx
end
elseif L[1]==3 then
local S=sfx[L[2]]
sfx[S]={love.audio.newSource("/SFX/"..S..".ogg","static")}
L[2]=L[2]+1
if L[2]>L[3]then
for i=1,L[3]do sfx[i]=nil end
L[1],L[2],L[3]=4,1,#modes
end
elseif L[1]==4 then
local m=modes[L[2]]
modes[L[2]]=require("modes/"..m[1])
local M=modes[L[2]]
M.saveFileName,M.id=m[1],m.id
M.x,M.y,M.size,M.shape=m.x,m.y,m.size,m.shape
M.unlock=m.unlock
M.records=loadRecord(m[1])or M.score and{}
-- M.icon=gc.newImage("image/modeIcon/"..m.icon..".png")
-- M.icon=gc.newImage("image/modeIcon/custom.png")
L[2]=L[2]+1
if L[2]>L[3]then
L[1],L[2],L[3]=5,1,1
end
elseif L[1]==5 then
--------------------------Loading some other things here?
local N=gc.newImage
titleImage=N("/image/mess/title.png")
coloredTitleImage=N("/image/mess/title_colored.png")
dialCircle=N("/image/mess/dialCircle.png")
dialNeedle=N("/image/mess/dialNeedle.png")
badgeIcon=N("/image/mess/badge.png")
spinCenter=N("/image/mess/spinCenter.png")
ctrlSpeedLimit=N("/image/mess/ctrlSpeedLimit.png")
speedLimit=N("/image/mess/speedLimit.png")
background1=N("/image/BG/bg1.png")
background2=N("/image/BG/bg2.png")
groupCode=N("/image/mess/groupcode.png")
payCode=N("/image/mess/paycode.png")
miya={
ch=N("/image/miya/ch.png"),
f1=N("/image/miya/f1.png"),
f2=N("/image/miya/f2.png"),
f3=N("/image/miya/f3.png"),
f4=N("/image/miya/f4.png"),
}
--------------------------
L[1],L[2],L[3]=0,1,1
SFX("welcome",.2)
else
L[2]=L[2]+1
L[3]=L[2]
if L[2]>50 then
stat.run=stat.run+1
scene.swapTo("intro","none")
end
end
end
function Tmr.intro()
sceneTemp=sceneTemp+1
if sceneTemp==200 then sceneTemp=80 end
end
function Tmr.main(dt)
players[1]:update(dt)
end
local function dumpTable(L)
local s="{\n"
for k,v in next,L do
local T
T=type(k)
if T=="number"then k="["..k.."]="
elseif T=="string"then k=k.."="
else error("Error data type!")
end
T=type(v)
if T=="number"then v=tostring(v)
elseif T=="string"then v="\""..v.."\""
elseif T=="table"then v=dumpTable(v)
else error("Error data type!")
end
s=s..k..v..",\n"
end
return s.."}"
end
function Tmr.mode(dt)
local cam=mapCam
local F
local x,y,k=cam.x,cam.y,cam.k
if kb.isDown("up", "w")then y=y-10*k;F=true end
if kb.isDown("down","s")then y=y+10*k;F=true end
if kb.isDown("left","a")then x=x-10*k;F=true end
if kb.isDown("right","d")then x=x+10*k;F=true end
local js1=joysticks[1]
if js1 then
local k=js1:getAxis(1)
if k~="c"then
if k=="u"or k=="ul"or k=="ur"then y=y-10*k;F=true end
if k=="d"or k=="dl"or k=="dl"then y=y+10*k;F=true end
if k=="l"or k=="ul"or k=="dl"then x=x-10*k;F=true end
if k=="r"or k=="ur"or k=="dr"then x=x+10*k;F=true end
end
end
if F or cam.keyCtrl and(x-cam.x1)^2+(y-cam.y1)^2>2.6 then
if F then
cam.keyCtrl=true
end
local x,y=(cam.x1-180)/cam.k1,cam.y1/cam.k1
local MM,R=modes,modeRanks
for _=1,#MM do
if R[_]then
local __
local M=MM[_]
local s=M.size
if M.shape==1 then
if x>M.x-s and x<M.x+s and y>M.y-s and y<M.y+s then __=_ end
elseif M.shape==2 then
if abs(x-M.x)+abs(y-M.y)<s then __=_ end
elseif M.shape==3 then
if(x-M.x)^2+(y-M.y)^2<s^2 then __=_ end
end
if __ and cam.sel~=__ then
cam.sel=__
SFX("click")
end
end
end
end
if x>1400*k then x=1400*k
elseif x<-1300*k then x=-1300*k
end
if y>500*k then y=500*k
elseif y<-1900*k then y=-1900*k
end
cam.x,cam.y=x,y
--keyboard controlling
if setting.bgspace then
space.scale(.85+k/cam.k1*.15)
space.translate((cam.x1/cam.k1-cam.x/k)*.03*k,(cam.y1/cam.k1-cam.y/k)*.03*k)
end
cam.x1=cam.x1*.85+x*.15
cam.y1=cam.y1*.85+y*.15
cam.k1=cam.k1*.85+k*.15
local _=scene.swap.tar
cam.zoomMethod=_=="play"and 1 or _=="mode"and 2
if cam.zoomMethod==1 then
if cam.sel then
local M=modes[cam.sel]
cam.x=cam.x*.8+M.x*cam.k*.2
cam.y=cam.y*.8+M.y*cam.k*.2
end
_=cam.zoomK
if _<.8 then _=_*1.05 end
if _<1.1 then _=_*1.05 end
cam.zoomK=_*1.05
elseif cam.zoomMethod==2 then
cam.zoomK=cam.zoomK^.9
end
end
function Tmr.draw()
if sceneTemp.sure>0 then sceneTemp.sure=sceneTemp.sure-1 end
end
function Tmr.play(dt)
frame=frame+1
stat.time=stat.time+dt
for i=#FX_attack,1,-1 do
local b=FX_attack[i]
b.t=b.t+1
if b.t>50 then
b.rad=b.rad*1.05+.1
b.x,b.y=b.x2,b.y2
elseif b.t>10 then
local t=((b.t-10)*.025)t=(3-2*t)*t*t
b.x,b.y=b.x1*(1-t)+b.x2*t,b.y1*(1-t)+b.y2*t
end
if b.t<60 then
local L=FX_attack[i].drag
if #L==4*setting.atkFX then
rem(L,1)rem(L,1)
end
ins(L,b.x)ins(L,b.y)
else
for i=i,#FX_attack do
FX_attack[i]=FX_attack[i+1]
end
end
end
for i=#FX_badge,1,-1 do
local b=FX_badge[i]
b.t=b.t+1
if b.t==60 then
rem(FX_badge,i)
end
end
for i=1,#virtualkey do
if virtualkeyPressTime[i]>0 then
virtualkeyPressTime[i]=virtualkeyPressTime[i]-1
end
end
if frame<180 then
if frame==179 then
gameStart()
elseif frame==60 or frame==120 then
SFX("ready")
end
for p=1,#players do
local P=players[p]
if P.keyPressing[1]then
if P.moving>0 then P.moving=0 end
P.moving=P.moving-1
elseif P.keyPressing[2]then
if P.moving<0 then P.moving=0 end
P.moving=P.moving+1
else
P.moving=0
end
end
if restartCount>0 then restartCount=restartCount-1 end
return
elseif players[1].keyPressing[10]then
restartCount=restartCount+1
if restartCount>20 then
clearTask("play")
updateStat()
resetGameData()
return
end
elseif restartCount>0 then
restartCount=restartCount>2 and restartCount-2 or 0
end--Counting,include pre-das,directy RETURN,or restart counting
for p=1,#players do
local P=players[p]
P:update(dt)
end
if modeEnv.royaleMode and frame%120==0 then freshMostDangerous()end
end
function Tmr.pause(dt)
if not gameResult then
pauseTime=pauseTime+dt
end
if pauseTimer<50 and not wd.isMinimized()then
pauseTimer=pauseTimer+1
end
end
function Tmr.setting_sound()
local t=sceneTemp.jump
if t>0 then
sceneTemp.jump=t-1
end
end
return Tmr