Skip to content

Commit

Permalink
实现修改下次点数和额外/跳过回合的格子效果
Browse files Browse the repository at this point in the history
框架跟进
  • Loading branch information
MrZ626 committed Jan 12, 2025
1 parent 67a1f30 commit 896bf98
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Zenitha
44 changes: 25 additions & 19 deletions assets/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,16 @@ function Game.new(data)
end
addQ('deco',cell,prop,QUAD.world.warn)
elseif prop[1]=='stop' then
addQ('text',cell,prop,"X")
addQ('text',cell,prop,"停止")
addQ('deco',cell,prop,QUAD.world.warn)
elseif prop[1]=='reverse' then
addQ('text',cell,prop,"R")
addQ('text',cell,prop,"反转")
addQ('deco',cell,prop,QUAD.world.warn)
elseif prop[1]=='diceMod' then
addQ('text',cell,prop,"下次点数"..prop[2]..prop[3]) -- TODO
addQ('deco',cell,prop,QUAD.world.warn)
elseif prop[1]=='exTurn' then
addQ('text',cell,prop,(prop[2]>0 and "再骰%d次" or "跳过%d回合"):format(math.abs(prop[2])))
addQ('deco',cell,prop,QUAD.world.warn)
end

Expand Down Expand Up @@ -330,27 +336,27 @@ function Game:roll()
repeat coroutine.yield() until p.dice.animState=='bounce'
p:move(p.dice.value)
repeat coroutine.yield() until not p.moving
self.roundIndex=self.roundIndex%#self.players+1
TEXT:add{
text="Player "..self.roundIndex.." turn",
r=1,g=1,b=1,a=.4,
duration=1.4,
x=500-4,y=300-4,k=1.5,
fontSize=40,
style='zoomout',
}
TEXT:add{
text="Player "..self.roundIndex.." turn",
color=self.players[self.roundIndex].color,
duration=1.6,
x=500,y=300,k=1.5,
fontSize=40,
style='zoomout',
}
self:updateTurn()
end)
end
end

function Game:updateTurn()
local p=self.players[self.roundIndex]
if p.extraTurn>0 then
p.extraTurn=p.extraTurn-1
MSG('other',"玩家"..self.roundIndex.."的额外回合")
else
while true do
self.roundIndex=self.roundIndex%#self.players+1
p=self.players[self.roundIndex]
if p.extraTurn>=0 then break end
p.extraTurn=p.extraTurn+1
end
MSG('other',"玩家"..self.roundIndex.."的回合")
end
end

