modules/world: add camera system to the world system
This commit is contained in:
parent
ffac18d6a5
commit
a046eb5a9c
2 changed files with 34 additions and 6 deletions
|
@ -26,7 +26,8 @@ local cwd = (...):gsub('%.baseworld$', '') .. "."
|
|||
|
||||
local BaseWorld = Object:extend()
|
||||
|
||||
local Sti = require(cwd .. "libs.sti")
|
||||
local Sti = require(cwd .. "libs.sti")
|
||||
local CameraSystem = require(cwd .. "camera")
|
||||
|
||||
-- INIT FUNCTIONS
|
||||
-- All functions to init the world and the map
|
||||
|
@ -34,6 +35,8 @@ local Sti = require(cwd .. "libs.sti")
|
|||
function BaseWorld:new(scene, actorlist, mapfile)
|
||||
self.scene = scene
|
||||
|
||||
self.cameras = CameraSystem(self)
|
||||
|
||||
self:initPlayers()
|
||||
self:setActorList(actorlist)
|
||||
self:setMap(mapfile)
|
||||
|
@ -192,20 +195,42 @@ end
|
|||
|
||||
function BaseWorld:draw(dt)
|
||||
self:drawBackgroundColor()
|
||||
self:drawMap()
|
||||
self:drawActors()
|
||||
local camNumber = self.cameras:getViewNumber()
|
||||
|
||||
if (camNumber == 0) then
|
||||
self:drawMap()
|
||||
self:drawActors()
|
||||
else
|
||||
for i=1, camNumber do
|
||||
self:drawMap(i)
|
||||
self:drawActors(i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function BaseWorld:drawActors()
|
||||
function BaseWorld:drawActors(id)
|
||||
self.cameras:attachView(id)
|
||||
local actors = self:getActors()
|
||||
for i,v in ipairs(actors) do
|
||||
v:draw()
|
||||
end
|
||||
self.cameras:detachView(id)
|
||||
end
|
||||
|
||||
function BaseWorld:drawMap()
|
||||
function BaseWorld:drawMap(id)
|
||||
local tx, ty, scale = 0, 0, 1
|
||||
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)
|
||||
scale = self.cameras:getViewScale(id) or 1
|
||||
|
||||
tx = math.floor(tx)
|
||||
ty = math.floor(ty)
|
||||
end
|
||||
|
||||
if self.haveMap then
|
||||
self.map:draw()
|
||||
self.map:draw(-tx, -ty, scale, scale)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -28,10 +28,13 @@ local World2D = BaseWorld:extend()
|
|||
|
||||
local Sti = require(cwd .. "libs.sti")
|
||||
local Bump = require(cwd .. "libs.bump")
|
||||
local CameraSystem = require(cwd .. "camera")
|
||||
|
||||
function World2D:new(scene, actorlist, mapfile)
|
||||
self.scene = scene
|
||||
|
||||
self.cameras = CameraSystem(self)
|
||||
|
||||
self:initPlayers()
|
||||
self:setActorList(actorlist)
|
||||
self:setMap(mapfile)
|
||||
|
|
Loading…
Reference in a new issue