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 - **world:** Make object creation more customizable by worlds
- **camera:** Make mode configuration configurable
### Fixed ### Fixed
- **world:** Remove a forgotten camera debug function - **world:** Remove a forgotten camera debug function

View file

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

View file

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

View file

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