[Z-framework stand alone ready]

This commit is contained in:
MrZ_26
2020-07-05 14:46:02 +08:00
parent e1d92a166b
commit 40de030cae
20 changed files with 554 additions and 540 deletions

View File

@@ -192,7 +192,7 @@ local function getScore(field,cb,cy)
return score
end
-------------------------------------------------
AI_think={
return{
["9S"]={
function(P,ctrl)
local Tfield={}--test field

View File

@@ -1,5 +1,22 @@
local min=math.min
local rem=table.remove
local function fadeOut(_,id)
local src=BGM.list[id]
local v=src:getVolume()-.025*setting.bgm*.1
src:setVolume(v>0 and v or 0)
if v<=0 then
src:stop()
return true
end
end
local function fadeIn(_,id)
local src=BGM.list[id]
local v=min(src:getVolume()+.025*setting.bgm*.1,setting.bgm*.1)
src:setVolume(v)
if v>=setting.bgm*.1 then return true end
end
local BGM={
--nowPlay=[str:playing ID]
--suspend=[str:pausing ID]
@@ -36,12 +53,12 @@ function BGM.play(s)
return
end
if BGM.nowPlay~=s then
if BGM.nowPlay then TASK.new(tickEvent.bgmFadeOut,nil,BGM.nowPlay)end
TASK.changeCode(tickEvent.bgmFadeIn,tickEvent.bgmFadeOut)
if BGM.nowPlay then TASK.new(fadeOut,nil,BGM.nowPlay)end
TASK.changeCode(fadeIn,fadeOut)
TASK.removeTask_data(s)
BGM.nowPlay,BGM.suspend=s
TASK.new(tickEvent.bgmFadeIn,nil,s)
TASK.new(fadeIn,nil,s)
BGM.playing=BGM.list[s]
BGM.playing:play()
end
@@ -64,9 +81,9 @@ function BGM.freshVolume()
end
function BGM.stop()
if BGM.nowPlay then
TASK.new(tickEvent.bgmFadeOut,nil,BGM.nowPlay)
TASK.new(fadeOut,nil,BGM.nowPlay)
end
TASK.changeCode(tickEvent.bgmFadeIn,tickEvent.bgmFadeOut)
TASK.changeCode(fadeIn,fadeOut)
BGM.playing,BGM.nowPlay=nil
end
return BGM

304
parts/gametoolfunc.lua Normal file
View File

@@ -0,0 +1,304 @@
local tm,gc=love.timer,love.graphics
local kb,data=love.keyboard,love.data
local int,abs,rnd=math.floor,math.abs,math.random
local max,min=math.max,math.min
local sub,find=string.sub,string.find
local char,byte=string.char,string.byte
local ins,rem=table.insert,table.remove
function destroyPlayers()
for i=#players,1,-1 do
local P=players[i]
if P.canvas then P.canvas:release()end
while P.field[1]do
freeRow.discard(rem(P.field))
freeRow.discard(rem(P.visTime))
end
if P.AI_mode=="CC"then
BOT.free(P.bot_opt)
BOT.free(P.bot_wei)
BOT.destroy(P.AI_bot)
P.AI_mode=nil
end
players[i]=nil
end
for i=#players.alive,1,-1 do
players.alive[i]=nil
end
players.human=0
collectgarbage()
end
function restoreVirtualKey()
for i=1,#VK_org do
local B,O=virtualkey[i],VK_org[i]
B.ava=O.ava
B.x=O.x
B.y=O.y
B.r=O.r
B.isDown=false
B.pressTime=0
end
if not modeEnv.Fkey then
virtualkey[9].ava=false
end
end
function copyBoard()
local str=""
local H=0
for y=20,1,-1 do
for x=1,10 do
if preField[y][x]~=0 then
H=y
goto L
end
end
end
::L::
for y=1,H do
local S=""
local L=preField[y]
for x=1,10 do
S=S..char(L[x]+1)
end
str=str..S
end
love.system.setClipboardText("Techmino sketchpad:"..data.encode("string","base64",data.compress("string","deflate",str)))
TEXT.show(text.copySuccess,350,360,40,"appear",.5)
end
function pasteBoard()
local str=love.system.getClipboardText()
local fX,fY=1,1--*ptr for Field(r*10+(c-1))
local _,Bid
local p=find(str,":")--ptr*
if p then str=sub(str,p+1)end
_,str=pcall(data.decode,"string","base64",str)
if not _ then goto ERROR end
_,str=pcall(data.decompress,"string","deflate",str)
if not _ then goto ERROR end
p=1
while true do
_=byte(str,p)--1byte
if not _ then
if fX~=1 then goto ERROR
else break
end
end--str end
__=_%32-1--block id
if __>17 then goto ERROR end--illegal blockid
_=int(_/32)--mode id
preField[fY][fX]=__
if fX<10 then
fX=fX+1
else
if fY==20 then break end
fX=1;fY=fY+1
end
p=p+1
end
for y=fY+1,20 do
for x=1,10 do
preField[y][x]=0
end
end
do return end
::ERROR::TEXT.show(text.dataCorrupted,350,360,35,"flicker",.5)
end
function mergeStat(stat,delta)
for k,v in next,delta do
if type(v)=="table"then
mergeStat(stat[k],v)
else
stat[k]=stat[k]+v
end
end
end
function randomTarget(P)
if #players.alive>1 then
local R
repeat
R=players.alive[rnd(#players.alive)]
until R~=P
return R
end
end--return a random opponent for P
function freshMostDangerous()
game.mostDangerous,game.secDangerous=nil
local m,m2=0,0
for i=1,#players.alive do
local h=#players.alive[i].field
if h>=m then
game.mostDangerous,game.secDangerous=players.alive[i],game.mostDangerous
m,m2=h,m
elseif h>=m2 then
game.secDangerous=players.alive[i]
m2=h
end
end
end
function freshMostBadge()
game.mostBadge,game.secBadge=nil
local m,m2=0,0
for i=1,#players.alive do
local h=players.alive[i].badge
if h>=m then
game.mostBadge,game.secBadge=players.alive[i],game.mostBadge
m,m2=h,m
elseif h>=m2 then
game.secBadge=players.alive[i]
m2=h
end
end
end
function royaleLevelup()
game.stage=game.stage+1
local spd
TEXT.show(text.royale_remain(#players.alive),640,200,40,"beat",.3)
if game.stage==2 then
spd=30
elseif game.stage==3 then
spd=15
game.garbageSpeed=.6
if players[1].alive then BGM.play("cruelty")end
elseif game.stage==4 then
spd=10
local _=players.alive
for i=1,#_ do
_[i].gameEnv.pushSpeed=3
end
elseif game.stage==5 then
spd=5
game.garbageSpeed=1
elseif game.stage==6 then
spd=3
if players[1].alive then BGM.play("final")end
end
for i=1,#players.alive do
players.alive[i].gameEnv.drop=spd
end
if curMode.lv==3 then
for i=1,#players.alive do
local P=players.alive[i]
P.gameEnv.drop=int(P.gameEnv.drop*.3)
if P.gameEnv.drop==0 then
P.curY=P.y_img
P.gameEnv._20G=true
if P.AI_mode=="CC"then CC_switch20G(P)end--little cheating,never mind
end
end
end
end
function pauseGame()
if not SCN.swapping then
restartCount=0--Avoid strange darkness
if not game.result then
game.pauseCount=game.pauseCount+1
end
for i=1,#players do
local l=players[i].keyPressing
for j=1,#l do
if l[j]then
players[i]:releaseKey(j)
end
end
end
SCN.swapTo("pause","none")
end
end
function resumeGame()
SCN.swapTo("play","none")
end
function loadGame(M)
--rec={}
stat.lastPlay=M
curMode=Modes[M]
local lang=setting.lang
drawableText.modeName:set(text.modes[M][1])
drawableText.levelName:set(text.modes[M][2])
needResetGameData=true
SCN.swapTo("play","fade_togame")
SFX.play("enter")
end
function resetPartGameData()
game={
result=false,
pauseTime=0,
pauseCount=0,
garbageSpeed=1,
warnLVL0=0,
warnLVL=0,
}
frame=150-setting.reTime*15
destroyPlayers()
curMode.load()
TEXT.clear()
if modeEnv.task then
for i=1,#players do
players[i].newTask(modeEnv.task)
end
end
if modeEnv.royaleMode then
for i=1,#players do
players[i]:changeAtk(randomTarget(players[i]))
end
end
BG.set(modeEnv.bg)
BGM.play(modeEnv.bgm)
if modeEnv.royaleMode then
for i=1,#players do
players[i]:changeAtk(randomTarget(players[i]))
end
game.stage=1
game.garbageSpeed=.3
end
restoreVirtualKey()
collectgarbage()
end
function resetGameData()
game={
result=false,
pauseTime=0,--Time paused
pauseCount=0,--Pausing count
garbageSpeed=1,--garbage timing speed
warnLVL0=0,
warnLVL=0,
}
frame=150-setting.reTime*15
destroyPlayers()
modeEnv=curMode.env
curMode.load()--bg/bgm need redefine in custom,so up here
if modeEnv.task then
for i=1,#players do
players[i].newTask(modeEnv.task)
end
end
BG.set(modeEnv.bg)
BGM.play(modeEnv.bgm)
TEXT.clear()
FX_badge={}
FX_attack={}
if modeEnv.royaleMode then
for i=1,#players do
players[i]:changeAtk(randomTarget(players[i]))
end
game.stage=1
game.garbageSpeed=.3
end
restoreVirtualKey()
stat.game=stat.game+1
freeRow.reset(30*#players)
SFX.play("ready")
collectgarbage()
end
function gameStart()
SFX.play("start")
for P=1,#players do
P=players[P]
P:popNext()
P.timing=true
P.control=true
end
end

View File

@@ -44,6 +44,10 @@ if setting.lang==1 then
"jstris 也很好玩!",
"tetr.io 也很好玩!",
"nullpomino 也很好玩!",
"↑↑↓↓←→←→BABA",
"草(日本语)",
"dym,永远的神",
"iced,永远的神",
}
elseif setting.lang==2 then
L={
@@ -90,6 +94,10 @@ elseif setting.lang==2 then
"jstris 也很好玩!",
"tetr.io 也很好玩!",
"nullpomino 也很好玩!",
"↑↑↓↓←→←→BABA",
"草(日本语)",
"dym,永远的神",
"iced,永远的神",
}
elseif setting.lang==3 then
L={
@@ -137,6 +145,11 @@ elseif setting.lang==3 then
"Also try jstris!",
"Also try tetr.io!",
"Also try nullpomino!",
"↑↑↓↓←→←→BABA",
"wwwwww",
"diaoyoumei so bully",
"iced so bully",
"diao so bully",
}
elseif setting.lang==4 then
L={'!','@','#','$','%','^','&','*','(',')','-','=','_','+','[',']','{','}','\\','|',';',':','\'','"',',','<','.','>','/','?'}

View File

@@ -1749,7 +1749,7 @@ function LANG.getLen()
end
function LANG.set(l)
text=langList[l]
for S,L in next,widgetList do
for S,L in next,Widgets do
for N,W in next,L do
W.text=text.WidgetText[S][N]
end

View File

@@ -1,4 +1,4 @@
modes={
return{
{"sprint_10", id=1, x=0, y=0, size=35,shape=1,icon="sprint", unlock={2,3}},
{"sprint_20", id=2, x=-300, y=0, size=45,shape=1,icon="sprint", unlock={}},
{"sprint_40", id=3, x=0, y=-400, size=55,shape=1,icon="sprint", unlock={4,9,71,72,73}},
@@ -82,10 +82,4 @@ modes={
{"custom_clear", id=71, x=200, y=-350, size=45,shape=3,icon="custom", unlock={}},
{"custom_puzzle", id=72, x=200, y=-200, size=45,shape=3,icon="puzzle", unlock={}},
{"sprintPenta", id=73, x=-200, y=-200, size=45,shape=3,icon="sprint", unlock={}},
}
modeRanks={}
for i=1,#modes do
modeRanks[i]=false
assert(i==modes[i].id,"ModeID error:"..i)
end
modeRanks[1]=0
}

View File

@@ -1,17 +0,0 @@
local new=love.graphics.setNewFont
local set=love.graphics.setFont
local F,cur={}
return function(s)
local f=F[s]
if s~=cur then
if f then
set(f)
else
f=new("font.ttf",s)
F[s]=f
set(f)
end
cur=s
end
return f
end

View File

@@ -1,71 +0,0 @@
local min=math.min
local mini=love.window.isMinimized
local tickEvent={}
function tickEvent.finish(P)
if SCN.cur~="play"then return true end
P.endCounter=P.endCounter+1
if P.endCounter>120 then pauseGame()end
end
function tickEvent.lose(P)
P.endCounter=P.endCounter+1
if P.endCounter>80 then
for i=1,#P.field do
for j=1,10 do
if P.visTime[i][j]>0 then
P.visTime[i][j]=P.visTime[i][j]-1
end
end
end
if P.endCounter==120 then
for _=#P.field,1,-1 do
freeRow.discard(P.field[_])
freeRow.discard(P.visTime[_])
P.field[_],P.visTime[_]=nil
end
if #players==1 and SCN.cur=="play"then
pauseGame()
end
return true
end
end
end
function tickEvent.throwBadge(A,data)
data[2]=data[2]-1
if data[2]%4==0 then
local S,R=data[1],data[1].lastRecv
local x1,y1,x2,y2
if S.small then
x1,y1=S.centerX,S.centerY
else
x1,y1=S.x+308*S.size,S.y+450*S.size
end
if R.small then
x2,y2=R.centerX,R.centerY
else
x2,y2=R.x+66*R.size,R.y+344*R.size
end
FX_badge[#FX_badge+1]={x1,y1,x2,y2,t=0}
--generate badge object
if not A.ai and data[2]%8==0 then
SFX.play("collect")
end
end
if data[2]<=0 then return true end
end
function tickEvent.bgmFadeOut(_,id)
local src=BGM.list[id]
local v=src:getVolume()-.025*setting.bgm*.1
src:setVolume(v>0 and v or 0)
if v<=0 then
src:stop()
return true
end
end
function tickEvent.bgmFadeIn(_,id)
local src=BGM.list[id]
local v=min(src:getVolume()+.025*setting.bgm*.1,setting.bgm*.1)
src:setVolume(v)
if v>=setting.bgm*.1 then return true end
end
return tickEvent