improvement: handle via gui the overworld hud

This commit is contained in:
Kazhnuz 2021-12-05 17:52:27 +01:00
parent 76e93332e7
commit 87d4bd389d
10 changed files with 181 additions and 88 deletions

View file

@ -1,27 +1,10 @@
local PlayerHealth = Object:extend() local PlayerHealth = Object:extend()
local ComplexHPBar = require "game.modules.gui.complexhpbar"
local HPBAR_SIZE = 80
function PlayerHealth:initHealth() 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.fallDamage = 0
self.fallSound = "" self.fallSound = ""
end 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) function PlayerHealth:takeDamage(damage)
local damage = damage or 10 local damage = damage or 10
damage = damage / 100 damage = damage / 100

View file

@ -42,7 +42,7 @@ function Player:new(world, x, y, id)
end end
function Player:updateStart(dt) function Player:updateStart(dt)
self.interactionName = "" self.scene.gui:getElement("interactions"):setInteractionName("")
self.tweens:update(dt) self.tweens:update(dt)
self:updateTerrain() self:updateTerrain()
self:updateActiveCharacter() self:updateActiveCharacter()
@ -121,19 +121,6 @@ function Player:timerResponse(response)
end end
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() function Player:draw()
Player.super.draw(self) Player.super.draw(self)
self:drawActionEffect() self:drawActionEffect()

View file

@ -24,7 +24,6 @@ function PlayerInteractions:initInteractions()
self.lastPos = {} self.lastPos = {}
self.lastPos.x = self.x self.lastPos.x = self.x
self.lastPos.y = self.y self.lastPos.y = self.y
self.interactionName = ""
end end
function PlayerInteractions:updateInteraction() function PlayerInteractions:updateInteraction()
@ -36,12 +35,12 @@ end
function PlayerInteractions:collideWithGizmo(other) function PlayerInteractions:collideWithGizmo(other)
if (other.needButton) then if (other.needButton) then
self.interactionName = other.interactionName self.scene.gui:getElement("interactions"):setInteractionName(other.interactionName)
if (self.keys["A"].isPressed) then if (self.keys["A"].isPressed) then
other:doAction() other:doAction()
self.haveCollided = true self.haveCollided = true
self.lastCollision = other.creationID self.lastCollision = other.creationID
self.interactionName = "" self.scene.gui:getElement("interactions"):setInteractionName("")
end end
else else
if (self.lastCollision ~= other.creationID) then if (self.lastCollision ~= other.creationID) then
@ -54,12 +53,12 @@ end
function PlayerInteractions:talkToGizmo(other) function PlayerInteractions:talkToGizmo(other)
if (self:faceRightDirection(other)) then if (self:faceRightDirection(other)) then
self.interactionName = other.interactionName self.scene.gui:getElement("interactions"):setInteractionName(other.interactionName)
if (self.keys["A"].isPressed) then if (self.keys["A"].isPressed) then
other:doAction() other:doAction()
self.haveCollided = true self.haveCollided = true
self.lastCollision = other.creationID self.lastCollision = other.creationID
self.interactionName = "" self.scene.gui:getElement("interactions"):setInteractionName("")
end end
end end
end end

View file

