Merge branch '0.5.1' of game-projects/gamecore into 0.5.x

This commit is contained in:
Kazhnuz 2019-06-21 18:52:33 +02:00 committed by Gitea
commit 79c79d9613
4 changed files with 55 additions and 23 deletions

View file

@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### 0.5.1 - 2019-06-21
- **examples:** Add missing HUD example for one-player plateformer
- **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

View file

@ -66,5 +66,8 @@ function Player:collisionResponse(collision)
end
end
function Player:drawHUD(id)
love.graphics.print(id .. " test", 4, 4)
end
return Player

View file

@ -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
@ -413,7 +417,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))

View file

@ -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
@ -194,15 +202,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)
@ -287,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)
@ -315,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)
@ -326,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