feat(world): add a drawHUD function to draw the current HUD

It is able to draw everything a player object want directly where it 
should go.

Fixes #3
This commit is contained in:
Kazhnuz 2019-06-13 22:23:23 +02:00
parent 6f59f1e732
commit 4c2427bfd6
5 changed files with 30 additions and 0 deletions

View file

@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **actor**: Add functions to add stuf before and after `update` and `draw()` - **actor**: Add functions to add stuf before and after `update` and `draw()`
- **world/camera:** Add support for Head-Up-Display
### Changed ### Changed
- **world:** automatize world integration in a scene - **world:** automatize world integration in a scene

View file

@ -28,4 +28,8 @@ function Player:draw()
Player.super.draw(self) Player.super.draw(self)
end end
function Player:drawHUD(id)
love.graphics.print(id .. " test", 4, 4)
end
return Player return Player

View file

@ -176,6 +176,11 @@ function BaseActor:drawEnd()
end end
function BaseActor:drawHUD(id, height, width)
end
-- SPRITES FUNCTIONS -- SPRITES FUNCTIONS
-- Handle the sprite of the actor -- Handle the sprite of the actor

View file

@ -332,6 +332,7 @@ function BaseWorld:draw(dt)
self:drawMap(i) self:drawMap(i)
self:drawActors(i) self:drawActors(i)
self.cameras:detachView(i) self.cameras:detachView(i)
self.cameras:drawHUD(i)
end end
end end
end end

View file

@ -305,6 +305,9 @@ function CameraSystem:followActor(id)
end end
end end
-- DRAW FUNCTIONS
-- Basic callback to draw stuff
function CameraSystem:drawDebugViewBox(id) function CameraSystem:drawDebugViewBox(id)
local viewx, viewy, vieww, viewh = self:getOnScreenViewCoordinate(id) local viewx, viewy, vieww, viewh = self:getOnScreenViewCoordinate(id)
utils.graphics.box(viewx, viewy, vieww, viewh) utils.graphics.box(viewx, viewy, vieww, viewh)
@ -314,6 +317,21 @@ function CameraSystem:drawDebugViewBox(id)
love.graphics.line(xx, yy-3, xx, yy+3) love.graphics.line(xx, yy-3, xx, yy+3)
local string = id .. " x:" .. viewx .. " y:" .. viewy local string = id .. " x:" .. viewx .. " y:" .. viewy
love.graphics.print(string, viewx + 4, viewy + 4) love.graphics.print(string, viewx + 4, viewy + 4)
print(viewy)
end
function CameraSystem:drawHUD(id)
local viewx, viewy, vieww, viewh = self:getOnScreenViewCoordinate(id)
local view = self:getView(id)
local string2 = id .. " (" .. viewx .. ":" .. (viewh-viewy) .. ") "
love.graphics.setScissor(viewx, viewh-viewy, vieww, viewh)
love.graphics.translate(viewx, viewh-viewy)
view.target:drawHUD(id, vieww, viewh)
love.graphics.translate(-viewx, -(viewh-viewy))
love.graphics.setScissor( )
end end
return CameraSystem return CameraSystem