scenes/levels: let the playermanager handle loot and HUD
This commit is contained in:
parent
c6f4149808
commit
fc53a491f6
|
@ -24,10 +24,6 @@ function Level:reset()
|
|||
self.map = nil
|
||||
self.backcolor = {0, 0, 0}
|
||||
|
||||
self.itemList = {}
|
||||
self.score = 0
|
||||
self.gold = 0
|
||||
|
||||
end
|
||||
|
||||
function Level:loadMission(levelID, missionID)
|
||||
|
@ -91,35 +87,6 @@ function Level:draw(dt)
|
|||
self.world:draw()
|
||||
|
||||
if (self.pause == false) then
|
||||
self:drawHUD()
|
||||
self.playermanager:drawHUD()
|
||||
end
|
||||
end
|
||||
|
||||
function Level:drawHUD(dt)
|
||||
utils.graphics.resetColor()
|
||||
local hp = 0
|
||||
local mp = 0
|
||||
local weapon = 0
|
||||
assets.textbox["yellowbox"]:draw(16,16,24,24)
|
||||
|
||||
if self.playermanager:playerHaveObject(1) then
|
||||
local player = self.playermanager:getPlayerByID(1)
|
||||
hp = player.hp / player.stats.maxHP
|
||||
mp = player.mp / player.stats.maxMP
|
||||
weapon = player.weapon
|
||||
end
|
||||
|
||||
if (weapon ~= 0) and (weapon ~= nil) then
|
||||
assets.sprites["weapon"]:drawIcon(weapon,28,28,0,1,1,8,8)
|
||||
end
|
||||
assets.progressbar["greenbar"]:draw("HP", 68, 14, 96, hp, "")
|
||||
assets.progressbar["bluebar"]:draw("MP", 68, 30, 96, mp, "")
|
||||
|
||||
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
|
||||
|
|
|
@ -7,6 +7,10 @@ function PlayerManager:new(scene)
|
|||
self.deathTimer = -100
|
||||
self.activePlayer = -1
|
||||
self.startx, self.starty = self.scene.world:getStartPosition()
|
||||
|
||||
self.itemList = {}
|
||||
self.score = 0
|
||||
self.gold = 0
|
||||
end
|
||||
|
||||
function PlayerManager:addPlayer(pigID)
|
||||
|
@ -83,4 +87,34 @@ function PlayerManager:update(dt)
|
|||
end
|
||||
end
|
||||
|
||||
function PlayerManager:drawHUD(dt)
|
||||
utils.graphics.resetColor()
|
||||
local hp = 0
|
||||
local mp = 0
|
||||
local weapon = 0
|
||||
assets.textbox["yellowbox"]:draw(16,16,24,24)
|
||||
|
||||
if self:playerHaveObject(1) then
|
||||
local player = self:getPlayerByID(1)
|
||||
hp = player.hp / player.stats.maxHP
|
||||
mp = player.mp / player.stats.maxMP
|
||||
weapon = player.weapon
|
||||
end
|
||||
|
||||
if (weapon ~= 0) and (weapon ~= nil) then
|
||||
assets.sprites["weapon"]:drawIcon(weapon,28,28,0,1,1,8,8)
|
||||
end
|
||||
assets.progressbar["greenbar"]:draw("HP", 68, 14, 96, hp, "")
|
||||
assets.progressbar["bluebar"]:draw("MP", 68, 30, 96, mp, "")
|
||||
|
||||
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
|
||||
|
||||
|
||||
return PlayerManager
|
||||
|
|
|
@ -11,7 +11,7 @@ end
|
|||
function Coin:takeLoot()
|
||||
self.obj.GFX(self.level, self.x+8, self.y+8, "sparkle", 1)
|
||||
self:destroy()
|
||||
self.level.gold = self.level.gold + self.value
|
||||
self.level.gold = self.level.playermanager.gold + self.value
|
||||
assets:playSFX("collectcoin")
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ end
|
|||
function Loot:takeLoot()
|
||||
self.obj.GFX(self.level, self.x+8, self.y+8, "sparkle", 1)
|
||||
self:destroy()
|
||||
self.level.gold = self.level.gold + 1
|
||||
self.level.gold = self.level.playermanager.gold + 1
|
||||
assets:playSFX("collectcoin")
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue