feat(camera+map): add a way to add padding to map limits

This commit is contained in:
Kazhnuz 2019-07-26 11:53:10 +02:00
parent 9ea2d2ca40
commit ca721ec8ac
3 changed files with 21 additions and 3 deletions

View file

@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **core:** add a way to activate easily debug mode directly - **core:** add a way to activate easily debug mode directly
- **camera+maps:** add a way to add padding to map limits
### Changed ### Changed
- **world:** extract map module from the world module - **world:** extract map module from the world module

View file

@ -274,8 +274,8 @@ function CameraSystem:limitView(id)
local posy = self.views.list[id].y local posy = self.views.list[id].y
local minx = worldx + self.views.width / 2 local minx = worldx + self.views.width / 2
local miny = worldy + self.views.height / 2 local miny = worldy + self.views.height / 2
local maxx = worldw - minx local maxx = worldw - self.views.width / 2
local maxy = worldh - miny local maxy = worldh - self.views.height / 2
self.views.list[id].x = utils.math.between(posx, minx, maxx) self.views.list[id].x = utils.math.between(posx, minx, maxx)
self.views.list[id].y = utils.math.between(posy, miny, maxy) self.views.list[id].y = utils.math.between(posy, miny, maxy)

View file

@ -11,6 +11,7 @@ function ParentMap:new(world, r, g, b)
local b = b or 128 local b = b or 128
self.backgroundColor = {r, g, b} self.backgroundColor = {r, g, b}
self:setPadding()
self:register() self:register()
end end
@ -18,6 +19,16 @@ function ParentMap:register()
self.world.map = self self.world.map = self
end end
function ParentMap:setPadding(x1, y1, x2, y2)
local padding = {}
padding.x1 = x1 or 0
padding.y1 = y1 or padding.x1
padding.x2 = x2 or padding.x1
padding.y2 = y2 or padding.y1
self.padding = padding
end
-- UPDATE FUNCTION -- UPDATE FUNCTION
-- Update or modify the map -- Update or modify the map
@ -62,13 +73,18 @@ function ParentMap:getBackgroundColor()
return self.backgroundColor[1]/256, self.backgroundColor[2]/256, self.backgroundColor[3]/256 return self.backgroundColor[1]/256, self.backgroundColor[2]/256, self.backgroundColor[3]/256
end end
function ParentMap:getPadding()
return self.padding.x1, self.padding.y1, self.padding.x2, self.padding.y2
end
function ParentMap:getDimensions() function ParentMap:getDimensions()
return core.screen:getDimensions() return core.screen:getDimensions()
end end
function ParentMap:getBox() function ParentMap:getBox()
local x1, y1, x2, y2 = self:getPadding()
local w, h = self:getDimensions() local w, h = self:getDimensions()
return 0, 0, w, h return -x1, -y1, w+x2, h+y2
end end
function ParentMap:drawBackgroundColor() function ParentMap:drawBackgroundColor()