From 4c2427bfd62d7a41cbf9be0eb5caec49b1b53dfb Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 13 Jun 2019 22:23:23 +0200 Subject: [PATCH] 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 --- CHANGELOG.md | 2 ++ examples/gameplay/moveplayer/actors/player.lua | 4 ++++ gamecore/modules/world/actors/baseactor.lua | 5 +++++ gamecore/modules/world/baseworld.lua | 1 + gamecore/modules/world/camera.lua | 18 ++++++++++++++++++ 5 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eca2e0c..e9fb98b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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()` +- **world/camera:** Add support for Head-Up-Display + ### Changed - **world:** automatize world integration in a scene diff --git a/examples/gameplay/moveplayer/actors/player.lua b/examples/gameplay/moveplayer/actors/player.lua index a752c38..9e80089 100644 --- a/examples/gameplay/moveplayer/actors/player.lua +++ b/examples/gameplay/moveplayer/actors/player.lua @@ -28,4 +28,8 @@ function Player:draw() Player.super.draw(self) end +function Player:drawHUD(id) + love.graphics.print(id .. " test", 4, 4) +end + return Player diff --git a/gamecore/modules/world/actors/baseactor.lua b/gamecore/modules/world/actors/baseactor.lua index ef9a325..0274d77 100644 --- a/gamecore/modules/world/actors/baseactor.lua +++ b/gamecore/modules/world/actors/baseactor.lua @@ -176,6 +176,11 @@ function BaseActor:drawEnd() end +function BaseActor:drawHUD(id, height, width) + +end + + -- SPRITES FUNCTIONS -- Handle the sprite of the actor diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index ece92a7..274f6d1 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -332,6 +332,7 @@ function BaseWorld:draw(dt) self:drawMap(i) self:drawActors(i) self.cameras:detachView(i) + self.cameras:drawHUD(i) end end end diff --git a/gamecore/modules/world/camera.lua b/gamecore/modules/world/camera.lua index a944e7e..db77abe 100644 --- a/gamecore/modules/world/camera.lua +++ b/gamecore/modules/world/camera.lua @@ -305,6 +305,9 @@ function CameraSystem:followActor(id) end end +-- DRAW FUNCTIONS +-- Basic callback to draw stuff + function CameraSystem:drawDebugViewBox(id) local viewx, viewy, vieww, viewh = self:getOnScreenViewCoordinate(id) utils.graphics.box(viewx, viewy, vieww, viewh) @@ -314,6 +317,21 @@ function CameraSystem:drawDebugViewBox(id) love.graphics.line(xx, yy-3, xx, yy+3) local string = id .. " x:" .. viewx .. " y:" .. viewy 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 return CameraSystem