Compare commits

..

No commits in common. "c97885571110c1bf8947fb2348e52aca67dbd876" and "2b9f605a0af85e201cfff54c2e5a2faa2c3f11f3" have entirely different histories.

8 changed files with 10 additions and 126 deletions

View File

@ -4,35 +4,6 @@ Camera = {
height = 0
}
function Camera:followPlayer(player)
local pos = player.pos
local room = player:getCollidingAt(pos.x,pos.y,LoadedObjects.Rooms)
self:positionCenterAt(pos.x, pos.y)
self:confineTo(room)
end
function Camera:confineTo(box)
if box == nil then
--frameDebug("not in a room")
return
end
--frameDebug("in a room")
local w = self.width/game.scale
local h = self.height/game.scale
-- bottom edge
self.pos.y = math.min(self.pos.y+h, box.to.y)-h
-- right edge
self.pos.x = math.min(self.pos.x+w, box.to.x)-w
-- top edge
self.pos.y = math.max(self.pos.y, box.from.y)
-- left edge
self.pos.x = math.max(self.pos.x, box.from.x)
end
function Camera:ConfineToLevel()
self.pos.x = math.max(0,math.min(self.pos.x,LevelData.Width-self.width/game.scale))
self.pos.y = math.max(0,math.min(self.pos.y,LevelData.Height-self.height/game.scale))
@ -41,7 +12,7 @@ end
function Camera:positionCenterAt(x,y)
self.pos.x = x-self.width/game.scale/2
self.pos.y = y-self.height/game.scale/2
--self:ConfineToLevel()
self:ConfineToLevel()
end
function Camera:positionAt(x,y)

View File