@ -1,17 +1,7 @@
local Team = Object:extend() local Team = Object:extend()
local Emblem = require "game.modules.gui.emblem"
function Team:initTeam() function Team:initTeam()
self.active = game.characters:getActiveCharacterData() 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 self.canChangeActive = true
end end
@ -42,23 +32,13 @@ function Team:switchActiveCharacter()
self.active = game.characters:getActiveCharacterData() self.active = game.characters:getActiveCharacterData()
self.canChangeActive = false self.canChangeActive = false
self.tweens:newTimer(0.3, "changeCharacter") 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
end end
function Team:endCharacterSwitchAnimation() function Team:endCharacterSwitchAnimation()
self.canChangeActive = true self.canChangeActive = true
self.activeVisible = game.characters.active
self:updateCurrentCharset() self:updateCurrentCharset()
end 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 return Team

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -33,10 +33,11 @@ local gui = require "game.modules.gui"
local TweenManager = require "birb.classes.time" local TweenManager = require "birb.classes.time"
local EventManager = require "game.events" local EventManager = require "game.events"
local MessageQueue = require "game.modules.messagequeue"
local OWScreen = require "scenes.overworld.gui.init"
function OverWorld:new(area, playerx, playery) function OverWorld:new(area, playerx, playery)
OverWorld.super.new(self) OverWorld.super.new(self, false, false)
self.charsetManager = CharsetManager(self) self.charsetManager = CharsetManager(self)
self.assets:batchImport("assets.overworld") self.assets:batchImport("assets.overworld")
@ -52,17 +53,15 @@ function OverWorld:new(area, playerx, playery)
self.backGroundOpacity = 0 self.backGroundOpacity = 0
self.borderPosition = 0 self.borderPosition = 0
self.isPaused = false self.isPaused = false
self.canPause = true self.canPause = false
self.gui:hideScreen("overlay")
self.borders = gui.newBorder(424, 30, 8) self.tweens:newSwitch(0.6, {"canPause"})
self.emblemPosition = 368
self.ringBorder = -16
self.tweens:newTween(0, 0.3, {ringBorder=16}, "inOutQuad")
self.timeBorder = -10
self.isPlaying = "" self.isPlaying = ""
self.events = EventManager(self) self.events = EventManager(self)
OWScreen()
end end
function OverWorld:updateCurrentMap(map) function OverWorld:updateCurrentMap(map)
@ -113,8 +112,10 @@ function OverWorld:update(dt)
if (keys["start"].isPressed and self.canPause) then if (keys["start"].isPressed and self.canPause) then
if (not self.isPaused) then if (not self.isPaused) then
if (not self.gui.screens["overlay"].isVisible) then
self.assets.sfx["mSelect"]:play() self.assets.sfx["mSelect"]:play()
self:pause() self:pause()
end
else else
self.assets.sfx["mBack"]:play() self.assets.sfx["mBack"]:play()
self:unpause() self:unpause()
@ -124,10 +125,8 @@ end
function OverWorld:pause() function OverWorld:pause()
self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad") self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad")
self.tweens:newTween(0,0.3, {borderPosition=30}, "inOutQuad") self.gui:showScreen("overlay")
self.tweens:newTween(0, 0.3, {emblemPosition=500}, "inOutQuad") self.gui:playScreenTransform("hud", "pause")
self.tweens:newTween(0, 0.3, {ringBorder=8}, "inOutQuad")
self.tweens:newTween(0, 0.3, {timeBorder=19}, "inOutQuad")
self.isPaused = true self.isPaused = true
self.world.isActive = false self.world.isActive = false
screens.mainmenu.pause(self) screens.mainmenu.pause(self)
@ -135,9 +134,8 @@ end
function OverWorld:gameover() function OverWorld:gameover()
self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad") self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad")
self.tweens:newTween(0,0.3, {borderPosition=30}, "inOutQuad") self.gui:showScreen("overlay")
self.tweens:newTween(0, 0.3, {emblemPosition=500}, "inOutQuad") self.gui:hideScreen("hud")
self.tweens:newTween(0, 0.3, {ringBorder=-16}, "inOutQuad")
self.world.isActive = false self.world.isActive = false
screens.gameover(self) screens.gameover(self)
end end
@ -155,11 +153,9 @@ end
function OverWorld:unpause() function OverWorld:unpause()
self.tweens:newTween(0.1, 0.2, {backGroundOpacity=0}, "inQuad") 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.tweens:newTimer(0.2, "unPause")
self.gui:hideScreen("overlay")
self.gui:playScreenTransform("hud", "unpause")
if (self.currentScreen ~= nil) then if (self.currentScreen ~= nil) then
self.currentScreen:quit() self.currentScreen:quit()
@ -195,15 +191,6 @@ function OverWorld:drawScreenBottomLayer()
end end
function OverWorld:drawScreenTopLayer() 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 if (self.currentScreen ~= nil) then
self.currentScreen:drawOverEverything() self.currentScreen:drawOverEverything()
end end