From 80072d285a152f59514cab03650be2f1012a3504 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 21 Jun 2019 17:11:32 +0200 Subject: [PATCH 1/4] fix(examples): add missing HUD in one-player example --- CHANGELOG.md | 4 ++++ examples/gameplay/plateform/actors/player.lua | 3 +++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d7632a..e79f614 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixed + +- **examples:** Add missing HUD example for one-player plateformer + ## 0.5.0 - 2019-06-16 - Meta: Add a Code of Conduct diff --git a/examples/gameplay/plateform/actors/player.lua b/examples/gameplay/plateform/actors/player.lua index add912c..74b0173 100644 --- a/examples/gameplay/plateform/actors/player.lua +++ b/examples/gameplay/plateform/actors/player.lua @@ -66,5 +66,8 @@ function Player:collisionResponse(collision) end end +function Player:drawHUD(id) + love.graphics.print(id .. " test", 4, 4) +end return Player From 3ced2dbef42d757d02e7ab22c522bdda71042cd0 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 21 Jun 2019 18:27:02 +0200 Subject: [PATCH 2/4] fix(world): separate getting data from the internal and advertised view Use two functions instead of just one, one showing the actual dimensions of the internal "cam" (basically, the whole screen), and one showing the advertised displaced camera. Fixes #16 --- CHANGELOG.md | 2 ++ gamecore/modules/world/baseworld.lua | 2 +- gamecore/modules/world/camera.lua | 26 +++++++++++++++++++------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e79f614..f5b2094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **examples:** Add missing HUD example for one-player plateformer +- **world:** Separate getting dimensions of the internal and advertised view. + ## 0.5.0 - 2019-06-16 - Meta: Add a Code of Conduct diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index 4bf83eb..db3fbf0 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -413,7 +413,7 @@ function BaseWorld:drawMap(id) if id ~= nil then -- Du à la manière dont fonctionne STI, on est obligé de récupérer les info -- de position de camera pour afficher la carte par rapport à ces infos - tx, ty = self.cameras:getViewCoordinate(id) + tx, ty = self.cameras:getInternalCamCoordinate(id) scale = self.cameras:getViewScale(id) or 1 local vx, vy = self.cameras:getOnScreenViewRelativePosition(id) tx = math.floor(tx - math.abs(vx)) diff --git a/gamecore/modules/world/camera.lua b/gamecore/modules/world/camera.lua index db77abe..3d9023e 100644 --- a/gamecore/modules/world/camera.lua +++ b/gamecore/modules/world/camera.lua @@ -194,15 +194,27 @@ function CameraSystem:detachView(id) end function CameraSystem:getViewCoordinate(id) - local cam = self:getViewCam(id) + local view = self:getView(id) - local camx, camy, camw, camh - camx = cam.x - (self.views.width/2) - camy = cam.y - (self.views.height/2) + local viewx, viewy, vieww, viewh + viewx = view.pos.x - (self.views.width/2) + viewy = view.pos.y - (self.views.height/2) - camw = self.views.width - camh = self.views.height - return camx, camy, camw, camh + vieww = self.views.width + viewh = self.views.height + return viewx, viewy, vieww, viewh +end + +function CameraSystem:getInternalCamCoordinate(id) + local view = self:getView(id) + local cam = self:getViewCam(id) + + local viewx, viewy, vieww, viewh + viewx = cam.x - (self.views.width/2) + viewy = cam.y - (self.views.height/2) + + vieww, viewh = core.screen:getDimensions() + return viewx, viewy, vieww, viewh end function CameraSystem:getOnScreenViewCoordinate(id) From 91019b2074d936e149566a11b5eb447b140ae19f Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 21 Jun 2019 18:51:14 +0200 Subject: [PATCH 3/4] fix(world): use right camera internal coordinate Fixes #15 and #17 --- CHANGELOG.md | 2 ++ gamecore/modules/world/baseworld.lua | 4 ++++ gamecore/modules/world/camera.lua | 35 ++++++++++++++++------------ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5b2094..e15cd4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **world:** Separate getting dimensions of the internal and advertised view. +- **world:** use right camera internal coordinate + ## 0.5.0 - 2019-06-16 - Meta: Add a Code of Conduct diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index db3fbf0..dd12150 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -384,6 +384,10 @@ function BaseWorld:draw(dt) self.cameras:detachView(i) self.cameras:drawHUD(i) end + + for i=1, camNumber do + self.cameras:drawDebugViewBox(i) + end end end diff --git a/gamecore/modules/world/camera.lua b/gamecore/modules/world/camera.lua index 3d9023e..0fb9329 100644 --- a/gamecore/modules/world/camera.lua +++ b/gamecore/modules/world/camera.lua @@ -73,19 +73,19 @@ function CameraSystem:initViews() self.views.posList.multi[1] = {} self.views.posList.multi[1].x = -(self.views.basewidth /4) - self.views.posList.multi[1].y = (self.views.baseheight/4) + self.views.posList.multi[1].y = -(self.views.baseheight/4) self.views.posList.multi[2] = {} self.views.posList.multi[2].x = (self.views.basewidth /4) - self.views.posList.multi[2].y = (self.views.baseheight/4) + self.views.posList.multi[2].y = -(self.views.baseheight/4) self.views.posList.multi[3] = {} self.views.posList.multi[3].x = -(self.views.basewidth /4) - self.views.posList.multi[3].y = -(self.views.baseheight/4) + self.views.posList.multi[3].y = (self.views.baseheight/4) self.views.posList.multi[4] = {} - self.views.posList.multi[4].x = (self.views.basewidth /4) - self.views.posList.multi[4].y = -(self.views.baseheight/4) + self.views.posList.multi[4].x = (self.views.basewidth /4) + self.views.posList.multi[4].y = (self.views.baseheight/4) end -- INFO FUNCTIONS @@ -180,6 +180,14 @@ function CameraSystem:attachView(id) local viewx, viewy, vieww, viewh = self:getOnScreenViewCoordinate(id) cam:attach() + + if (self:getViewNumber() > 2) or (self:getViewNumber() == 2 and SPLITSCREEN_ISVERTICAL) then + -- FIXME: it's an ugly workaround that need to be fixed. For an unkown + -- reason, the scissoring is wrong in and only in this function and only + -- when we have vertical split. Thus, we need to substract viewy to viewy + viewy = viewh - viewy + end + love.graphics.setScissor(viewx, viewy, vieww, viewh) end end @@ -299,11 +307,7 @@ function CameraSystem:computeCamPosition(id) local realy = self.views.list[id].pos.y self.views.list[id].cam.x = realx - decalx - self.views.list[id].cam.y = realy + decaly - -- FIXME: this workaround certainly will cause some problem but that's the only - -- solution we seem to have right now - -- We invert the y decalage for the camera in order to work around a problem - -- that invert the y between it and the clipping. + self.views.list[id].cam.y = realy - decaly end function CameraSystem:followActor(id) @@ -327,9 +331,10 @@ function CameraSystem:drawDebugViewBox(id) local xx, yy = self:getOnScreenViewCenter(id) love.graphics.line(xx-3, yy, xx+3, yy) love.graphics.line(xx, yy-3, xx, yy+3) - local string = id .. " x:" .. viewx .. " y:" .. viewy + + local xx, yy = self:getInternalCamCoordinate(id) + local string = id .. " x:" .. xx .. " y:" .. yy love.graphics.print(string, viewx + 4, viewy + 4) - print(viewy) end function CameraSystem:drawHUD(id) @@ -338,11 +343,11 @@ function CameraSystem:drawHUD(id) local string2 = id .. " (" .. viewx .. ":" .. (viewh-viewy) .. ") " - love.graphics.setScissor(viewx, viewh-viewy, vieww, viewh) - love.graphics.translate(viewx, viewh-viewy) + love.graphics.setScissor(viewx, viewy, vieww, viewh) + love.graphics.translate(viewx, viewy) view.target:drawHUD(id, vieww, viewh) - love.graphics.translate(-viewx, -(viewh-viewy)) + love.graphics.translate(-viewx, -(viewy)) love.graphics.setScissor( ) end From 664a2c73093a9dd1d4dea168a88f6dcd9253f96b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 21 Jun 2019 18:51:41 +0200 Subject: [PATCH 4/4] meta: publish 0.5.1 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e15cd4d..c3bdfc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased -### Fixed +### 0.5.1 - 2019-06-21 - **examples:** Add missing HUD example for one-player plateformer