scenes/levels: fuse controller main functions
This commit is contained in:
parent
0472d56397
commit
136ae0e128
|
@ -1,65 +0,0 @@
|
|||
function Level:draw(dt)
|
||||
love.graphics.setColor(1, 1, 1, 1) -- On reset la couleur.
|
||||
|
||||
-- Ona attache puis détache la caméra pour dessiner le monde, afin que celui
|
||||
-- reste "fixe" tandis que le jouer bouge.
|
||||
self:floorCameraCoord()
|
||||
self:drawBackgroundColor()
|
||||
self.camera:attach()
|
||||
|
||||
self:drawMap()
|
||||
self:drawCollisions()
|
||||
self:worldDraw()
|
||||
|
||||
self.camera:detach()
|
||||
if (self.pause == false) then
|
||||
self:drawHUD()
|
||||
end
|
||||
self:drawDebugHUD()
|
||||
end
|
||||
|
||||
function Level:drawMap()
|
||||
local tx = self.camera.x - 424 / 2
|
||||
local ty = self.camera.y - 240 / 2
|
||||
|
||||
tx = math.floor(tx)
|
||||
ty = math.floor(ty)
|
||||
|
||||
self.map:draw(-tx, -ty, self.camera.scale, self.camera.scale)
|
||||
end
|
||||
|
||||
function Level:drawBackgroundColor()
|
||||
local r, g, b = self.backcolor[1], self.backcolor[2], self.backcolor[3]
|
||||
love.graphics.setColor(r/256, g/256, b/256)
|
||||
love.graphics.rectangle("fill", 0, 0, 480, 272)
|
||||
utils.graphics.resetColor()
|
||||
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: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
|
|
@ -1,8 +1,5 @@
|
|||
Level = Object:extend() -- On créer la classe des entitées, c'est la classe de base
|
||||
|
||||
require "scenes.levels.controller.update"
|
||||
require "scenes.levels.controller.draw"
|
||||
|
||||
require "scenes.levels.controller.virtualpad"
|
||||
|
||||
require "scenes.levels.controller.world"
|
||||
|
@ -107,3 +104,85 @@ function Level:launchMission()
|
|||
self.score = 0
|
||||
self.gold = 0
|
||||
end
|
||||
|
||||
-- UPDATE FUNCTIONS
|
||||
|
||||
function Level:update(dt)
|
||||
self:updateMap(dt)
|
||||
|
||||
if (self.pause == false) then
|
||||
self:updatePlayerSystem(dt)
|
||||
self:worldUpdate(dt)
|
||||
assets:update(dt)
|
||||
self:updateCamera(dt)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- DRAW FUNCTIONS
|
||||
|
||||
function Level:draw(dt)
|
||||
love.graphics.setColor(1, 1, 1, 1) -- On reset la couleur.
|
||||
|
||||
-- Ona attache puis détache la caméra pour dessiner le monde, afin que celui
|
||||
-- reste "fixe" tandis que le jouer bouge.
|
||||
self:floorCameraCoord()
|
||||
self:drawBackgroundColor()
|
||||
self.camera:attach()
|
||||
|
||||
self:drawMap()
|
||||
self:drawCollisions()
|
||||
self:worldDraw()
|
||||
|
||||
self.camera:detach()
|
||||
if (self.pause == false) then
|
||||
self:drawHUD()
|
||||
end
|
||||
self:drawDebugHUD()
|
||||
end
|
||||
|
||||
function Level:drawMap()
|
||||
local tx = self.camera.x - 424 / 2
|
||||
local ty = self.camera.y - 240 / 2
|
||||
|
||||
tx = math.floor(tx)
|
||||
ty = math.floor(ty)
|
||||
|
||||
self.map:draw(-tx, -ty, self.camera.scale, self.camera.scale)
|
||||
end
|
||||
|
||||
function Level:drawBackgroundColor()
|
||||
local r, g, b = self.backcolor[1], self.backcolor[2], self.backcolor[3]
|
||||
love.graphics.setColor(r/256, g/256, b/256)
|
||||
love.graphics.rectangle("fill", 0, 0, 480, 272)
|
||||
utils.graphics.resetColor()
|
||||
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: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
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
function Level:update(dt)
|
||||
self:updateMap(dt)
|
||||
|
||||
if (self.pause == false) then
|
||||
self:updatePlayerSystem(dt)
|
||||
self:worldUpdate(dt)
|
||||
assets:update(dt)
|
||||
self:updateCamera(dt)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue