Skip to content
Snippets Groups Projects
Commit 47efc042 authored by dg's avatar dg
Browse files

scrolls map bounded

git-svn-id: http://svn.net-core.org/repos/t-engine4@46 51575b47-30f0-44d4-a5cc-537603b46e54
parent 06ed3f5e
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ setmetatable(__uids, {__mode="v"})
function _M:init(t)
t = t or {}
self.uid = next_uid
-- __uids[self.uid] = self
__uids[self.uid] = self
for k, e in pairs(t) do self[k] = e end
......@@ -37,7 +37,14 @@ end
-- If we are cloned we need a new uid
function _M:cloned()
self.uid = next_uid
-- __uids[self.uid] = self
__uids[self.uid] = self
next_uid = next_uid + 1
end
-- If we are loaded we need a new uid
function _M:loaded()
self.uid = next_uid
__uids[self.uid] = self
next_uid = next_uid + 1
end
......
......@@ -270,4 +270,27 @@ function _M:centerViewAround(x, y)
self.mx = x - math.floor(self.viewport.mwidth / 2)
self.my = y - math.floor(self.viewport.mheight / 2)
self.changed = true
self:checkMapViewBounded()
end
--- Sets the current view area if x and y are out of bounds
function _M:moveViewSurround(x, y, marginx, marginy)
if self.mx + marginx >= x or self.mx + self.viewport.mwidth - marginx <= x then
self.mx = x - math.floor(self.viewport.mwidth / 2)
self.changed = true
end
if self.my + marginy >= y or self.my + self.viewport.mheight - marginy <= y then
self.my = y - math.floor(self.viewport.mheight / 2)
self.changed = true
end
self:checkMapViewBounded()
end
--- Checks the map is bound to the screen (no "empty space" if the map is big enough)
function _M:checkMapViewBounded()
if self.mx < 0 then self.mx = 0 self.changed = true end
if self.my < 0 then self.my = 0 self.changed = true end
if self.mx > self.w - self.viewport.mwidth then self.mx = self.w - self.viewport.mwidth self.changed = true end
if self.my > self.h - self.viewport.mheight then self.my = self.h - self.viewport.mheight self.changed = true end
end
......@@ -13,7 +13,7 @@ end
function _M:move(x, y, force)
local moved = mod.class.Actor.move(self, x, y, force)
if moved then
game.level.map:centerViewAround(self.x, self.y)
game.level.map:moveViewSurround(self.x, self.y, 4, 4)
end
return moved
end
......
......@@ -7,7 +7,7 @@ return {
level_npcs = {5, 10},
generator = {
map = {
class= "engine.generator.map.Rooms",
class= "engine.generator.map.Empty",
floor = "FLOOR",
wall = "WALL",
up = "UP",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment