94 lines
2.4 KiB
Lua
94 lines
2.4 KiB
Lua
LoadedObjects.Spawns = {}
|
|
|
|
function addSpawn(archetype, ...)
|
|
local o = {
|
|
archetype = archetype,
|
|
args = {...}
|
|
}
|
|
table.insert(LoadedObjects.Spawns, o)
|
|
end
|
|
|
|
function activateSpawns()
|
|
for _, spawn in pairs(LoadedObjects.Spawns) do
|
|
spawn.archetype:new(unpack(spawn.args))
|
|
end
|
|
end
|
|
|
|
function deselectSpawns()
|
|
for _, spawn in pairs(LoadedObjects.Spawns) do
|
|
spawn.selected = nil
|
|
end
|
|
end
|
|
|
|
function selectSpawns(x,y)
|
|
for _, spawn in pairs(LoadedObjects.Spawns) do
|
|
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
|
|
local left = spawn.args[1] - Camera.pos.x - offset_x
|
|
local top = spawn.args[2] - Camera.pos.y - offset_y
|
|
local right = spawn.args[1] - Camera.pos.x + offset_x
|
|
local bottom = spawn.args[2] - Camera.pos.y + offset_y
|
|
local x = (x / game.scale)
|
|
local y = (y / game.scale)
|
|
if x >= left and y >= top and x <= right and y <= bottom then
|
|
spawn.selected = true
|
|
end
|
|
|
|
if spawn.selected then
|
|
love.graphics.setColor(0,1,1,1)
|
|
else
|
|
love.graphics.setColor(0,1,0,1)
|
|
end
|
|
|
|
love.graphics.rectangle("fill",left-2,top-2,4,4)
|
|
love.graphics.rectangle("fill",right-2,bottom-2,4,4)
|
|
love.graphics.setColor(1,1,1,1)
|
|
end
|
|
end
|
|
|
|
function moveSpawns(x,y)
|
|
for _, spawn in pairs(LoadedObjects.Spawns) do
|
|
if spawn.selected then
|
|
spawn.args[1] = math.floor(x/game.scale)+Camera.pos.x
|
|
spawn.args[2] = math.floor(y/game.scale)+Camera.pos.y
|
|
end
|
|
end
|
|
end
|
|
|
|
function drawSpawns()
|
|
for _, spawn in pairs(LoadedObjects.Spawns) do
|
|
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
|
|
love.graphics.setColor(1,1,1,1)
|
|
spawn.archetype.display:draw(
|
|
spawn.args[1] - Camera.pos.x - offset_x,
|
|
spawn.args[2] - Camera.pos.y - offset_y
|
|
)
|
|
|
|
if spawn.selected then
|
|
love.graphics.setColor(0,1,1,1)
|
|
else
|
|
love.graphics.setColor(0,1,0,1)
|
|
end
|
|
|
|
love.graphics.rectangle(
|
|
"line",
|
|
spawn.args[1] - Camera.pos.x - offset_x,
|
|
spawn.args[2] - Camera.pos.y - offset_y,
|
|
spawn.args[1] - Camera.pos.x + offset_x - (spawn.args[1] - Camera.pos.x - offset_x),
|
|
spawn.args[2] - Camera.pos.y + offset_y - (spawn.args[2] - Camera.pos.y - offset_y)
|
|
)
|
|
|
|
if spawn.selected then
|
|
local text = spawn.archetype.type.."\n["..spawn.args[1]..","..spawn.args[2].."]\n"
|
|
for i=3, #spawn.args do
|
|
if i > 3 then text = text .. ", " end
|
|
text = text .. tostring(spawn.args[i])
|
|
end
|
|
love.graphics.print(
|
|
text,
|
|
spawn.args[1] - Camera.pos.x + 20,
|
|
spawn.args[2] - Camera.pos.y
|
|
)
|
|
end
|
|
end
|
|
end
|