feat: add character switching to subgames

This commit is contained in:
Kazhnuz 2022-05-11 23:07:55 +02:00
parent f5bff3e1b9
commit cdc5b083ca
5 changed files with 104 additions and 3 deletions

View file

@ -0,0 +1,62 @@
local GuiScreen = require "birb.modules.gui.screen"
local OWScreen = GuiScreen:extend()
local Composite = require "birb.modules.gui.elements.composite"
local Counter = require "birb.modules.gui.elements.counter"
local Asset = require "birb.modules.gui.elements.assets"
local Emblems = require "scenes.overworld.gui.hudelements.emblems"
local show = {
-- {"rings", "movement", 0, 0.3, 16, 16, "inOutQuart"},
-- {"time", "movement", 0, 0.3, 408, 250, "inOutQuart"},
{"teamEmblems", "movement", 0, 0.3, 368, 24, "inOutQuart"},
-- {"lifebars", "movement", 0, 0.3, 8, 168, "inOutQuart"},
}
local hide = {
-- {"rings", "movement", 0, 0.3, -16, -16, "inOutQuart"},
-- {"time", "movement", 0, 0.3, 408, 250, "inOutQuart"},
{"teamEmblems", "movement", 0, 0.3, 500, 24, "inOutQuart"},
-- {"lifebars", "movement", 0, 0.3, -124, 168, "inOutQuart"},
}
local showMenu = {
-- {"rings", "movement", 0, 0.5, 8, 8, "inOutQuart"},
-- {"time", "movement", 0, 0.5, 408, 221, "inOutQuart"},
{"teamEmblems", "movement", 0, 0.3, 500, 24, "inOutQuart"},
-- {"lifebars", "movement", 0, 0.3, -124, 168, "inOutQuart"},
}
local hideMenu = {
-- {"rings", "movement", 0, 0.5, 16, 16, "inOutQuart"},
-- {"time", "movement", 0, 0.5, 408, 250, "inOutQuart"},
{"teamEmblems", "movement", 0, 0.3, 368, 24, "inOutQuart"},
-- {"lifebars", "movement", 0, 0.3, 8, 168, "inOutQuart"}
}
function OWScreen:new()
OWScreen.super.new(self, "hud")
self:addTransform("show", show)
self:addTransform("hide", hide)
self:addTransform("pause", showMenu)
self:addTransform("unpause", hideMenu)
self:show()
end
function OWScreen:createElements()
local list = {
-- {Composite("rings", -16, -16, {
-- {Asset("guiRing", "images", "guiRing", -1, -1), 0, 0},
-- {Counter("turnCnt", "hudnbrs", game.loot, "rings", 3, -1, -1), 14, 1}
-- }), 0, -100},
-- {TimeElement("hudnbrs", 408, 250, "right"), 0, -100},
Emblems(500, 24),
-- Lifebars(-124, 168),
-- Interactions()
}
return list
end
return OWScreen

View file

@ -3,6 +3,7 @@ local PlayStyle = Scene:extend()
local TweenManager = require "birb.classes.time"
local PauseScreen = require("game.modules.subgames.pause")
local HUD = require("game.modules.subgames.hud")
local TestWorld = require("game.modules.subgames.world.parent")
function PlayStyle:new(supportedLevels, missionfile)
@ -17,6 +18,7 @@ function PlayStyle:new(supportedLevels, missionfile)
self.tweens = TweenManager(self)
PauseScreen()
HUD()
self.haveStarted = false
self.canPause = true

View file

@ -10,4 +10,13 @@ function PlayerActions:doActions()
end
end
function PlayerActions:actionSwitch()
if self.keys["L1"].isPressed and (self.action == "normal") and (self.onGround) then
self:switchActiveCharacter()
end
if self.keys["R1"].isPressed and (self.action == "normal") and (self.onGround) then
self:switchActiveCharacter(-1)
end
end
return PlayerActions

View file

@ -2,15 +2,19 @@ local cwd = (...):gsub('%.player$', '') .. "."
local Parent = require(cwd .. "parent")
local Player = Parent:extend()
local TweenManager = require "birb.classes.time"
local Actions = require "game.modules.subgames.world.actors.player.actions"
local Movements = require "game.modules.subgames.world.actors.player.movements"
local Score = require "game.modules.subgames.world.actors.player.score"
local Sprites = require "game.modules.subgames.world.actors.player.sprites"
local Team = require "scenes.overworld.actors.player.team"
Player:implement(Actions)
Player:implement(Movements)
Player:implement(Score)
Player:implement(Sprites)
Player:implement(Team)
function Player:new(world, x, y, z, id)
Player.super.new(self, world, "player", x, y, 0, 16, 12, 24, true)
@ -18,19 +22,35 @@ function Player:new(world, x, y, z, id)
self:initCharactersSprites()
self:initScore()
self:initActions()
self:initTeam()
self.tweens = TweenManager(self)
end
function Player:updateStart(dt)
self:basicMovements()
self:doActions()
self:actionSwitch()
end
function Player:update(dt)
Player.super.update(self, dt)
self.tweens:update(dt)
end
function Player:collisionResponse(collision)
if collision.other.type == "collectible" then
collision.other.owner:getPicked(self)
end
end
function Player:timerResponse(response)
if (response == "changeCharacter") then
self:endCharacterSwitchAnimation()
end
end
function Player:animationEnded(name)
end

View file

@ -1,9 +1,11 @@
local SpritedPlayer = Object:extend()
function SpritedPlayer:initCharactersSprites()
self.charName = game.characters:getActiveCharacter()
self.assets:addSprite(self.charName, "datas/gamedata/characters/" .. self.charName .. "/sprites")
self:setSprite(self.charName, true, 8, 10)
for id, name in ipairs(game.characters.team) do
self.assets:addSprite(name, "datas/gamedata/characters/" .. name .. "/sprites")
end
self.direction = 1
self:updateCurrentCharset()
end
function SpritedPlayer:setAnimation()
@ -38,4 +40,10 @@ function SpritedPlayer:setDirection(direction)
end
end
function SpritedPlayer:updateCurrentCharset()
self.charName = game.characters:getActiveCharacter()
self:setSprite(self.charName, true, 8, 10)
self.sprite:setScallingX(self.direction)
end
return SpritedPlayer