---@param a {p:ReroChess.Player}
local function coSorter(a,b)
return a.p.y<b.p.y
Expand Down
14 changes: 7 additions & 7 deletions assets/map/lue_first.luaon
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ return {
{'mDrawQ',TEX.world.default,QUAD.world.finish,8,10,0,-1/128,1/128},
},
mapData={
{0,0,prop='label,start text,起点'},{1,0},{1,0},{1,0,prop='move,-1'},{1,0,prop='text,DiceAgain'},{1,t},
{0,1,prop='move,-3'},{-1,t},{-1,0,prop='move,-2'},{-1,0,prop='move,-1'},{-1,0},{-1,t,prop='text,NextDice+1'},
{0,1,prop='text,Skip1'},{1,t,prop='move,1'},{1,0},{1,0,prop='move,-1'},{1,0,prop='text,NextDice*2'},{1,t},
{0,1,prop='move,-1'},{-1,t,prop='move,-1'},{-1,0,prop='move,-1'},{-1,0},{-1,0,prop='text,NextDice-3'},{-1,t,prop='move,-3'},
{0,0,prop='label,start text,起点'},{1,0},{1,0},{1,0,prop='move,-1'},{1,0,prop='exTurn'},{1,t},
{0,1,prop='move,-3'},{-1,t},{-1,0,prop='move,-2'},{-1,0,prop='move,-1'},{-1,0},{-1,t,prop='diceMod,+,1'},
{0,1,prop='text,Skip1'},{1,t,prop='move,1'},{1,0},{1,0,prop='move,-1'},{1,0,prop='diceMod,*,2'},{1,t},
{0,1,prop='move,-1'},{-1,t,prop='move,-1'},{-1,0,prop='move,-1'},{-1,0},{-1,0,prop='diceMod,-,3'},{-1,t,prop='move,-3'},
{0,1},{1,t,prop='move,+1'},{1,0},{1,0,prop='text,@p+1'},{1,0,prop='text,HospitalExit'},{1,t,prop='move,-4'},
{0,1},{-1,t,prop='text,NextDice/2'},{-1,0,prop='text,NextDice*3'},{-1,0,prop='text,NextDice^2'},{-1,0,prop='text,NextDice//2'},{-1,t},
{0,1},{1,t,prop='move,-2'},{1,0,prop='teleport,hospital text,住院'},{1,0,prop='move,-1'},{1,0,prop='text,Skip3'},{1,0,prop='text,JailExit'},{1,0},{1,-h,prop='text,DiceAgain'},
{0,1},{-1,t,prop='diceMod,/,2'},{-1,0,prop='diceMod,*,3'},{-1,0,prop='diceMod,^,2'},{-1,0,prop='diceMod,&,2'},{-1,t},
{0,1},{1,t,prop='move,-2'},{1,0,prop='teleport,hospital text,住院'},{1,0,prop='move,-1'},{1,0,prop='text,Skip3'},{1,0,prop='text,JailExit'},{1,0},{1,-h,prop='exTurn'},
{0,-1,prop='text,@pSwap'},{0,-1},{0,-1,prop='move,-1'},{0,-1,prop='move,-18'},{0,-1,prop='text,@pQuitJail'},{0,-1,prop='text,@pHosp@sJail'},{0,-1,prop='text,@c-1'},{0,-1,prop='move,2'},{0,-1},
{1,-h,prop='move,-12'},{1,0,prop='text,前方\n苦痛之路'},{1,0,prop='move,-1'},{1,0,prop='move,-1'},{1,0,prop='move,-1'},
{0,1,prop='text,NextDice-1'},{0,1},{0,1,prop='move,-3'},{0,1,prop='move,-1'},{0,1,prop='move,-1'},{0,1},{0,1,prop='move,-2'},{0,1,prop='move,-1'},{0,1,prop='move,-1'},{0,1},
{0,1,prop='diceMod,-,1'},{0,1},{0,1,prop='move,-3'},{0,1,prop='move,-1'},{0,1,prop='move,-1'},{0,1},{0,1,prop='move,-2'},{0,1,prop='move,-1'},{0,1,prop='move,-1'},{0,1},
{-1,0,prop='move,-2'},{-1,0,prop='teleport,start text,回到起点'},{-1,0,prop='text,终点'},

{x=8.5,y=1.5+1/6,prop='label,hospital text,医院'},
Expand Down
24 changes: 24 additions & 0 deletions assets/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ local Prop=require'assets.prop'
---@field moveDir 'next' | 'prev' | false
---@field dice ReroChess.Dice
---
---Variables between rounds
---@field extraTurn integer
---@field diceMod table[]
---
---Variables for moving in round
---@field moving boolean
---@field moveSignal boolean
Expand Down Expand Up @@ -77,6 +81,9 @@ function Player.new(id,data,game)
animState='hide',
},

extraTurn=0,
diceMod={},

x=(id-1)%2==0 and -.26 or .26,
y=(id-1)%4<=1 and -.26 or .26,
},Player)
Expand Down Expand Up @@ -129,6 +136,23 @@ function Player:roll()
d.value=d.points[r]
end
end):setEase('OutCirc'):setDuration(2.6):setOnFinish(function()
if #self.diceMod>0 then
local mod=table.remove(self.diceMod,1)
if mod[1]=='+' then
d.value=d.value+mod[2]
elseif mod[1]=='-' then
d.value=d.value-mod[2]
elseif mod[1]=='*' then
d.value=d.value*mod[2]
elseif mod[1]=='/' then
d.value=d.value/mod[2]
elseif mod[1]=='^' then
d.value=d.value^mod[2]
elseif mod[1]=='&' then
d.value=d.value^(1/mod[2])
end
d.value=math.floor(d.value+.001)
end
d.animState='bounce'
TWEEN.new(function(t)
d.size=1+math.sin(t*26)/(1+62*t)
Expand Down
46 changes: 46 additions & 0 deletions assets/prop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,50 @@ Prop.reverse={
end,
}

local modifiers={
['+']=true,
['-']=true,
['*']=true,
['/']=true,
['^']=true,
['&']=true,
}
Prop.diceMod={
parse=function(prop)
prop[3]=tonumber(prop[3])
assert(
modifiers[prop[2]] and
type(prop[3])=='number',
'diceMod[1] must be operator and diceMod[2] must be number'
)
end,
---@param P ReroChess.Player
code=function(P,op,num)
P:popText{
text=("下一次点数%s%d"):format(op,num),
duration=2,
}
table.insert(P.diceMod,{op,num})
end,
}

Prop.exTurn={
parse=function(prop)
if prop[2]==nil then prop[2]=1 end
prop[2]=tonumber(prop[2])
assert(
type(prop[2])=='number' and prop[2]%1==0 and prop[2]~=0,
'exTurn[1] must be non-zero integer'
)
end,
---@param P ReroChess.Player
code=function(P,cnt)
P:popText{
text=cnt>0 and "额外回合!" or "跳过回合!",
duration=2,
}
P.extraTurn=P.extraTurn+cnt
end,
}

return Prop

0 comments on commit 896bf98

Please sign in to comment.