refactor(levels): let the player manage itself its HUD
This commit is contained in:
parent
5445d619aa
commit
fd986f6b30
|
@ -25,6 +25,7 @@ function Player:new(world, x, y, playerID)
|
||||||
self:lifeInit()
|
self:lifeInit()
|
||||||
self:initWeapon()
|
self:initWeapon()
|
||||||
self:initStats()
|
self:initStats()
|
||||||
|
self:initHUD()
|
||||||
|
|
||||||
self.currentWeapon = 1
|
self.currentWeapon = 1
|
||||||
|
|
||||||
|
@ -224,6 +225,48 @@ self:setSpriteScallingX(self.direction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- HUD FUNCTIONS
|
||||||
|
-- All functions related to the HUD
|
||||||
|
|
||||||
|
function Player:initHUD()
|
||||||
|
local mediumfont, smallfont
|
||||||
|
mediumfont = self.scene.assets.fonts["medium"]
|
||||||
|
smallfont = self.scene.assets.fonts["small"]
|
||||||
|
self.hpbar = game.gui.newProgressBar("greenbar", mediumfont, smallfont, "HP", 96)
|
||||||
|
self.mpbar = game.gui.newProgressBar("bluebar", mediumfont, smallfont, "MP", 96)
|
||||||
|
|
||||||
|
self.itembox = game.gui.newTextBox("assets/sprites/gui/textbox/yellowbox.png", 24,24)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Player:drawHUD()
|
||||||
|
utils.graphics.resetColor()
|
||||||
|
local hp = 0
|
||||||
|
local mp = 0
|
||||||
|
local weapon = 0
|
||||||
|
love.graphics.draw(self.itembox, 16, 16)
|
||||||
|
|
||||||
|
if (true) then
|
||||||
|
hp = self.hp / self.stats.maxHP
|
||||||
|
mp = self.mp / self.stats.maxMP
|
||||||
|
weapon = self.weapon
|
||||||
|
end
|
||||||
|
|
||||||
|
if (weapon ~= 0) and (weapon ~= nil) then
|
||||||
|
self.scene.assets.tileset["weapon"]:drawTile(weapon,28,28,0,1,1,8,8)
|
||||||
|
end
|
||||||
|
|
||||||
|
self.hpbar:draw(68, 14, hp)
|
||||||
|
self.mpbar:draw(68, 30, mp)
|
||||||
|
|
||||||
|
self.scene.assets.fonts["medium"]:set()
|
||||||
|
|
||||||
|
love.graphics.printf( utils.math.numberToString(self.manager.score, 6), 373, 10, 96, "right")
|
||||||
|
love.graphics.printf( utils.math.numberToString(self.manager.gold, 4), 373, 25, 96-18, "right")
|
||||||
|
love.graphics.setColor(1, 1, 85/256)
|
||||||
|
love.graphics.printf( "G", 373, 25, 96, "right")
|
||||||
|
utils.graphics.resetColor()
|
||||||
|
end
|
||||||
|
|
||||||
-- DEATH and HIT functions
|
-- DEATH and HIT functions
|
||||||
-- All function related to damage management
|
-- All function related to damage management
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,6 @@ function PlayerManager:new(scene)
|
||||||
self.itemList = {}
|
self.itemList = {}
|
||||||
self.score = 0
|
self.score = 0
|
||||||
self.gold = 0
|
self.gold = 0
|
||||||
local mediumfont, smallfont
|
|
||||||
mediumfont = self.scene.assets.fonts["medium"]
|
|
||||||
smallfont = self.scene.assets.fonts["small"]
|
|
||||||
self.hpbar = game.gui.newProgressBar("greenbar", mediumfont, smallfont, "HP", 96)
|
|
||||||
self.mpbar = game.gui.newProgressBar("bluebar", mediumfont, smallfont, "MP", 96)
|
|
||||||
|
|
||||||
self.itembox = game.gui.newTextBox("assets/sprites/gui/textbox/yellowbox.png", 24,24)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- PLAYER FUNCTIONS
|
-- PLAYER FUNCTIONS
|
||||||
|
@ -106,32 +99,12 @@ end
|
||||||
-- Functions made to draw the HUD
|
-- Functions made to draw the HUD
|
||||||
|
|
||||||
function PlayerManager:drawHUD(dt)
|
function PlayerManager:drawHUD(dt)
|
||||||
utils.graphics.resetColor()
|
|
||||||
local hp = 0
|
|
||||||
local mp = 0
|
|
||||||
local weapon = 0
|
|
||||||
love.graphics.draw(self.itembox, 16, 16)
|
|
||||||
|
|
||||||
if self:playerHaveObject(1) then
|
if self:playerHaveObject(1) then
|
||||||
local player = self:getPlayerByID(1)
|
local player = self:getPlayerByID(1)
|
||||||
hp = player.hp / player.stats.maxHP
|
player:drawHUD()
|
||||||
mp = player.mp / player.stats.maxMP
|
|
||||||
weapon = player.weapon
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if (weapon ~= 0) and (weapon ~= nil) then
|
|
||||||
self.scene.assets.tileset["weapon"]:drawTile(weapon,28,28,0,1,1,8,8)
|
|
||||||
end
|
|
||||||
self.hpbar:draw(68, 14, hp)
|
|
||||||
self.mpbar:draw(68, 30, mp)
|
|
||||||
|
|
||||||
self.scene.assets.fonts["medium"]:set()
|
|
||||||
|
|
||||||
love.graphics.printf( utils.math.numberToString(self.score, 6), 373, 10, 96, "right")
|
|
||||||
love.graphics.printf( utils.math.numberToString(self.gold, 4), 373, 25, 96-18, "right")
|
|
||||||
love.graphics.setColor(1, 1, 85/256)
|
|
||||||
love.graphics.printf( "G", 373, 25, 96, "right")
|
|
||||||
utils.graphics.resetColor()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return PlayerManager
|
return PlayerManager
|
||||||
|
|
Loading…
Reference in New Issue