@ -4,8 +4,6 @@ LoadedObjects.Collisions = {}
LoadedObjects.Platforms = {}
LoadedObjects.Ladders = {}
LoadedObjects.Hazards = {}
LoadedObjects.Rooms = {}
--[[
Collision
@ -53,8 +51,6 @@ function Collision:New(ox,oy,tx,ty)
return o
end
function Collision:CenterAt(x, y)
self.from.x = x-self.width/2
self.from.y = y-self.height/2
@ -69,13 +65,6 @@ function Collision:PlaceAt(x, y)
self.to.y = self.from.x + self.height
end
function Collision:ContainsPoint(x, y)
return x >= self.from.x and
y >= self.from.y and
x <= self.to.x and
y <= self.to.y
end
function Collision:Draw(color)
if self.isColliding == true then
love.graphics.setColor(0,1,0,0.5)
@ -88,10 +77,3 @@ function Collision:Draw(color)
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)
end
function DrawRooms()
for _, room in pairs(LoadedObjects.Rooms) do
love.graphics.setColor(0,0,100,1)
love.graphics.rectangle("line",room.from.x-Camera.pos.x, room.from.y-Camera.pos.y, room.width, room.height)
end
end

View File

@ -93,21 +93,3 @@ end
function logWrite(string)
if logging then logFile:write(string.."\n") end
end
local frameDebug_lines = {}
-- used for debug output that will be printed every frame
function frameDebug(str)
table.insert(frameDebug_lines, str)
end
-- called at the end of each frame, draw everything passed to frameDebug this frame
function frameDebugFlush()
local y = 0
love.graphics.setColor(100, 100, 100, 0.8)
for _, str in ipairs(frameDebug_lines) do
love.graphics.print(str, 2, y)
y = y + 10
end
frameDebug_lines = {}
end

View File

@ -1,17 +1,6 @@
assert(editor == nil)
editor = { room_mode = false }
function EditorStep()
palette = palette or false
AnimateTiles()
if Keybind:CheckPressed(Keybind.editor.room_mode) then
if love.keyboard.isDown("lshift") then
editor.room_mode = "delete"
else
editor.room_mode = not editor.room_mode
end
editor.room_points = {}
end
if Keybind:CheckPressed(Keybind.editor.palette) then
if palette then
@ -24,18 +13,17 @@ function EditorStep()
palette_scroll_y = 0
end
end
-- TODO:
if love.keyboard.isDown('a',"left") then
Camera.pos.x = Camera.pos.x - 3/game.scale
Camera.pos.x = Camera.pos.x - 3*game.scale
end
if love.keyboard.isDown('d',"right") then
Camera.pos.x = Camera.pos.x + 3/game.scale
Camera.pos.x = Camera.pos.x + 3*game.scale
end
if love.keyboard.isDown("up", "w") then
Camera.pos.y = Camera.pos.y - 3/game.scale
Camera.pos.y = Camera.pos.y - 3*game.scale
end
if love.keyboard.isDown("down", "s") then
Camera.pos.y = Camera.pos.y + 3/game.scale
Camera.pos.y = Camera.pos.y + 3*game.scale
end
if palette then
@ -95,8 +83,6 @@ function EditorDraw()
GameworldDrawEnd()
EditorDoEdit()
DrawRooms()
DrawSelectingPaletteTile()
if palette then
EditorDoPalette()
@ -123,39 +109,10 @@ function EditorDoEdit()
elseif vertical < 0 then
expand_v = vertical
end
love.graphics.setColor(100, 100, 100, 0.8)
love.graphics.print("> " .. horizontal .. ", " .. vertical .. "; " .. math.floor(mouse_x / game.scale + Camera.pos.x) .. ", " .. math.floor(mouse_y / game.scale + Camera.pos.y))
love.graphics.print("> " .. LevelWidth .. "(" .. expand_h .. "), " .. LevelHeight .. "(".. expand_v .. ")", 0, 10)
if editor.room_mode then
local rx = horizontal * tileProperties.width
local ry = vertical * tileProperties.height
local r = editor.room_points
if Keybind:CheckPressed(Keybind.generic.rclick) then
editor.room_points = {}
elseif Keybind:CheckPressed(Keybind.generic.lclick) then
if editor.room_mode == "delete" then
for i, room in ipairs(LoadedObjects.Rooms) do
if room:ContainsPoint(rx, ry) then
table.remove(LoadedObjects.Rooms, i)
end
end
else
table.insert(r, { x = rx, y = ry })
end
end
if #editor.room_points == 2 then
table.insert(LoadedObjects.Rooms, Collision:New(r[1].x,r[1].y,r[2].x,r[2].y))
editor.room_points = {}
end
if editor.room_mode == "delete" then
love.graphics.print("Select room to delete", 0, 20)
elseif #editor.room_points == 0 then
love.graphics.print("Select top left of new room", 0, 20)
else
love.graphics.print("Select bottom right of new room", 0, 20)
end
elseif not palette then
if not palette then
if LevelTiles[vertical] ~= nil
and LevelTiles[vertical][horizontal] ~= nil
and love.keyboard.isDown("lshift") ~= true

View File

@ -162,10 +162,6 @@ end
-- checks if the the reciever would collide with an object if it was positioned at the given point.
-- also marks collisioned tile as collision true
function Entity:isCollidingAt(x,y,object)
return self:getCollidingAt(x,y,object) ~= nil
end
function Entity:getCollidingAt(x,y,object)
for _, collision in pairs(object) do
if collision.disable then
-- Dont calculate if disabled
@ -175,10 +171,10 @@ function Entity:getCollidingAt(x,y,object)
and y + self.boxCollision.to.y > collision.from.y
then
collision.isColliding = true
return collision
return true
end
end
return nil
return false
end
function Entity:isCollidingWith(entity)

View File

@ -17,8 +17,7 @@ function GameStep()
end
AnimateTiles()
Camera:followPlayer(main_Player)
--Camera:positionCenterAt(main_Player.pos.x, main_Player.pos.y)
Camera:positionCenterAt(main_Player.pos.x, main_Player.pos.y)
--camera:positionAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height)
if Keybind:CheckPressed(Keybind.debug.debug) then

View File

@ -101,8 +101,7 @@ function Keybind:Default()
-- Editor
Keybind.editor.palette = { keys = {"tab"}}
Keybind.editor.room_mode = { keys = {"r"}}
-- Generic
Keybind.generic.lclick = { keys = {1}}
Keybind.generic.rclick = { keys = {2}}

View File

@ -133,6 +133,4 @@ function love.draw()
love.graphics.print(game.scale,10,40)
if DemoRecording or DemoPlayback then Demo:Draw() end
frameDebugFlush()
end