From 8f27270c39382fb32ca5cf94a42c13116919267b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 10 Apr 2021 17:59:01 +0200 Subject: [PATCH] feat: add initial action checking system --- sonic-radiance.love/datas/gamedata/startdata.lua | 3 ++- sonic-radiance.love/game/init.lua | 3 +++ .../scenes/overworld/actors/player/actions.lua | 11 +++++++++++ .../scenes/overworld/actors/player/team.lua | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/datas/gamedata/startdata.lua b/sonic-radiance.love/datas/gamedata/startdata.lua index 0883566..ef58b35 100644 --- a/sonic-radiance.love/datas/gamedata/startdata.lua +++ b/sonic-radiance.love/datas/gamedata/startdata.lua @@ -4,5 +4,6 @@ return { y = 10, area = "test.plain" }, - baseteam = {"sonic", "tails", "amy"} + baseteam = {"sonic", "tails", "amy"}, + actions = {"run", "punch", "fly"} } \ No newline at end of file diff --git a/sonic-radiance.love/game/init.lua b/sonic-radiance.love/game/init.lua index 414068b..4a16d8b 100644 --- a/sonic-radiance.love/game/init.lua +++ b/sonic-radiance.love/game/init.lua @@ -55,6 +55,7 @@ function Game:new() self.variables = {} self.completion = 0 self.mapName = "" + self.actions = startdata.actions self.version = "0.0.0" end @@ -73,6 +74,7 @@ function Game:setData(data) self.variables = data.variables self.flags = data.flags self.position = data.position + self.actions = data.actions self.characters:setData(data.characters) self.loot:setData(data.loot) end @@ -86,6 +88,7 @@ function Game:getData() data.destroyedGizmo = self.destroyedGizmo data.variables = self.variables data.position = self.position + data.actions = self.actions return data end diff --git a/sonic-radiance.love/scenes/overworld/actors/player/actions.lua b/sonic-radiance.love/scenes/overworld/actors/player/actions.lua index 6d98c01..00d999b 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/actions.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/actions.lua @@ -3,10 +3,21 @@ local PlayerActions = Object:extend() local BASE_SPEED = 120 local JMP_STRENGHT = 2.5 +local ACTIONS = {} +ACTIONS["speedster"] = {"run"} +ACTIONS["technic"] = {"fly"} +ACTIONS["power"] = {"punch"} + function PlayerActions:initActions() self.currentAction = "idle" end +function PlayerActions:canDoAction(action) + local classCanDoAction = utils.table.contain(ACTIONS[self:getCurrentCharType()], action) + local playerCanDoAction = utils.table.contain(game.actions, action) + return (classCanDoAction and playerCanDoAction) +end + function PlayerActions:actionMove() if self.keys["up"].isDown then self.ysp = -BASE_SPEED diff --git a/sonic-radiance.love/scenes/overworld/actors/player/team.lua b/sonic-radiance.love/scenes/overworld/actors/player/team.lua index fbb1361..4107446 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/team.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/team.lua @@ -15,6 +15,10 @@ function Team:initTeam() self.canChangeActive = true end +function Team:getCurrentCharType() + return self.active.data.class +end + function Team:switchActiveCharacter() if (self.canChangeActive) then game.characters:setActiveCharacter()