Browse Source

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

master
Kazhnuz 4 months ago
parent
commit
ca721ec8ac
3 changed files with 21 additions and 3 deletions
  1. 2
    0
      CHANGELOG.md
  2. 2
    2
      gamecore/modules/world/camera/init.lua
  3. 17
    1
      gamecore/modules/world/maps/parent.lua

+ 2
- 0
CHANGELOG.md 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

- **camera+maps:** add a way to add padding to map limits

### Changed

- **world:** extract map module from the world module

+ 2
- 2
gamecore/modules/world/camera/init.lua View File

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

self.views.list[id].x = utils.math.between(posx, minx, maxx)
self.views.list[id].y = utils.math.between(posy, miny, maxy)

+ 17
- 1
gamecore/modules/world/maps/parent.lua View File

@@ -11,6 +11,7 @@ function ParentMap:new(world, r, g, b)
local b = b or 128
self.backgroundColor = {r, g, b}

self:setPadding()
self:register()
end

@@ -18,6 +19,16 @@ function ParentMap:register()
self.world.map = self
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 or modify the map

@@ -62,13 +73,18 @@ function ParentMap:getBackgroundColor()
return self.backgroundColor[1]/256, self.backgroundColor[2]/256, self.backgroundColor[3]/256
end

function ParentMap:getPadding()
return self.padding.x1, self.padding.y1, self.padding.x2, self.padding.y2
end

function ParentMap:getDimensions()
return core.screen:getDimensions()
end

function ParentMap:getBox()
local x1, y1, x2, y2 = self:getPadding()
local w, h = self:getDimensions()
return 0, 0, w, h
return -x1, -y1, w+x2, h+y2
end

function ParentMap:drawBackgroundColor()

Loading…
Cancel
Save