feat(camera): make the camera support multiple "mode"

This commit is contained in:
Kazhnuz 2019-06-29 11:32:42 +02:00
parent a31eae5c24
commit 91fc55555f
4 changed files with 24 additions and 12 deletions

View file

@ -35,6 +35,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **world:** Make object creation more customizable by worlds
- **camera:** Make mode configuration configurable
### Fixed
- **world:** Remove a forgotten camera debug function

View file

@ -225,17 +225,14 @@ function BaseWorld:setPlayerNumber(playerNumber)
self.playerNumber = playerNumber or 1
end
function BaseWorld:addPlayer(actor, sourceid, haveCam)
function BaseWorld:addPlayer(actor, sourceid)
local player = {}
player.actor = actor
player.sourceid = sourceid or 1
table.insert(self.players, player)
if (haveCam) then
local xx, yy = player.actor:getViewCenter()
self.cameras:addView(xx, yy, player.actor)
end
self.cameras:addTarget(player.actor)
end
function BaseWorld:sendInputToPlayers(actor)
@ -319,7 +316,7 @@ function BaseWorld:newCollisionFromMap(objectlayer, object)
end
function BaseWorld:addPlayerFromMap(object, i)
self:addPlayer(self.obj.Player(self, object.x, object.y), i, true)
self:addPlayer(self.obj.Player(self, object.x, object.y), i)
end
function BaseWorld:loadMapPlayers()

View file

@ -37,11 +37,18 @@ function CameraSystem:new(world)
self.scene = world.scene
self.world = world
self.verticalSplit = SPLITSCREEN_ISVERTICAL
self.mode = "split"
self.verticalSplit = SPLITSCREEN_ISVERTICAL
self:initViews()
end
function CameraSystem:setMode(mode)
self.mode = mode
print("Camera system mode set to " .. mode)
return mode
end
function CameraSystem:initViews()
self.views = {}
@ -143,6 +150,15 @@ end
-- WRAPPER and UTILS
-- Access data from the views
function CameraSystem:addTarget(target)
if (#self.views < SCREEN_LIMIT) then
if (#self.views.list == 0) or (self.mode == "split") then
local x, y = target:getViewCenter()
self:addView(x, y, target)
end
end
end
function CameraSystem:addView(x, y, target)
if (#self.views.list < SCREEN_LIMIT) then
local id = #self.views.list + 1

View file

@ -82,10 +82,7 @@ function World2D:addPlayer(actor, sourceid, haveCam)
table.insert(self.players, player)
if (haveCam) then
local xx, yy = player.actor:getViewCenter()
self.cameras:addView(xx, yy, player.actor)
end
self.cameras:addTarget(player.actor)
end
-- MAP LOADING FUNCTIONS
@ -119,7 +116,7 @@ function World2D:newCollisionFromMap(objectlayer, object)
end
function World2D:addPlayerFromMap(object, i)
self:addPlayer(self.obj.Player(self, object.x, object.y), i, true)
self:addPlayer(self.obj.Player(self, object.x, object.y), i)
end
-- BODIES MANAGEMENT FUNCTIONS