more editor work on handling entity spawns

This commit is contained in:
lustlion 2022-03-10 10:21:10 +01:00
parent 6e76607030
commit 39b65571a0
10 changed files with 91 additions and 8 deletions

View File

@ -15,6 +15,10 @@ function Animation:new(anim_data,speed)
return o
end
function Animation:getCenteredOffset()
return self.imgs[1]:getWidth()/2, self.imgs[1]:getHeight()/2
end
function Animation:change(anim_data)
if anim_data.path == self.path
then

View File

@ -139,6 +139,7 @@ function drawEditor()
drawGameworldForeground()
endGameworldDraw()
doEditorEdit()
drawSpawns()
drawEditorRooms()
drawSelectingPaletteTile()
@ -206,15 +207,18 @@ function doEditorEdit()
and love.keyboard.isDown("lshift") ~= true
and love.keyboard.isDown("lctrl") ~= true
then
if Keybind:checkDown(Keybind.generic.lclick)
and selecting_tile ~= nil
then
setTile(vertical,horizontal,selecting_tile)
elseif Keybind:checkDown(Keybind.generic.rclick) then
setTile(vertical,horizontal,0)
if selecting_tile ~= nil then
if Keybind:checkDown(Keybind.generic.lclick) then
setTile(vertical,horizontal,selecting_tile)
elseif Keybind:checkDown(Keybind.generic.rclick) then
setTile(vertical,horizontal,0)
end
reloadLevelTiles()
else
if Keybind:checkDown(Keybind.generic.lclick) then
selectSpawns(mouse_x,mouse_y)
end
end
reloadLevelTiles()
elseif Keybind:checkPressed(Keybind.generic.lshift) then
expandLevelCanvas(math.sign(expand_h),math.sign(expand_v))
reloadLevelTiles()

View File

@ -1,5 +1,6 @@
CursedBook = Entity:new()
CursedBook.type = "CursedBook"
CursedBook.display = Animation:new(animation.cursed_book.flying)
function CursedBook:new(x,y)
local o = Entity:new(x,y)

View File

@ -1,5 +1,6 @@
Decoration = Entity:new()
Decoration.type = "Decoration"
Decoration.display = nil
function Decoration:new(x,y,animation,light_radius)
local o = Entity:new(x,y)

View File

@ -1,5 +1,6 @@
Fairy = Entity:new()
Fairy.type = "Fairy"
Fairy.display = Animation:new(animation.fairy.flying)
function Fairy:new(x,y)
local o = Entity:new(x,y)

View File

@ -1,5 +1,6 @@
HookAnchor = Entity:new()
HookAnchor.type = "HookAnchor"
HookAnchor.display = Animation:new(animation.fairy.flying)
function HookAnchor:new(x,y,hook_distance)
local o = Entity:new(x,y)

View File

@ -1,5 +1,6 @@
Kupo = Entity:new()
Kupo.type = "Kupo"
Kupo.display = Animation:new(animation.kupo.body)
function Kupo:new(x,y)
local o = Entity:new(x,y)

View File

@ -1,5 +1,6 @@
Player = Entity:new()
Player.type = "Player"
Player.display = Animation:new(animation.nancy.idle)
function Player:new(x,y)
local o = Entity:new(x,y)

View File

@ -128,6 +128,7 @@ function Keybind:default()
Keybind.generic.lclick = { keys = {1}}
Keybind.generic.rclick = { keys = {2}}
Keybind.generic.lshift = { keys = {"lshift"}}
Keybind.generic.alt = { keys = {"alt"}}
Keybind.generic.lctrl = { keys = {"lctrl"}}
end

View File

@ -13,3 +13,71 @@ function activateSpawns()
spawn.archetype:new(unpack(spawn.args))
end
end
function selectSpawns(x,y)
for _, spawn in pairs(LoadedObjects.Spawns) do
spawn.selected = nil
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 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 = ""
for i=1, #spawn.args do
text = text .. tostring(spawn.args[i])..", "
end
love.graphics.print(
spawn.archetype.type,
spawn.args[1] - Camera.pos.x + 20,
spawn.args[2] - Camera.pos.y
)
love.graphics.print(
text,
spawn.args[1] - Camera.pos.x + 20,
spawn.args[2] - Camera.pos.y + 20
)
end
end
end