2019-07-22 22:38:19 +02:00
|
|
|
local ParentMap = Object:extend()
|
|
|
|
|
|
|
|
-- INIT FUNCTION
|
|
|
|
-- Initialize the map
|
|
|
|
|
|
|
|
function ParentMap:new(world, r, g, b)
|
|
|
|
self.world = world
|
|
|
|
|
|
|
|
local r = r or 128
|
|
|
|
local g = g or 128
|
|
|
|
local b = b or 128
|
|
|
|
self.backgroundColor = {r, g, b}
|
|
|
|
|
2019-07-26 11:53:10 +02:00
|
|
|
self:setPadding()
|
2019-07-22 22:38:19 +02:00
|
|
|
self:register()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ParentMap:register()
|
|
|
|
self.world.map = self
|
|
|
|
end
|
|
|
|
|
2019-07-26 11:53:10 +02:00
|
|
|
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
|
|
|
|
|
2019-07-22 22:38:19 +02:00
|
|
|
-- UPDATE FUNCTION
|
|
|
|
-- Update or modify the map
|
|
|
|
|
|
|
|
function ParentMap:resize(w, h)
|
|
|
|
-- Empty Placeholder function
|
|
|
|
end
|
|
|
|
|
|
|
|
function ParentMap:update(dt)
|
|
|
|
-- Empty Placeholder function
|
|
|
|
end
|
|
|
|
|
|
|
|
function ParentMap:loadObjects()
|
|
|
|
self:loadCollisions()
|
|
|
|
self:loadPlayers()
|
|
|
|
self:loadActors()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ParentMap:loadCollisions()
|
|
|
|
-- Empty Placeholder function
|
|
|
|
end
|
|
|
|
|
|
|
|
function ParentMap:loadPlayers()
|
|
|
|
-- Empty Placeholder function
|
|
|
|
end
|
|
|
|
|
|
|
|
function ParentMap:loadActors()
|
|
|
|
-- Empty Placeholder function
|
|
|
|
end
|
|
|
|
|
|
|
|
function ParentMap:setBackgroundColor(r, g, b)
|
|
|
|
local r = r or 128
|
|
|
|
local g = g or 128
|
|
|
|
local b = b or 128
|
|
|
|
self.backgroundColor = {r, g, b}
|
|
|
|
end
|
|
|
|
|
|
|
|
function ParentMap:setBackgroundColorFromTable(backgroundColor)
|
|
|
|
self.backgroundColor = backgroundColor or {128, 128, 128}
|
|
|
|
end
|
|
|
|
|
|
|
|
function ParentMap:getBackgroundColor()
|
|
|
|
return self.backgroundColor[1]/256, self.backgroundColor[2]/256, self.backgroundColor[3]/256
|
|
|
|
end
|
|
|
|
|
2019-07-26 11:53:10 +02:00
|
|
|
function ParentMap:getPadding()
|
|
|
|
return self.padding.x1, self.padding.y1, self.padding.x2, self.padding.y2
|
|
|
|
end
|
|
|
|
|
2019-07-22 22:38:19 +02:00
|
|
|
function ParentMap:getDimensions()
|
|
|
|
return core.screen:getDimensions()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ParentMap:getBox()
|
2019-07-26 11:53:10 +02:00
|
|
|
local x1, y1, x2, y2 = self:getPadding()
|
2019-07-22 22:38:19 +02:00
|
|
|
local w, h = self:getDimensions()
|
2019-07-26 11:53:10 +02:00
|
|
|
return -x1, -y1, w+x2, h+y2
|
2019-07-22 22:38:19 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ParentMap:drawBackgroundColor()
|
|
|
|
local r, g, b = self.backgroundColor[1], self.backgroundColor[2], self.backgroundColor[3]
|
|
|
|
love.graphics.setColor(r/256, g/256, b/256)
|
|
|
|
love.graphics.rectangle("fill", 0, 0, 480, 272)
|
|
|
|
utils.graphics.resetColor()
|
|
|
|
end
|
|
|
|
|
|
|
|
return ParentMap
|