added rooms
This commit is contained in:
@@ -4,6 +4,35 @@ Camera = {
|
||||
height = 0
|
||||
}
|
||||
|
||||
function Camera:followPlayer(player)
|
||||
local pos = player.pos
|
||||
local room = player:getCollidingAt(pos.x,pos.y,LoadedObjects.Rooms)
|
||||
|
||||
self:positionCenterAt(pos.x, pos.y)
|
||||
|
||||
self:confineTo(room)
|
||||
end
|
||||
|
||||
function Camera:confineTo(box)
|
||||
if box == nil then
|
||||
--frameDebug("not in a room")
|
||||
return
|
||||
end
|
||||
--frameDebug("in a room")
|
||||
|
||||
local w = self.width/game.scale
|
||||
local h = self.height/game.scale
|
||||
|
||||
-- bottom edge
|
||||
self.pos.y = math.min(self.pos.y+h, box.to.y)-h
|
||||
-- right edge
|
||||
self.pos.x = math.min(self.pos.x+w, box.to.x)-w
|
||||
-- top edge
|
||||
self.pos.y = math.max(self.pos.y, box.from.y)
|
||||
-- left edge
|
||||
self.pos.x = math.max(self.pos.x, box.from.x)
|
||||
end
|
||||
|
||||
function Camera:ConfineToLevel()
|
||||
self.pos.x = math.max(0,math.min(self.pos.x,LevelData.Width-self.width/game.scale))
|
||||
self.pos.y = math.max(0,math.min(self.pos.y,LevelData.Height-self.height/game.scale))
|
||||
@@ -12,7 +41,7 @@ end
|
||||
function Camera:positionCenterAt(x,y)
|
||||
self.pos.x = x-self.width/game.scale/2
|
||||
self.pos.y = y-self.height/game.scale/2
|
||||
self:ConfineToLevel()
|
||||
--self:ConfineToLevel()
|
||||
end
|
||||
|
||||
function Camera:positionAt(x,y)
|
||||
|
||||
Reference in New Issue
Block a user