diff --git a/sonic-radiance.love/scenes/overworld/actors/player/health.lua b/sonic-radiance.love/scenes/overworld/actors/player/health.lua index 96bb584..47a6448 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/health.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/health.lua @@ -1,27 +1,10 @@ local PlayerHealth = Object:extend() -local ComplexHPBar = require "game.modules.gui.complexhpbar" - -local HPBAR_SIZE = 80 - function PlayerHealth:initHealth() - self.hpbar = ComplexHPBar(HPBAR_SIZE) - self.hpbar:setColorForeground(248/255, 160/255, 0, 1) - self.hpbar:setColorBackground(112/255, 0, 0) self.fallDamage = 0 self.fallSound = "" end -function PlayerHealth:drawHealth(x, y) - for i, name in ipairs(game.characters.team) do - local yy = y + (i * 17) - local character = game.characters.list[name] - self.scene.assets.fonts["hudnbrs_small"]:set() - self.hpbar:drawWithLabels(x + 18, yy, character.hp, character.stats:get(character.stats.HPMAX)) - self.assets.tileset["charicons"]:drawTile(character.data.icon, x, yy - 3) - end -end - function PlayerHealth:takeDamage(damage) local damage = damage or 10 damage = damage / 100 diff --git a/sonic-radiance.love/scenes/overworld/actors/player/init.lua b/sonic-radiance.love/scenes/overworld/actors/player/init.lua index b9c17af..5c0f9cd 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/init.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/init.lua @@ -42,7 +42,7 @@ function Player:new(world, x, y, id) end function Player:updateStart(dt) - self.interactionName = "" + self.scene.gui:getElement("interactions"):setInteractionName("") self.tweens:update(dt) self:updateTerrain() self:updateActiveCharacter() @@ -121,19 +121,6 @@ function Player:timerResponse(response) end end -function Player:drawHUD(id) - self:drawHealth((424 - self.scene:getEmblemsPosition()) - 48, 168) - self:drawEmblems(self.scene:getEmblemsPosition(), 24) - if (not utils.string.isEmpty(self.interactionName)) then - local w = self.assets.fonts["small"]:getWidth(self.interactionName) + 16 - love.graphics.setColor(0,0,0,0.5) - local x, y = 424 - w + 4, 240 - 24 - love.graphics.rectangle("fill", x - w/2, y + 1, w, 15, 8, 8) - utils.graphics.resetColor() - self.assets.fonts["small"]:draw(self.interactionName, x, y, -1, "center") - end -end - function Player:draw() Player.super.draw(self) self:drawActionEffect() diff --git a/sonic-radiance.love/scenes/overworld/actors/player/interactions.lua b/sonic-radiance.love/scenes/overworld/actors/player/interactions.lua index 6fa9ccd..0f8dc5c 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/interactions.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/interactions.lua @@ -24,7 +24,6 @@ function PlayerInteractions:initInteractions() self.lastPos = {} self.lastPos.x = self.x self.lastPos.y = self.y - self.interactionName = "" end function PlayerInteractions:updateInteraction() @@ -36,12 +35,12 @@ end function PlayerInteractions:collideWithGizmo(other) if (other.needButton) then - self.interactionName = other.interactionName + self.scene.gui:getElement("interactions"):setInteractionName(other.interactionName) if (self.keys["A"].isPressed) then other:doAction() self.haveCollided = true self.lastCollision = other.creationID - self.interactionName = "" + self.scene.gui:getElement("interactions"):setInteractionName("") end else if (self.lastCollision ~= other.creationID) then @@ -54,12 +53,12 @@ end function PlayerInteractions:talkToGizmo(other) if (self:faceRightDirection(other)) then - self.interactionName = other.interactionName + self.scene.gui:getElement("interactions"):setInteractionName(other.interactionName) if (self.keys["A"].isPressed) then other:doAction() self.haveCollided = true self.lastCollision = other.creationID - self.interactionName = "" + self.scene.gui:getElement("interactions"):setInteractionName("") end end end diff --git a/sonic-radiance.love/scenes/overworld/actors/player/team.lua b/sonic-radiance.love/scenes/overworld/actors/player/team.lua index ab44f0f..eba901a 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/team.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/team.lua @@ -1,17 +1,7 @@ local Team = Object:extend() -local Emblem = require "game.modules.gui.emblem" - function Team:initTeam() self.active = game.characters:getActiveCharacterData() - - self.emblems = {} - for i, name in ipairs(game.characters.team) do - game.characters:loadSprite(self.assets, name) - self.emblems[i] = Emblem(game.characters.list[name], self.scene) - end - - self.activeVisible = game.characters.active self.canChangeActive = true end @@ -42,23 +32,13 @@ function Team:switchActiveCharacter() self.active = game.characters:getActiveCharacterData() self.canChangeActive = false self.tweens:newTimer(0.3, "changeCharacter") - self.tweens:newTween(0, 0.3, {activeVisible = self.activeVisible + count}, "inQuad") + self.scene.gui:getElement("teamEmblems"):changeActivePlayer(count) end end function Team:endCharacterSwitchAnimation() self.canChangeActive = true - self.activeVisible = game.characters.active self:updateCurrentCharset() end -function Team:drawEmblems(x, y) - for i,emblem in ipairs(self.emblems) do - local angle = ((i-self.activeVisible) * (360/#self.emblems)) - 90 - local rad = math.rad(angle) - local emblemX, emblemY = utils.math.lengthdir(18, rad) - emblem:draw(x + emblemX, y + emblemY) - end - end - return Team \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/hudelements/emblems.lua b/sonic-radiance.love/scenes/overworld/gui/hudelements/emblems.lua new file mode 100644 index 0000000..c0fbcf5 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/hudelements/emblems.lua @@ -0,0 +1,30 @@ +local GuiElement = require "birb.modules.gui.elements.parent" +local TeamEmblems = GuiElement:extend() + +local Emblem = require "game.modules.gui.emblem" + +function TeamEmblems:new(x, y) + TeamEmblems.super.new(self, "teamEmblems", x, y, 50, 50) + self.activeVisible = game.characters.active + + self.emblems = {} + for i, name in ipairs(game.characters.team) do + game.characters:loadSprite(self.assets, name) + self.emblems[i] = Emblem(game.characters.list[name], self.scene) + end +end + +function TeamEmblems:changeActivePlayer(count) + self.tweens:newTween(0, 0.3, {activeVisible = self.activeVisible + count}, "inQuad") +end + +function TeamEmblems:draw() + for i,emblem in ipairs(self.emblems) do + local angle = ((i-self.activeVisible) * (360/#self.emblems)) - 90 + local rad = math.rad(angle) + local emblemX, emblemY = utils.math.lengthdir(18, rad) + emblem:draw(self.x + emblemX, self.y + emblemY) + end +end + +return TeamEmblems diff --git a/sonic-radiance.love/scenes/overworld/gui/hudelements/interactions.lua b/sonic-radiance.love/scenes/overworld/gui/hudelements/interactions.lua new file mode 100644 index 0000000..efb3bf2 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/hudelements/interactions.lua @@ -0,0 +1,25 @@ +local GuiElement = require "birb.modules.gui.elements.parent" +local Interactions = GuiElement:extend() + +function Interactions:new() + Interactions.super.new(self, "interactions", 428, 240 - 24, 50, 50) + self.interactionName = "" +end + +function Interactions:setInteractionName(interactionName) + self.interactionName = interactionName +end + +function Interactions:draw() + if (not utils.string.isEmpty(self.interactionName)) then + local w = self.assets.fonts["small"]:getWidth(self.interactionName) + 16 + love.graphics.setColor(0, 0, 0, 0.5) + local x = self.x - w + love.graphics.rectangle("fill", x - w / 2, self.y + 1, w, 15, 8, 8) + love.graphics.setColor(1, 1, 1, 1) + self.assets.fonts["small"]:draw(self.interactionName, x, self.y, -1, "center") + end + utils.graphics.resetColor() +end + +return Interactions diff --git a/sonic-radiance.love/scenes/overworld/gui/hudelements/lifebars.lua b/sonic-radiance.love/scenes/overworld/gui/hudelements/lifebars.lua new file mode 100644 index 0000000..99e0640 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/hudelements/lifebars.lua @@ -0,0 +1,25 @@ +local GuiElement = require "birb.modules.gui.elements.parent" +local LifeBars = GuiElement:extend() + +local ComplexHPBar = require "game.modules.gui.complexhpbar" + +local HPBAR_SIZE = 80 + +function LifeBars:new(x, y) + LifeBars.super.new(self, "lifebars", x, y, 50, 50) + self.hpbar = ComplexHPBar(HPBAR_SIZE) + self.hpbar:setColorForeground(248/255, 160/255, 0, 1) + self.hpbar:setColorBackground(112/255, 0, 0) +end + +function LifeBars:draw() + for i, name in ipairs(game.characters.team) do + local yy = self.y + (i * 17) + local character = game.characters.list[name] + self.scene.assets.fonts["hudnbrs_small"]:set() + self.hpbar:drawWithLabels(self.x + 18, yy, character.hp, character.stats:get(character.stats.HPMAX)) + self.assets.tileset["charicons"]:drawTile(character.data.icon, self.x, yy - 3) + end +end + +return LifeBars diff --git a/sonic-radiance.love/scenes/overworld/gui/hudelements/time.lua b/sonic-radiance.love/scenes/overworld/gui/hudelements/time.lua new file mode 100644 index 0000000..f02a3d6 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/hudelements/time.lua @@ -0,0 +1,12 @@ +local TextElement = require "birb.modules.gui.elements.text" +local TimeElement = TextElement:extend() + +function TimeElement:new(fontName, x, y, align) + TimeElement.super.new(self, "time", fontName, "", x, y, align) +end + +function TimeElement:getText() + return game:getTimeString() +end + +return TimeElement \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/gui/init.lua b/sonic-radiance.love/scenes/overworld/gui/init.lua new file mode 100644 index 0000000..0241f3d --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/gui/init.lua @@ -0,0 +1,65 @@ +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 TimeElement = require "scenes.overworld.gui.hudelements.time" +local Emblems = require "scenes.overworld.gui.hudelements.emblems" +local Lifebars = require "scenes.overworld.gui.hudelements.lifebars" +local Interactions = require "scenes.overworld.gui.hudelements.interactions" + +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 diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index 8337da9..bf9df30 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -33,10 +33,11 @@ local gui = require "game.modules.gui" local TweenManager = require "birb.classes.time" local EventManager = require "game.events" -local MessageQueue = require "game.modules.messagequeue" + +local OWScreen = require "scenes.overworld.gui.init" function OverWorld:new(area, playerx, playery) - OverWorld.super.new(self) + OverWorld.super.new(self, false, false) self.charsetManager = CharsetManager(self) self.assets:batchImport("assets.overworld") @@ -52,17 +53,15 @@ function OverWorld:new(area, playerx, playery) self.backGroundOpacity = 0 self.borderPosition = 0 self.isPaused = false - self.canPause = true - - self.borders = gui.newBorder(424, 30, 8) - self.emblemPosition = 368 - self.ringBorder = -16 - self.tweens:newTween(0, 0.3, {ringBorder=16}, "inOutQuad") - self.timeBorder = -10 + self.canPause = false + self.gui:hideScreen("overlay") + self.tweens:newSwitch(0.6, {"canPause"}) self.isPlaying = "" self.events = EventManager(self) + + OWScreen() end function OverWorld:updateCurrentMap(map) @@ -113,8 +112,10 @@ function OverWorld:update(dt) if (keys["start"].isPressed and self.canPause) then if (not self.isPaused) then - self.assets.sfx["mSelect"]:play() - self:pause() + if (not self.gui.screens["overlay"].isVisible) then + self.assets.sfx["mSelect"]:play() + self:pause() + end else self.assets.sfx["mBack"]:play() self:unpause() @@ -124,10 +125,8 @@ end function OverWorld:pause() self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad") - self.tweens:newTween(0,0.3, {borderPosition=30}, "inOutQuad") - self.tweens:newTween(0, 0.3, {emblemPosition=500}, "inOutQuad") - self.tweens:newTween(0, 0.3, {ringBorder=8}, "inOutQuad") - self.tweens:newTween(0, 0.3, {timeBorder=19}, "inOutQuad") + self.gui:showScreen("overlay") + self.gui:playScreenTransform("hud", "pause") self.isPaused = true self.world.isActive = false screens.mainmenu.pause(self) @@ -135,9 +134,8 @@ end function OverWorld:gameover() self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad") - self.tweens:newTween(0,0.3, {borderPosition=30}, "inOutQuad") - self.tweens:newTween(0, 0.3, {emblemPosition=500}, "inOutQuad") - self.tweens:newTween(0, 0.3, {ringBorder=-16}, "inOutQuad") + self.gui:showScreen("overlay") + self.gui:hideScreen("hud") self.world.isActive = false screens.gameover(self) end @@ -155,11 +153,9 @@ end function OverWorld:unpause() self.tweens:newTween(0.1, 0.2, {backGroundOpacity=0}, "inQuad") - self.tweens:newTween(0, 0.3, {borderPosition=0}, "inOutQuad") - self.tweens:newTween(0, 0.3, {emblemPosition=368}, "inOutQuad") - self.tweens:newTween(0, 0.3, {ringBorder=16}, "inOutQuad") - self.tweens:newTween(0, 0.3, {timeBorder=-20}, "inOutQuad") self.tweens:newTimer(0.2, "unPause") + self.gui:hideScreen("overlay") + self.gui:playScreenTransform("hud", "unpause") if (self.currentScreen ~= nil) then self.currentScreen:quit() @@ -195,15 +191,6 @@ function OverWorld:drawScreenBottomLayer() end function OverWorld:drawScreenTopLayer() - love.graphics.draw(self.borders, 0, self.borderPosition, 0, 1, -1) - love.graphics.draw(self.borders, 424, 240 - self.borderPosition, 0, -1, 1) - - self.assets.images["guiRing"]:draw(self.ringBorder, self.ringBorder) - local ringString = utils.math.numberToString(game.loot.rings, 3) - self.assets.fonts["hudnbrs"]:print(ringString, self.ringBorder + 14, self.ringBorder + 1) - - self.assets.fonts["hudnbrs"]:print(game:getTimeString(), 424 - 16, 240 - self.timeBorder, "right") - if (self.currentScreen ~= nil) then self.currentScreen:drawOverEverything() end