Compare commits
No commits in common. "829963e080bfc2ce4a60d9c92f85835af1f62c17" and "3a5e0b395bc880bf5c8f3685e1d1cbbde4955ebc" have entirely different histories.
829963e080
...
3a5e0b395b
@ -77,16 +77,3 @@ function Camera:positionAt(x,y)
|
|||||||
self.pos.y = math.floor((y/self.height)*self.height)
|
self.pos.y = math.floor((y/self.height)*self.height)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- translate screen coordinates to game coordinates
|
|
||||||
function Camera:ptScreenToGame(pt)
|
|
||||||
return self.pos + pt
|
|
||||||
end
|
|
||||||
|
|
||||||
function Camera:mouseScreenPos()
|
|
||||||
return Point:new(love.mouse.getX(),love.mouse.getY()) / game.scale
|
|
||||||
end
|
|
||||||
|
|
||||||
-- return the mouse position as game coordinates
|
|
||||||
function Camera:mouseGamePos()
|
|
||||||
return self:ptScreenToGame(self:mouseScreenPos())
|
|
||||||
end
|
|
||||||
|
@ -88,7 +88,3 @@ function Collision:draw(color)
|
|||||||
love.graphics.setColor(0,1,90,0.5)
|
love.graphics.setColor(0,1,90,0.5)
|
||||||
love.graphics.rectangle("line",self.from.x-Camera.pos.x, self.from.y-Camera.pos.y, self.width, self.height)
|
love.graphics.rectangle("line",self.from.x-Camera.pos.x, self.from.y-Camera.pos.y, self.width, self.height)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Collision:asRect()
|
|
||||||
return Rect:fromCoords(self.from.x, self.from.y, self.to.x, self.to.y)
|
|
||||||
end
|
|
||||||
|
@ -1,36 +1,17 @@
|
|||||||
assert(editor == nil)
|
assert(editor == nil)
|
||||||
editor = {
|
editor = {
|
||||||
active = false,
|
|
||||||
room_mode = false,
|
room_mode = false,
|
||||||
|
--palette_mode = false,
|
||||||
palette = {
|
palette = {
|
||||||
active = false,
|
active = false,
|
||||||
scroll = Point:new(0, 0),
|
scroll = Point:new(0, 0),
|
||||||
},
|
},
|
||||||
multiselect = {
|
|
||||||
active = false,
|
|
||||||
sweeping = false,
|
|
||||||
box = nil,
|
|
||||||
},
|
|
||||||
pan = { fixed = false, speed = 3 },
|
pan = { fixed = false, speed = 3 },
|
||||||
}
|
}
|
||||||
|
|
||||||
function stepEditor()
|
function stepEditor()
|
||||||
|
|
||||||
animateTiles()
|
animateTiles()
|
||||||
local osweep = editor.multiselect.sweeping
|
|
||||||
editor.multiselect.sweeping = love.mouse.isDown(2)
|
|
||||||
frameDebug("sweeping: "..tostring(editor.multiselect.sweeping))
|
|
||||||
if editor.multiselect.sweeping and not editor.multiselect.active then
|
|
||||||
print("multiselect enabled")
|
|
||||||
editor.multiselect.active = true
|
|
||||||
end
|
|
||||||
if not osweep and osweep ~= editor.multiselect.sweeping then
|
|
||||||
editor.multiselect.box = nil
|
|
||||||
end
|
|
||||||
if editor.multiselect.active then
|
|
||||||
doEditorMultiselect()
|
|
||||||
end
|
|
||||||
|
|
||||||
if Keybind:checkPressed(Keybind.editor.room_mode) then
|
if Keybind:checkPressed(Keybind.editor.room_mode) then
|
||||||
if love.keyboard.isDown("lshift") then
|
if love.keyboard.isDown("lshift") then
|
||||||
editor.room_mode = "delete"
|
editor.room_mode = "delete"
|
||||||
@ -108,6 +89,13 @@ function stepEditor()
|
|||||||
end,
|
end,
|
||||||
}):activate()
|
}):activate()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Keybind:checkPressed(Keybind.debug.editor) then
|
||||||
|
editor_mode = not editor_mode
|
||||||
|
deselectSpawns()
|
||||||
|
createTileObjects()
|
||||||
|
restartGame()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function scrollEditor(y)
|
function scrollEditor(y)
|
||||||
@ -140,10 +128,6 @@ function drawEditor()
|
|||||||
if editor.palette.active then
|
if editor.palette.active then
|
||||||
doEditorPalette()
|
doEditorPalette()
|
||||||
end
|
end
|
||||||
if editor.multiselect.box ~= nil then
|
|
||||||
frameDebug("drawing multiselect "..tostring(editor.multiselect.box))
|
|
||||||
drawEditorMultiselect()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function doEditorEdit()
|
function doEditorEdit()
|
||||||
@ -370,25 +354,6 @@ end
|
|||||||
function drawEditorRooms()
|
function drawEditorRooms()
|
||||||
for _, room in pairs(LoadedObjects.Rooms) do
|
for _, room in pairs(LoadedObjects.Rooms) do
|
||||||
love.graphics.setColor(0,0,100,1)
|
love.graphics.setColor(0,0,100,1)
|
||||||
room:asRect():draw("line")
|
love.graphics.rectangle("line",room.from.x-Camera.pos.x, room.from.y-Camera.pos.y, room.width, room.height)
|
||||||
--love.graphics.rectangle("line",room.from.x-Camera.pos.x, room.from.y-Camera.pos.y, room.width, room.height)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawEditorMultiselect()
|
|
||||||
love.graphics.setColor(100,100,50,1)
|
|
||||||
editor.multiselect.box:draw("line")
|
|
||||||
end
|
|
||||||
|
|
||||||
function doEditorMultiselect()
|
|
||||||
local mousept = Camera:mouseGamePos()
|
|
||||||
if editor.multiselect.box == nil then
|
|
||||||
print("sweep started")
|
|
||||||
editor.multiselect.box = Rect:fromPoints(mousept, mousept)
|
|
||||||
print("box: "..tostring(editor.multiselect.box))
|
|
||||||
elseif editor.multiselect.sweeping then
|
|
||||||
editor.multiselect.box.max = mousept
|
|
||||||
frameDebug("swept to "..tostring(mousept))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
@ -53,6 +53,10 @@ function stepGame()
|
|||||||
initMenu("dialog",dialog_sequence.example)
|
initMenu("dialog",dialog_sequence.example)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Keybind:checkPressed(Keybind.debug.editor) then
|
||||||
|
editor_mode = true
|
||||||
|
end
|
||||||
|
|
||||||
if Keybind:checkPressed(Keybind.debug.recording) then
|
if Keybind:checkPressed(Keybind.debug.recording) then
|
||||||
if DemoRecording then
|
if DemoRecording then
|
||||||
Demo:endRecord()
|
Demo:endRecord()
|
||||||
|
@ -1,75 +0,0 @@
|
|||||||
-- based of of plan9's Rectangle struct
|
|
||||||
-- rect.max is not counted as "in" the rectangle
|
|
||||||
Rect = {}
|
|
||||||
Rect.__index = Rect
|
|
||||||
|
|
||||||
function Rect:fromPoints(pt1, pt2)
|
|
||||||
local o = { min = pt1, max = pt2 }
|
|
||||||
setmetatable(o, self)
|
|
||||||
return o
|
|
||||||
end
|
|
||||||
|
|
||||||
function Rect:fromCoords(x1, y1, x2, y2)
|
|
||||||
return Rect:fromPoints(Point:new(x1, y1), Point:new(x2, y2))
|
|
||||||
end
|
|
||||||
|
|
||||||
-- clone refers to a deep copy
|
|
||||||
function Rect:clone()
|
|
||||||
return Rect:fromCoods(self.min.x, self.min.y, self.max.x, self.max.y)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- make sure min and max refer to the correct corners
|
|
||||||
-- acts in place, returns self
|
|
||||||
function Rect:fix()
|
|
||||||
if self.min.x > self.max.x then
|
|
||||||
self.min.x, self.max.x = self.max.x, self.min.x
|
|
||||||
end
|
|
||||||
if self.min.y > self.max.y then
|
|
||||||
self.min.y, self.max.y = self.max.y, self.min.y
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Rect:width()
|
|
||||||
return self.max.x - self.min.x
|
|
||||||
end
|
|
||||||
|
|
||||||
function Rect:height()
|
|
||||||
return self.max.y - self.min.y
|
|
||||||
end
|
|
||||||
|
|
||||||
function Rect:size()
|
|
||||||
return Point:new(self:width(), self:height())
|
|
||||||
end
|
|
||||||
|
|
||||||
function Rect:__add(pt)
|
|
||||||
return Rect:fromPoints(self.min + pt, self.max + pt)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Rect:corners()
|
|
||||||
return {
|
|
||||||
self.min:copy(), -- top left
|
|
||||||
Point:new(self.max.x, self.min.y), -- top right
|
|
||||||
Point:new(self.min.x, self.max.y), -- bottom left
|
|
||||||
self.max:copy(), -- bottom right
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
function Rect:containsPoint(pt)
|
|
||||||
return self.min.x < pt.x and
|
|
||||||
self.min.y < pt.y and
|
|
||||||
pt.x < self.max.x and
|
|
||||||
pt.y < self.max.y
|
|
||||||
end
|
|
||||||
|
|
||||||
function Rect:overlapsRect(other)
|
|
||||||
return self.min.x<other.max.x and self.min.x<other.max.x and
|
|
||||||
self.min.y<other.max.y and self.min.y<other.max.y
|
|
||||||
end
|
|
||||||
|
|
||||||
function Rect:draw(style)
|
|
||||||
love.graphics.rectangle(style, self.min.x - Camera.pos.x, self.min.y - Camera.pos.y, self:width(), self:height())
|
|
||||||
end
|
|
||||||
|
|
||||||
function Rect:__tostring()
|
|
||||||
return "Rect["..tostring(self.min).." "..tostring(self.max).."]"
|
|
||||||
end
|
|
@ -14,7 +14,6 @@ require "code/in_out"
|
|||||||
|
|
||||||
-- classes
|
-- classes
|
||||||
require "code/point"
|
require "code/point"
|
||||||
require "code/rect"
|
|
||||||
require "code/objects"
|
require "code/objects"
|
||||||
require "code/level"
|
require "code/level"
|
||||||
require "code/camera"
|
require "code/camera"
|
||||||
|
18
main.lua
18
main.lua
@ -6,10 +6,9 @@ function love.load()
|
|||||||
secs = 0
|
secs = 0
|
||||||
|
|
||||||
menu_type = "no"
|
menu_type = "no"
|
||||||
-- FIXME: this overrides a standard library!
|
|
||||||
debug = false
|
debug = false
|
||||||
debug_collision = false
|
debug_collision = false
|
||||||
--editor_mode = false
|
editor_mode = false
|
||||||
|
|
||||||
text_size = 1
|
text_size = 1
|
||||||
|
|
||||||
@ -104,15 +103,6 @@ function love.update(dt)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if Keybind:checkPressed(Keybind.debug.editor) then
|
|
||||||
if editor.active then
|
|
||||||
deselectSpawns()
|
|
||||||
createTileObjects()
|
|
||||||
restartGame()
|
|
||||||
end
|
|
||||||
editor.active = not editor.active
|
|
||||||
end
|
|
||||||
|
|
||||||
if love.keyboard.isDown("f7") then
|
if love.keyboard.isDown("f7") then
|
||||||
local test_prompt = Prompt:new({
|
local test_prompt = Prompt:new({
|
||||||
name = "test prompt",
|
name = "test prompt",
|
||||||
@ -137,7 +127,7 @@ function love.update(dt)
|
|||||||
if menu_type ~= nil then stepMenu(menu_type) end
|
if menu_type ~= nil then stepMenu(menu_type) end
|
||||||
|
|
||||||
--editor
|
--editor
|
||||||
if editor.active then
|
if editor_mode then
|
||||||
stepEditor()
|
stepEditor()
|
||||||
else
|
else
|
||||||
stepGame()
|
stepGame()
|
||||||
@ -146,7 +136,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function love.wheelmoved(_, y)
|
function love.wheelmoved(_, y)
|
||||||
if editor.active then
|
if editor_mode then
|
||||||
scrollEditor(y)
|
scrollEditor(y)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -160,7 +150,7 @@ function love.draw()
|
|||||||
game_resize = false
|
game_resize = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if editor.active then
|
if editor_mode then
|
||||||
drawEditor()
|
drawEditor()
|
||||||
else
|
else
|
||||||
drawGame()
|
drawGame()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user