naming convention for most stuff but not all

This commit is contained in:
lustlion 2022-03-04 23:28:30 +01:00
parent c978855711
commit cef2096577
29 changed files with 354 additions and 436 deletions

View File

@ -1,6 +1,6 @@
Animation = {} Animation = {}
function Animation:New(anim_data) function Animation:new(anim_data)
local o = {} local o = {}
o.path = anim_data.path o.path = anim_data.path
@ -14,17 +14,17 @@ function Animation:New(anim_data)
return o return o
end end
function Animation:ChangeTo(anim_data) function Animation:change(anim_data)
if anim_data.path == self.path if anim_data.path == self.path
then then
return self return self
else else
return Animation:New(anim_data) return Animation:new(anim_data)
end end
end end
-- to manually handle what frame -- to manually handle what frame
function Animation:DrawFrame(frame, x, y, rotate, sx, sy) function Animation:drawFrame(frame, x, y, rotate, sx, sy)
if frame > #self.frames then if frame > #self.frames then
frame = #self.frames frame = #self.frames
end end
@ -43,7 +43,7 @@ function Animation:DrawFrame(frame, x, y, rotate, sx, sy)
end end
-- to linearly animate -- to linearly animate
function Animation:Animate() function Animation:animate()
if self.frames[self.frame] ~= 0 then if self.frames[self.frame] ~= 0 then
-- try to animate -- try to animate
self.subframe = self.subframe + current_dt self.subframe = self.subframe + current_dt
@ -61,7 +61,7 @@ function Animation:Animate()
end end
-- to draw the current frame -- to draw the current frame
function Animation:Draw(x, y, rotate, sx, sy) function Animation:draw(x, y, rotate, sx, sy)
local x = x or 0 local x = x or 0
local y = y or 0 local y = y or 0
local sx = sx or 1 local sx = sx or 1

View File

@ -33,7 +33,7 @@ function Camera:confineTo(box)
self.pos.x = math.max(self.pos.x, box.from.x) self.pos.x = math.max(self.pos.x, box.from.x)
end end
function Camera:ConfineToLevel() function Camera:confineToLevel()
self.pos.x = math.max(0,math.min(self.pos.x,LevelData.Width-self.width/game.scale)) 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)) self.pos.y = math.max(0,math.min(self.pos.y,LevelData.Height-self.height/game.scale))
end end

View File

@ -1,6 +1,6 @@
Canvas = {class = "Canvas"} Canvas = {class = "Canvas"}
function Canvas:New(name) function Canvas:new(name)
local o = {} local o = {}
o.name = name o.name = name
o.width = game.width/game.scale o.width = game.width/game.scale
@ -12,12 +12,12 @@ function Canvas:New(name)
return o return o
end end
function Canvas:Recreate() function Canvas:recreate()
self.canvas:release() self.canvas:release()
self.canvas = love.graphics.newCanvas(self.width,self.height) self.canvas = love.graphics.newCanvas(self.width,self.height)
end end
function Canvas:Reset() function Canvas:reset()
love.graphics.setCanvas(self.canvas) love.graphics.setCanvas(self.canvas)
love.graphics.setBlendMode("replace") love.graphics.setBlendMode("replace")
love.graphics.setColor(0,0,0,0) love.graphics.setColor(0,0,0,0)
@ -31,18 +31,18 @@ function Canvas:Reset()
love.graphics.setCanvas() love.graphics.setCanvas()
end end
function Canvas:DrawingStart() function Canvas:startDrawing()
self:Reset() self:reset()
love.graphics.setCanvas(self.canvas) love.graphics.setCanvas(self.canvas)
end end
function Canvas:DrawingEnd() function Canvas:endDrawing()
love.graphics.setCanvas() love.graphics.setCanvas()
love.graphics.setBlendMode("alpha") love.graphics.setBlendMode("alpha")
love.graphics.setColor(1,1,1,1) love.graphics.setColor(1,1,1,1)
end end
function Canvas:Draw() function Canvas:draw()
love.graphics.draw(self.canvas) love.graphics.draw(self.canvas)
end end

View File

@ -1,6 +1,6 @@
Canvas.Darkness = Canvas:New("Darkness") Canvas.Darkness = Canvas:new("Darkness")
function Canvas.Darkness:Reset() function Canvas.Darkness:reset()
love.graphics.setCanvas(Canvas.Darkness.canvas) love.graphics.setCanvas(Canvas.Darkness.canvas)
love.graphics.setBlendMode("replace") love.graphics.setBlendMode("replace")
love.graphics.setColor(0,0,0,0.95) love.graphics.setColor(0,0,0,0.95)

View File

@ -30,7 +30,7 @@ LoadedObjects.Rooms = {}
--]] --]]
-- can also be called with only ox and oy, where they become the width and height instead -- can also be called with only ox and oy, where they become the width and height instead
function Collision:New(ox,oy,tx,ty) function Collision:new(ox,oy,tx,ty)
local o = {isColliding = false, isDisabled = false} local o = {isColliding = false, isDisabled = false}
if tx ~= nil and ty ~= nil then if tx ~= nil and ty ~= nil then
@ -55,28 +55,28 @@ end
function Collision:CenterAt(x, y) function Collision:centerAt(x, y)
self.from.x = x-self.width/2 self.from.x = x-self.width/2
self.from.y = y-self.height/2 self.from.y = y-self.height/2
self.to.x = x+self.width/2 self.to.x = x+self.width/2
self.to.y = y+self.height/2 self.to.y = y+self.height/2
end end
function Collision:PlaceAt(x, y) function Collision:placeAt(x, y)
self.from.x = x or self.from.x self.from.x = x or self.from.x
self.from.y = y or self.from.y self.from.y = y or self.from.y
self.to.x = self.from.x + self.width self.to.x = self.from.x + self.width
self.to.y = self.from.x + self.height self.to.y = self.from.x + self.height
end end
function Collision:ContainsPoint(x, y) function Collision:containsPoint(x, y)
return x >= self.from.x and return x >= self.from.x and
y >= self.from.y and y >= self.from.y and
x <= self.to.x and x <= self.to.x and
y <= self.to.y y <= self.to.y
end end
function Collision:Draw(color) function Collision:draw(color)
if self.isColliding == true then if self.isColliding == true then
love.graphics.setColor(0,1,0,0.5) love.graphics.setColor(0,1,0,0.5)
elseif color == 1 then elseif color == 1 then
@ -88,10 +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 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

@ -1,4 +1,4 @@
function DebugUI() function debugUI()
love.graphics.setScale() love.graphics.setScale()
local mouse_x, mouse_y = love.mouse.getPosition() local mouse_x, mouse_y = love.mouse.getPosition()
@ -26,19 +26,19 @@ function DebugUI()
love.graphics.setColor(1,0,0) love.graphics.setColor(1,0,0)
end end
function DebugColisions() function debugColisions()
love.graphics.setScale(game.scale) love.graphics.setScale(game.scale)
-- DrawColisionTable() -- DrawColisionTable()
LoadedObjects.DrawCollisions() LoadedObjects.drawCollisions()
end end
function DebugEntities() function debugEntities()
love.graphics.setScale(game.scale) love.graphics.setScale(game.scale)
for _, particle in pairs(LoadedParticles) do for _, particle in pairs(LoadedParticles) do
particle:Debug() particle:debug()
end end
for _, enty in pairs(LoadedObjects.Entities) do for _, enty in pairs(LoadedObjects.Entities) do
enty:Debug() enty:debug()
end end
end end

View File

@ -4,7 +4,7 @@ DemoRecording = false
DemoAction = nil -- Table of actions DemoAction = nil -- Table of actions
CurrentDemoFrame = nil CurrentDemoFrame = nil
function Demo:Draw() function Demo:draw()
if DemoRecording then if DemoRecording then
love.graphics.setColor(1,0,0,1) love.graphics.setColor(1,0,0,1)
elseif DemoPlayback then elseif DemoPlayback then
@ -13,18 +13,18 @@ function Demo:Draw()
love.graphics.rectangle("line",0,0,game.width ,game.height) love.graphics.rectangle("line",0,0,game.width ,game.height)
end end
function Demo:PlaybackStart() function Demo:startPlayback()
DemoPlayback = true DemoPlayback = true
CurrentDemoFrame = 0 CurrentDemoFrame = 0
dofile("demos/play_demo.lua") dofile("demos/play_demo.lua")
end end
function Demo:PlaybackEnd() function Demo:endPlayback()
DemoPlayback = false DemoPlayback = false
DemoAction = nil DemoAction = nil
end end
function Demo:RecordAction(action) function Demo:recordAction(action)
if DemoRecording if DemoRecording
and action ~= nil and action ~= nil
then then
@ -32,7 +32,7 @@ function Demo:RecordAction(action)
end end
end end
function Demo:RecordStart() function Demo:startRecord()
-- Make demo stuff -- Make demo stuff
os.execute( "mkdir \"./demos\"" ) os.execute( "mkdir \"./demos\"" )
DemoFile = io.open("demos/play_demo.lua", "w+") DemoFile = io.open("demos/play_demo.lua", "w+")
@ -44,14 +44,14 @@ function Demo:RecordStart()
CurrentDemoFrame = 1 CurrentDemoFrame = 1
end end
function Demo:RecordEnd() function Demo:endRecord()
DemoFile:write("}\n}") DemoFile:write("}\n}")
DemoFile:close() DemoFile:close()
DemoFile = nil DemoFile = nil
DemoRecording = false DemoRecording = false
end end
function Demo:Step() function Demo:step()
if DemoRecording then if DemoRecording then
if CurrentDemoFrame == 1 then if CurrentDemoFrame == 1 then
DemoFile:write("\t{") DemoFile:write("\t{")
@ -59,7 +59,7 @@ function Demo:Step()
DemoFile:write("},\n\t{") DemoFile:write("},\n\t{")
end end
elseif DemoPlayback then elseif DemoPlayback then
if DemoAction[CurrentDemoFrame + 1] == nil then Demo:PlaybackEnd() end if DemoAction[CurrentDemoFrame + 1] == nil then Demo:endPlayback() end
end end
CurrentDemoFrame = CurrentDemoFrame + 1 CurrentDemoFrame = CurrentDemoFrame + 1
end end

View File

@ -1,7 +1,7 @@
assert(editor == nil) assert(editor == nil)
editor = { room_mode = false } editor = { room_mode = false }
function EditorStep() function stepEditor()
palette = palette or false palette = palette or false
AnimateTiles() AnimateTiles()
if Keybind:CheckPressed(Keybind.editor.room_mode) then if Keybind:CheckPressed(Keybind.editor.room_mode) then
@ -74,7 +74,7 @@ function EditorStep()
end end
end end
function EditorScroll(y) function scrollEditor(y)
if palette then if palette then
if love.keyboard.isDown("lshift") then if love.keyboard.isDown("lshift") then
palette_scroll_y = palette_scroll_y + y palette_scroll_y = palette_scroll_y + y
@ -87,23 +87,23 @@ function EditorScroll(y)
end end
end end
function EditorDraw() function drawEditor()
GameworldDrawPrepare() startGameworldDraw()
GameworldDrawBackground() drawGameworldBackground()
GridDisplay() drawGridDisplay()
GameworldDrawForeground() drawGameworldForeground()
GameworldDrawEnd() endGameworldDraw()
EditorDoEdit() doEditorEdit()
DrawRooms() drawEditorRooms()
drawSelectingPaletteTile()
DrawSelectingPaletteTile()
if palette then if palette then
EditorDoPalette() doEditorPalette()
end end
end end
function EditorDoEdit() function doEditorEdit()
local mouse_x = love.mouse.getX() local mouse_x = love.mouse.getX()
local mouse_y = love.mouse.getY() local mouse_y = love.mouse.getY()
local horizontal = 1+math.floor(((mouse_x/game.scale) / tileProperties.width) + (Camera.pos.x / tileProperties.width)) local horizontal = 1+math.floor(((mouse_x/game.scale) / tileProperties.width) + (Camera.pos.x / tileProperties.width))
@ -145,7 +145,7 @@ function EditorDoEdit()
end end
end end
if #editor.room_points == 2 then if #editor.room_points == 2 then
table.insert(LoadedObjects.Rooms, Collision:New(r[1].x,r[1].y,r[2].x,r[2].y)) table.insert(LoadedObjects.Rooms, Collision:new(r[1].x,r[1].y,r[2].x,r[2].y))
editor.room_points = {} editor.room_points = {}
end end
if editor.room_mode == "delete" then if editor.room_mode == "delete" then
@ -180,7 +180,7 @@ function EditorDoEdit()
end end
end end
function DrawSelectingPaletteTile() function drawSelectingPaletteTile()
if selecting_tile ~= nil and selecting_tile ~= 0 then if selecting_tile ~= nil and selecting_tile ~= 0 then
local mouse_x = love.mouse.getX() local mouse_x = love.mouse.getX()
@ -199,7 +199,7 @@ function DrawSelectingPaletteTile()
end end
end end
function EditorDoPalette() function doEditorPalette()
local width = LevelData.tileset:getPixelWidth()/tileProperties.width local width = LevelData.tileset:getPixelWidth()/tileProperties.width
local height = LevelData.tileset:getPixelHeight()/tileProperties.height local height = LevelData.tileset:getPixelHeight()/tileProperties.height
@ -279,3 +279,11 @@ function EditorDoPalette()
1 + LevelData.tileset:getPixelHeight()* ((tileProperties.height+1) / tileProperties.height) 1 + LevelData.tileset:getPixelHeight()* ((tileProperties.height+1) / tileProperties.height)
) )
end end
function drawEditorRooms()
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

@ -1,7 +1,7 @@
Arrow = Entity:New() Arrow = Entity:new()
function Arrow:New(x,y,rotation,speed) function Arrow:new(x,y,rotation,speed)
local o = Entity:New(x,y) local o = Entity:new(x,y)
o.type = "arrow" o.type = "arrow"
@ -17,9 +17,9 @@ function Arrow:New(x,y,rotation,speed)
o.illuminated = true o.illuminated = true
-- animations -- animations
o.body = Animation:New(animation.kupo.arrow) o.body = Animation:new(animation.kupo.arrow)
o.boxCollision = { o.box = {
from = {x = -0.5, y = -0.5}, --gameworld pixels from = {x = -0.5, y = -0.5}, --gameworld pixels
to = {x = 0.5, y = 0.5} -- gameworld pixels to = {x = 0.5, y = 0.5} -- gameworld pixels
} }
@ -32,11 +32,11 @@ function Arrow:New(x,y,rotation,speed)
return o return o
end end
function Arrow:DrawBackground() function Arrow:drawBackground()
self:Draw(self.body) self:draw(self.body)
end end
function Arrow:DoPhysics() function Arrow:doPhysics()
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x self.pos.x = self.pos.x + self.vel.x
else else

View File

@ -1,7 +1,7 @@
CursedBook = Entity:New() CursedBook = Entity:new()
function CursedBook:New(x,y) function CursedBook:new(x,y)
local o = Entity:New(x,y) local o = Entity:new(x,y)
o.type = "cursed_book" o.type = "cursed_book"
-- behaviour -- behaviour
@ -20,14 +20,14 @@ function CursedBook:New(x,y)
o.attack_range = 50 o.attack_range = 50
-- animations -- animations
o.body = Animation:New(animation.cursed_book.spawn) o.body = Animation:new(animation.cursed_book.spawn)
o.sprite_tint = {0.7,0.7,0.7} o.sprite_tint = {0.7,0.7,0.7}
o:centerOffset(o.body) o:centerOffset(o.body)
o:getBoundingBox(o.body) o:createBox(o.body)
-- light -- light
o.light_range = 500 o.light_range = 500
o.light = Light:New(o.pos.x,o.pos.y,o.light_range,2,HEX2RGB("#fe00d1")) o.light = Light:new(o.pos.x,o.pos.y,o.light_range,2,HEX2RGB("#fe00d1"))
table.insert(LoadedObjects.Entities,o) table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities o.id = #LoadedObjects.Entities
@ -37,7 +37,7 @@ function CursedBook:New(x,y)
return o return o
end end
function CursedBook:Smart() function CursedBook:doLogic()
self.target.x = main_Player.pos.x - main_Player.target_offset.x self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y self.target.y = main_Player.pos.y - main_Player.target_offset.y
local distance_x = self.target.x - self.pos.x local distance_x = self.target.x - self.pos.x
@ -66,7 +66,7 @@ function CursedBook:Smart()
end end
end end
function CursedBook:HandleAnimation() function CursedBook:handleAnimation()
if self.status == 1 then if self.status == 1 then
if self.body.path == "assets/entities/cursed_book/spawn" then if self.body.path == "assets/entities/cursed_book/spawn" then
self.body.speed = 1/3 self.body.speed = 1/3
@ -74,7 +74,7 @@ function CursedBook:HandleAnimation()
self.sprite_tint = {tint,tint,tint} self.sprite_tint = {tint,tint,tint}
if self.body.frame == self.body.frames then if self.body.frame == self.body.frames then
self.status = 2 self.status = 2
self.body = self.body:ChangeTo(animation.cursed_book.flying) self.body = self.body:change(animation.cursed_book.flying)
self.sprite_tint = {1,1,1} self.sprite_tint = {1,1,1}
--self:getBoundingBox(self.body,2,2,-2,-2) --self:getBoundingBox(self.body,2,2,-2,-2)
self:centerOffset(self.body) self:centerOffset(self.body)
@ -82,21 +82,21 @@ function CursedBook:HandleAnimation()
end end
elseif self.status == 3 then elseif self.status == 3 then
if self.body.path == "assets/entities/cursed_book/flying" then if self.body.path == "assets/entities/cursed_book/flying" then
self.body = self.body:ChangeTo(animation.cursed_book.attack_transition) self.body = self.body:change(animation.cursed_book.attack_transition)
self.body.speed = 1/3 self.body.speed = 1/3
self:centerOffset(self.body) self:centerOffset(self.body)
if self.body.frame == self.body.frames then if self.body.frame == self.body.frames then
self.status = 4 self.status = 4
self.body = self.body:ChangeTo(animation.cursed_book.attack_loop) self.body = self.body:change(animation.cursed_book.attack_loop)
self:centerOffset(self.body) self:centerOffset(self.body)
end end
end end
end end
self.body:Animate() self.body:animate()
self:Draw(self.body) self:draw(self.body)
end end
function CursedBook:DoPhysics() function CursedBook:doPhysics()
if self.isFlying then if self.isFlying then
local random_x = math.random(-4, 4)/100 local random_x = math.random(-4, 4)/100
local random_y = math.random(-4, 4)/100 local random_y = math.random(-4, 4)/100
@ -105,11 +105,11 @@ function CursedBook:DoPhysics()
end end
-- move -- move
self:CollisionMove() self:moveWithCollision()
self:LightAdjust() self:adjustLight()
end end
function CursedBook:Debug() function CursedBook:debug()
-- draw center GREEN -- draw center GREEN
love.graphics.setColor(0,1,0) love.graphics.setColor(0,1,0)
love.graphics.circle("line", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, self.spawn_range) love.graphics.circle("line", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, self.spawn_range)

View File

@ -1,20 +1,20 @@
Decoration = Entity:New() Decoration = Entity:new()
function Decoration:New(x,y,animation,lightRange) function Decoration:new(x,y,animation,light_radius)
local o = Entity:New(x,y) local o = Entity:new(x,y)
o.type = "decoration" o.type = "decoration"
o.pos = {x = x, y = y} o.pos = {x = x, y = y}
-- animations -- animations
o.body = Animation:New(animation) o.body = Animation:new(animation)
o:centerOffset(o.body) o:centerOffset(o.body)
o:getBoundingBox(o.body) o:createBox(o.body)
if lightRange ~= nil then if light_radius ~= nil then
o.lightRange = lightRange o.light_radius = light_radius
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange) o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
end end
table.insert(LoadedObjects.Entities,o) table.insert(LoadedObjects.Entities,o)
@ -25,10 +25,10 @@ function Decoration:New(x,y,animation,lightRange)
return o return o
end end
function Decoration:HandleAnimation() function Decoration:handleAnimation()
self.body:Animate() self.body:animate()
self:Draw(self.body) self:draw(self.body)
end end
function Decoration:DoPhysics() function Decoration:doPhysics()
end end

View File

@ -1,7 +1,7 @@
Fairy = Entity:New() Fairy = Entity:new()
function Fairy:New(x,y) function Fairy:new(x,y)
local o = Entity:New(x,y) local o = Entity:new(x,y)
o.type = "fairy" o.type = "fairy"
@ -14,13 +14,13 @@ function Fairy:New(x,y)
o.hover_distance = 60 o.hover_distance = 60
-- animations -- animations
o.body = Animation:New(animation.fairy.flying) o.body = Animation:new(animation.fairy.flying)
o:centerOffset(o.body) o:centerOffset(o.body)
o:getBoundingBox(o.body) o:createBox(o.body)
-- light -- light
o.light_range = 80 o.light_radius = 80
o.light = Light:New(o.pos.x,o.pos.y,o.light_range,nil,HEX2RGB("#fed100")) o.light = Light:new(o.pos.x,o.pos.y,o.light_radius,nil,HEX2RGB("#fed100"))
-- timer -- timer
o.particle_timer = 0 o.particle_timer = 0
@ -34,9 +34,9 @@ function Fairy:New(x,y)
return o return o
end end
function Fairy:Smart() function Fairy:doLogic()
if self:CheckVisionLine(main_Player,self.vision_range) then if self:checkVisionLine(main_Player,self.vision_range) then
self.target.x = main_Player.pos.x + main_Player.target_offset.x self.target.x = main_Player.pos.x + main_Player.target_offset.x
self.target.y = main_Player.pos.y + main_Player.target_offset.y self.target.y = main_Player.pos.y + main_Player.target_offset.y
@ -85,31 +85,31 @@ function Fairy:Smart()
speed = 0.8*(distance/50), speed = 0.8*(distance/50),
speed_increase = -0.01, speed_increase = -0.01,
} }
Particle:New(self.pos.x,self.pos.y,particle_data) Particle:new(self.pos.x,self.pos.y,particle_data)
end end
end end
function Fairy:HandleAnimation() function Fairy:handleAnimation()
self.body:Animate() self.body:animate()
--if self:isCollidingWith(main_Player) then self.sprite_tint = {1,0,0} else self.sprite_tint = {1,1,1} end --if self:isCollidingWith(main_Player) then self.sprite_tint = {1,0,0} else self.sprite_tint = {1,1,1} end
self:Draw(self.body) self:draw(self.body)
end end
function Fairy:DoPhysics() function Fairy:doPhysics()
local random_x = math.random(-4, 4)/10 local random_x = math.random(-4, 4)/10
local random_y = math.random(-4, 4)/10 local random_y = math.random(-4, 4)/10
self.vel.x = self.vel.x + random_x self.vel.x = self.vel.x + random_x
self.vel.y = self.vel.y + random_y self.vel.y = self.vel.y + random_y
self:CollisionMove() self:moveWithCollision()
self.vel.x = 0 self.vel.x = 0
self.vel.y = 0 self.vel.y = 0
self:LightAdjust() self:adjustLight()
end end
function Fairy:Debug() function Fairy:debug()
Entity.Debug(self) Entity.debug(self)
self:CheckVisionLineDebug(main_Player,self.vision_range) self:checkVisionLineDebug(main_Player,self.vision_range)
end end

View File

@ -1,16 +1,16 @@
HookAnchor = Entity:New() HookAnchor = Entity:new()
function HookAnchor:New(x,y,hookDistance) function HookAnchor:new(x,y,hookDistance)
local o = Entity:New(x,y) local o = Entity:new(x,y)
o.type = "hook_anchor" o.type = "hook_anchor"
o.pos = {x = x, y = y} o.pos = {x = x, y = y}
o.hookDistance = hookDistance or 100 o.hookDistance = hookDistance or 100
-- animations -- animations
o.body = Animation:New(animation.fairy.flying) o.body = Animation:new(animation.fairy.flying)
o:centerOffset(o.body) o:centerOffset(o.body)
o:getBoundingBox(o.body) o:createBox(o.body)
table.insert(LoadedObjects.Entities,o) table.insert(LoadedObjects.Entities,o)
@ -21,13 +21,13 @@ function HookAnchor:New(x,y,hookDistance)
return o return o
end end
function HookAnchor:HandleAnimation() function HookAnchor:handleAnimation()
self.body:Animate() self.body:animate()
self:Draw(self.body) self:draw(self.body)
end end
function HookAnchor:DrawBackground() function HookAnchor:drawBackground()
Entity.DrawBackground(self) Entity.drawBackground(self)
love.graphics.setColor(1,1,1,0) love.graphics.setColor(1,1,1,0)
love.graphics.circle( love.graphics.circle(
"fill", "fill",
@ -37,10 +37,10 @@ function HookAnchor:DrawBackground()
) )
end end
function HookAnchor:DoPhysics() function HookAnchor:doPhysics()
end end
function Fairy:Debug() function Fairy:debug()
Entity.Debug(self) Entity.debug(self)
end end

View File

@ -1,7 +1,7 @@
Kupo = Entity:New() Kupo = Entity:new()
function Kupo:New(x,y) function Kupo:new(x,y)
local o = Entity:New(x,y) local o = Entity:new(x,y)
o.type = "kupo" o.type = "kupo"
@ -12,8 +12,8 @@ function Kupo:New(x,y)
o.sprite_offset = {x = 8, y = 5} o.sprite_offset = {x = 8, y = 5}
-- animations -- animations
o.body = Animation:New(animation.kupo.body) o.body = Animation:new(animation.kupo.body)
o.bow = Animation:New(animation.kupo.bow) o.bow = Animation:new(animation.kupo.bow)
-- bow -- bow
o.bow_flip = 1 o.bow_flip = 1
@ -27,8 +27,8 @@ function Kupo:New(x,y)
o.bow_aim_frames = 8 o.bow_aim_frames = 8
o.hostile = true o.hostile = true
o.lightRange = o.range/2 o.light_radius = o.range/2
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange) o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
table.insert(LoadedObjects.Entities,o) table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities o.id = #LoadedObjects.Entities
@ -38,9 +38,8 @@ function Kupo:New(x,y)
return o return o
end end
function Kupo:Smart() function Kupo:doLogic()
self.light.pos.x = self.pos.x-self.target_offset.x self:adjustLight(self.target_offset.x,self.target_offset.y)
self.light.pos.y = self.pos.y-self.target_offset.y
self.target.x = main_Player.pos.x - main_Player.target_offset.x self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y self.target.y = main_Player.pos.y - main_Player.target_offset.y
@ -89,7 +88,7 @@ function Kupo:Smart()
if self.bow_aim_frame > self.bow_aim_frames then if self.bow_aim_frame > self.bow_aim_frames then
self.bow_aim_frame = self.bow_aim_frame - self.bow_aim_frames self.bow_aim_frame = self.bow_aim_frame - self.bow_aim_frames
self.bow_frame = self.bow_frame + 1 self.bow_frame = self.bow_frame + 1
Arrow:New(self.pos.x,self.pos.y,self.bow_rotation,10) Arrow:new(self.pos.x,self.pos.y,self.bow_rotation,10)
end end
else else
self.bow_frame = self.bow_frame + 1 self.bow_frame = self.bow_frame + 1
@ -130,7 +129,7 @@ function Kupo:Smart()
self.angle = angle self.angle = angle
end end
function Kupo:HandleAnimation() function Kupo:handleAnimation()
local distance_x = self.target.x - self.pos.x local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y local distance_y = self.target.y - self.pos.y
@ -143,11 +142,11 @@ function Kupo:HandleAnimation()
-- flip sprite to look in the direction is moving -- flip sprite to look in the direction is moving
if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end
self.body:Animate() self.body:animate()
self:Draw(self.body) self:Draw(self.body)
if self.draw_bow == true then if self.draw_bow == true then
self.bow:DrawFrame( self.bow:drawFrame(
math.min(self.bow_frame,self.bow_frames), math.min(self.bow_frame,self.bow_frames),
self.pos.x + ( 8 * math.sin(self.bow_rotation)), self.pos.x + ( 8 * math.sin(self.bow_rotation)),
self.pos.y + (2 - 6 * math.cos(self.bow_rotation)), self.pos.y + (2 - 6 * math.cos(self.bow_rotation)),
@ -156,6 +155,6 @@ function Kupo:HandleAnimation()
end end
end end
function Kupo:DoPhysics() function Kupo:doPhysics()
self:CollisionMove() self:moveWithCollision()
end end

View File

@ -1,8 +1,8 @@
Particle = Entity:New() Particle = Entity:new()
LoadedObjects.Particles = {} LoadedObjects.Particles = {}
function Particle:New(x,y,particle_data) function Particle:new(x,y,particle_data)
local o = Entity:New(x,y) local o = Entity:new(x,y)
o.pos = {x = x, y = y} o.pos = {x = x, y = y}
@ -29,17 +29,17 @@ function Particle:New(x,y,particle_data)
o.speed_increase = particle_data.speed_increase or 0 o.speed_increase = particle_data.speed_increase or 0
if particle_data.light ~= nil then if particle_data.light ~= nil then
o.lightRange = particle_data.light o.light_range = particle_data.light
local flicker = particle_data.light_flicker or nil local flicker = particle_data.light_flicker or nil
local color = particle_data.light_color or nil local color = particle_data.light_color or nil
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange,flicker,color) o.light = Light:new(o.pos.x,o.pos.y,o.light_range,flicker,color)
end end
-- animations -- animations
if particle_data.animation ~= nil then if particle_data.animation ~= nil then
o.body = Animation:New(particle_data.animation) o.body = Animation:new(particle_data.animation)
o:centerOffset(o.body) o:centerOffset(o.body)
o:getBoundingBox(o.body) o:createBox(o.body)
if not o.animation_active then if not o.animation_active then
o.body.speed = 0 o.body.speed = 0
end end
@ -53,9 +53,9 @@ function Particle:New(x,y,particle_data)
return o return o
end end
function Particle:Kill() function Particle:kill()
if self.light ~= nil then if self.light ~= nil then
self.light:Kill() self.light:kill()
end end
if self.id ~= nil then if self.id ~= nil then
for _, e in pairs(LoadedObjects.Particles) do for _, e in pairs(LoadedObjects.Particles) do
@ -68,21 +68,21 @@ function Particle:Kill()
self = nil self = nil
end end
function Particle:HandleAnimation() function Particle:handleAnimation()
self.timer = self.timer + current_dt self.timer = self.timer + current_dt
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
if self.light ~= nil then if self.light ~= nil then
self:LightAdjust() self:adjustLight()
self.light.range = self.lightRange * self.sprite_alpha/2 self.light.range = self.light_range * self.sprite_alpha/2
end end
if self.sprite_alpha < 0 then self:Kill() end if self.sprite_alpha < 0 then self:kill() end
if self.body ~= nil then if self.body ~= nil then
self.body:Animate() self.body:animate()
self:Draw(self.body) self:draw(self.body)
end end
end end
function Particle:DoPhysics() function Particle:doPhysics()
-- adjust speed -- adjust speed
if self.speed_increase ~= 0 then if self.speed_increase ~= 0 then
self.speed = self.speed + self.speed_increase self.speed = self.speed + self.speed_increase
@ -90,10 +90,10 @@ function Particle:DoPhysics()
self.vel.y = self.speed * math.sin(self.direction) self.vel.y = self.speed * math.sin(self.direction)
end end
-- move -- move
self:CollisionMove() self:moveWithCollision()
end end
function Particle:Debug() function Particle:debug()
-- draw center CYAN -- draw center CYAN
love.graphics.setColor(0,1,1) love.graphics.setColor(0,1,1)
love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1) love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1)

View File

@ -1,7 +1,7 @@
Player = Entity:New() Player = Entity:new()
function Player:New(x,y) function Player:new(x,y)
local o = Entity:New(x,y) local o = Entity:new(x,y)
o.type = "player" o.type = "player"
-- physics -- physics
@ -43,7 +43,7 @@ function Player:New(x,y)
o.walljumpFriction = 0.3 -- gameworld pixels o.walljumpFriction = 0.3 -- gameworld pixels
-- light values -- light values
o.lightRange = 40 -- screen pixels o.light_radius = 40 -- screen pixels
-- status -- status
o.canJump = true o.canJump = true
@ -69,13 +69,13 @@ function Player:New(x,y)
-- sprite -- sprite
o.target_offset = {x = 0, y = 0} o.target_offset = {x = 0, y = 0}
o.body = Animation:New(animation.nancy.idle) o.body = Animation:new(animation.nancy.idle)
o.mask = Animation:New(animation.moth_mask.idle) o.mask = Animation:new(animation.moth_mask.idle)
o:centerOffset(o.body) o:centerOffset(o.body)
o:getBoundingBox(o.body,0,3,-1,-3) o:createBox(o.body,0,3,-1,-3)
-- lights -- lights
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange) o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
table.insert(LoadedObjects.Entities,o) table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities o.id = #LoadedObjects.Entities
@ -85,8 +85,8 @@ function Player:New(x,y)
return o return o
end end
function Player:Smart() function Player:doLogic()
self:LightAdjust(self.target_offset.x,self.target_offset.y) self:adjustLight(self.target_offset.x,self.target_offset.y)
-- reset coyoteValue -- reset coyoteValue
if self.isOnGround then if self.isOnGround then
@ -134,7 +134,7 @@ function Player:Smart()
if self.dashCooldownTimer == 0 if self.dashCooldownTimer == 0
and not self.isDashing and not self.isDashing
and self.dashCount > 0 then and self.dashCount > 0 then
self:Unhook() self:unhook()
-- state player -- state player
self.isDashing = true self.isDashing = true
@ -164,9 +164,9 @@ function Player:Smart()
if self.canHook and Keybind:CheckPressed(Keybind.move.hook) then if self.canHook and Keybind:CheckPressed(Keybind.move.hook) then
if self.isHooked then if self.isHooked then
self:Unhook() self:unhook()
else else
local anchor = self:CheckNearest("hook_anchor",self.hookDistance) local anchor = self:checkNearest("hook_anchor",self.hookDistance)
if anchor then if anchor then
self.isHooked = true self.isHooked = true
self.hookDistance = anchor.hookDistance self.hookDistance = anchor.hookDistance
@ -179,7 +179,7 @@ function Player:Smart()
end end
end end
function Player:DoPhysics() function Player:doPhysics()
if self.dashTimer <= 0 then if self.dashTimer <= 0 then
if self.isOnGround then if self.isOnGround then
self.vel.x = self.vel.x * (1-self.groundFriction) self.vel.x = self.vel.x * (1-self.groundFriction)
@ -219,7 +219,7 @@ function Player:DoPhysics()
y = self.sprite_flip.y y = self.sprite_flip.y
} }
} }
Particle:New(self.pos.x,self.pos.y,particle_data) Particle:new(self.pos.x,self.pos.y,particle_data)
self.dashCooldownTimer = self.dashCooldownTime self.dashCooldownTimer = self.dashCooldownTime
-- dash movement -- dash movement
self.vel.x = self.dashSpeed * math.cos(self.dashDirection) self.vel.x = self.dashSpeed * math.cos(self.dashDirection)
@ -252,7 +252,7 @@ function Player:DoPhysics()
y = self.sprite_flip.y y = self.sprite_flip.y
} }
} }
Particle:New(self.pos.x,self.pos.y,particle_data) Particle:new(self.pos.x,self.pos.y,particle_data)
local pos_x = self.hookAnchor.x + dist * math.cos(hook_angle) local pos_x = self.hookAnchor.x + dist * math.cos(hook_angle)
local pos_y = self.hookAnchor.y + dist * math.sin(hook_angle) local pos_y = self.hookAnchor.y + dist * math.sin(hook_angle)
@ -291,16 +291,16 @@ function Player:DoPhysics()
-- if u collision w hazard, respawn -- if u collision w hazard, respawn
if self:isCollidingAt(self.pos.x, self.pos.y, LoadedObjects.Hazards) then if self:isCollidingAt(self.pos.x, self.pos.y, LoadedObjects.Hazards) then
self:Respawn() self:respawn()
end end
end end
function Player:Respawn() function Player:respawn()
self.pos.x = self.anchorRespawn.x self.pos.x = self.anchorRespawn.x
self.pos.y = self.anchorRespawn.y self.pos.y = self.anchorRespawn.y
end end
function Player:HandleAnimation() function Player:handleAnimation()
-- flip sprite to look in the direction is moving -- flip sprite to look in the direction is moving
if self.isHooked then if self.isHooked then
if self.vel.x ~= 0 then if self.vel.x ~= 0 then
@ -312,17 +312,17 @@ function Player:HandleAnimation()
-- animation priority -- animation priority
if self.vel.y > 1.25 or self.isSliding then if self.vel.y > 1.25 or self.isSliding then
self.body = self.body:ChangeTo(animation.nancy.fall) self.body = self.body:change(animation.nancy.fall)
self.mask = self.mask:ChangeTo(self.maskType.fall) self.mask = self.mask:change(self.maskType.fall)
elseif self.vel.y < 0 then elseif self.vel.y < 0 then
self.body = self.body:ChangeTo(animation.nancy.jump) self.body = self.body:change(animation.nancy.jump)
self.mask = self.mask:ChangeTo(self.maskType.jump) self.mask = self.mask:change(self.maskType.jump)
elseif self.vel.x + self.move_x ~= 0 then elseif self.vel.x + self.move_x ~= 0 then
self.body = self.body:ChangeTo(animation.nancy.run) self.body = self.body:change(animation.nancy.run)
self.mask = self.mask:ChangeTo(self.maskType.run) self.mask = self.mask:change(self.maskType.run)
else else
self.body = self.body:ChangeTo(animation.nancy.idle) self.body = self.body:change(animation.nancy.idle)
self.mask = self.mask:ChangeTo(self.maskType.idle) self.mask = self.mask:change(self.maskType.idle)
end end
-- special case: idle animation gets slower by time -- special case: idle animation gets slower by time
@ -341,21 +341,21 @@ function Player:HandleAnimation()
) )
end end
self.body:Animate() self.body:animate()
self:Draw(self.body) self:draw(self.body)
if self.dashCount > 0 then if self.dashCount > 0 then
self:Draw(self.mask) self:draw(self.mask)
end end
self.move_x = 0 self.move_x = 0
end end
function Player:Unhook() function Player:unhook()
self.isHooked = false self.isHooked = false
self.hookAnchor = nil self.hookAnchor = nil
end end
function Player:Debug() function Player:debug()
Entity.Debug(self) Entity.debug(self)
love.graphics.print("wallHit: "..self.wallHit) love.graphics.print("wallHit: "..self.wallHit)
end end

View File

@ -1,7 +1,7 @@
Entity = {class = "Entity"} Entity = {class = "Entity"}
LoadedObjects.Entities = {} LoadedObjects.Entities = {}
function Entity:New(x,y) function Entity:new(x,y)
local o = {} local o = {}
o.pos = {x = x, y = y} o.pos = {x = x, y = y}
@ -9,7 +9,7 @@ function Entity:New(x,y)
o.direction = 0 o.direction = 0
o.boxCollision = { o.box = {
from = {x = x, y = y}, from = {x = x, y = y},
to = {x = x, y = y}, to = {x = x, y = y},
} }
@ -30,7 +30,7 @@ function Entity:New(x,y)
return o return o
end end
function Entity:CheckNearest(type,maxdistance) function Entity:checkNearest(type,maxdistance)
local return_entity = nil local return_entity = nil
local shortest = -1 local shortest = -1
for _, entity in pairs(LoadedObjects.Entities) do for _, entity in pairs(LoadedObjects.Entities) do
@ -51,15 +51,15 @@ function Entity:CheckNearest(type,maxdistance)
return return_entity return return_entity
end end
function Entity:Smart() function Entity:doLogic()
end end
function Entity:Move() function Entity:move()
self.pos.x = self.pos.x + self.vel.x self.pos.x = self.pos.x + self.vel.x
self.pos.y = self.pos.y + self.vel.y self.pos.y = self.pos.y + self.vel.y
end end
function Entity:CollisionMove() function Entity:moveWithCollision()
local r = false local r = false
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x self.pos.x = self.pos.x + self.vel.x
@ -76,7 +76,7 @@ function Entity:CollisionMove()
return r return r
end end
function Entity:LightAdjust(x,y) function Entity:adjustLight(x,y)
if self.light ~= nil then if self.light ~= nil then
local x = x or 0 local x = x or 0
local y = y or 0 local y = y or 0
@ -85,9 +85,9 @@ function Entity:LightAdjust(x,y)
end end
end end
function Entity:Kill() function Entity:kill()
if self.light ~= nil then if self.light ~= nil then
self.light:Kill() self.light:kill()
end end
if self.id ~= nil then if self.id ~= nil then
for _, e in pairs(LoadedObjects.Entities) do for _, e in pairs(LoadedObjects.Entities) do
@ -100,7 +100,7 @@ function Entity:Kill()
self = nil self = nil
end end
function Entity:CheckVisionLine(entity,range) function Entity:checkVisionLine(entity,range)
local target_x = entity.pos.x + entity.target_offset.x local target_x = entity.pos.x + entity.target_offset.x
local target_y = entity.pos.y + entity.target_offset.y local target_y = entity.pos.y + entity.target_offset.y
@ -128,10 +128,10 @@ function Entity:CheckVisionLine(entity,range)
return not is_colliding return not is_colliding
end end
function Entity:Draw(animation) function Entity:draw(animation)
local c1, c2, c3, a = love.graphics.getColor() local c1, c2, c3, a = love.graphics.getColor()
love.graphics.setColor(self.sprite_tint[1],self.sprite_tint[2],self.sprite_tint[3],self.sprite_alpha) love.graphics.setColor(self.sprite_tint[1],self.sprite_tint[2],self.sprite_tint[3],self.sprite_alpha)
animation:Draw( animation:draw(
self.pos.x - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x, self.pos.x - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
self.pos.y - Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y, self.pos.y - Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
self.sprite_rotation, self.sprite_rotation,
@ -148,15 +148,15 @@ function Entity:centerOffset(animation,x,y)
self.sprite_offset.y = animation.imgs[1]:getHeight()/2 + y self.sprite_offset.y = animation.imgs[1]:getHeight()/2 + y
end end
function Entity:getBoundingBox(animation,top,left,bottom,right) function Entity:createBox(animation,top,left,bottom,right)
local left = left or 0 local left = left or 0
local right = right or 0 local right = right or 0
local top = top or 0 local top = top or 0
local bottom = bottom or 0 local bottom = bottom or 0
self.boxCollision.from.x = -animation.imgs[1]:getWidth()/2 + left self.box.from.x = -animation.imgs[1]:getWidth()/2 + left
self.boxCollision.to.x = animation.imgs[1]:getWidth()/2 + right self.box.to.x = animation.imgs[1]:getWidth()/2 + right
self.boxCollision.from.y = -animation.imgs[1]:getHeight()/2 + top self.box.from.y = -animation.imgs[1]:getHeight()/2 + top
self.boxCollision.to.y = animation.imgs[1]:getHeight()/2 + bottom self.box.to.y = animation.imgs[1]:getHeight()/2 + bottom
end end
-- checks if the the reciever would collide with an object if it was positioned at the given point. -- checks if the the reciever would collide with an object if it was positioned at the given point.
@ -169,10 +169,10 @@ function Entity:getCollidingAt(x,y,object)
for _, collision in pairs(object) do for _, collision in pairs(object) do
if collision.disable then if collision.disable then
-- Dont calculate if disabled -- Dont calculate if disabled
elseif x + self.boxCollision.from.x < collision.to.x elseif x + self.box.from.x < collision.to.x
and x + self.boxCollision.to.x > collision.from.x and x + self.box.to.x > collision.from.x
and y + self.boxCollision.from.y < collision.to.y and y + self.box.from.y < collision.to.y
and y + self.boxCollision.to.y > collision.from.y and y + self.box.to.y > collision.from.y
then then
collision.isColliding = true collision.isColliding = true
return collision return collision
@ -182,10 +182,10 @@ function Entity:getCollidingAt(x,y,object)
end end
function Entity:isCollidingWith(entity) function Entity:isCollidingWith(entity)
return self.pos.x + self.boxCollision.from.x < entity.pos.x + entity.boxCollision.to.x return self.pos.x + self.box.from.x < entity.pos.x + entity.box.to.x
and entity.pos.x + entity.boxCollision.from.x < self.pos.x + self.boxCollision.to.x and entity.pos.x + entity.box.from.x < self.pos.x + self.box.to.x
and self.pos.y + self.boxCollision.from.y < entity.pos.y + entity.boxCollision.to.y and self.pos.y + self.box.from.y < entity.pos.y + entity.box.to.y
and entity.pos.y + entity.boxCollision.from.y < self.pos.y + self.boxCollision.to.y and entity.pos.y + entity.box.from.y < self.pos.y + self.box.to.y
end end
function Entity:isCollidingAtAll(x,y) function Entity:isCollidingAtAll(x,y)
@ -202,7 +202,7 @@ function Entity:isCollidingAtAll(x,y)
return result return result
end end
function Entity:CheckVisionLineDebug(entity,range) function Entity:checkVisionLineDebug(entity,range)
local c1, c2, c3, a = love.graphics.getColor() local c1, c2, c3, a = love.graphics.getColor()
local target_x = entity.pos.x + entity.target_offset.x local target_x = entity.pos.x + entity.target_offset.x
@ -237,7 +237,7 @@ function Entity:CheckVisionLineDebug(entity,range)
love.graphics.setColor(c1,c2,c3,a) love.graphics.setColor(c1,c2,c3,a)
end end
function Entity:Debug() function Entity:debug()
-- draw center GREEN -- draw center GREEN
love.graphics.setColor(0,1,0) love.graphics.setColor(0,1,0)
love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1) love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1)
@ -245,10 +245,10 @@ function Entity:Debug()
love.graphics.setColor(1,0,1) love.graphics.setColor(1,0,1)
love.graphics.rectangle( love.graphics.rectangle(
"line", "line",
-Camera.pos.x + self.pos.x + self.boxCollision.from.x, -Camera.pos.x + self.pos.x + self.box.from.x,
-Camera.pos.y + self.pos.y + self.boxCollision.from.y, -Camera.pos.y + self.pos.y + self.box.from.y,
-Camera.pos.x + self.pos.x + self.boxCollision.to.x -(-Camera.pos.x + self.pos.x + self.boxCollision.from.x), -Camera.pos.x + self.pos.x + self.box.to.x -(-Camera.pos.x + self.pos.x + self.box.from.x),
-Camera.pos.y + self.pos.y + self.boxCollision.to.y -(-Camera.pos.y + self.pos.y + self.boxCollision.from.y) -Camera.pos.y + self.pos.y + self.box.to.y -(-Camera.pos.y + self.pos.y + self.box.from.y)
) )
if self.target ~= nil then if self.target ~= nil then
love.graphics.line( love.graphics.line(
@ -260,10 +260,10 @@ function Entity:Debug()
end end
end end
function Entity:HandleAnimation() function Entity:handleAnimation()
end end
function Entity:DrawBackground() function Entity:drawBackground()
end end
require "code/entities/kupo" require "code/entities/kupo"

View File

@ -1,19 +1,19 @@
function GameStep() function stepGame()
SetCollisionFlags() setCollisionFlags()
if menu_type == "no" then if menu_type == "no" then
for _, particle in pairs(LoadedParticles) do for _, particle in pairs(LoadedParticles) do
particle:Smart() particle:doLogic()
end end
for _, enty in pairs(LoadedObjects.Entities) do for _, enty in pairs(LoadedObjects.Entities) do
enty:Smart() enty:doLogic()
end end
end end
for _, particle in pairs(LoadedObjects.Particles) do for _, particle in pairs(LoadedObjects.Particles) do
particle:DoPhysics() particle:doPhysics()
end end
for _, enty in pairs(LoadedObjects.Entities) do for _, enty in pairs(LoadedObjects.Entities) do
enty:DoPhysics() enty:doPhysics()
end end
AnimateTiles() AnimateTiles()
@ -50,50 +50,50 @@ function GameStep()
if Keybind:CheckPressed(Keybind.debug.recording) then if Keybind:CheckPressed(Keybind.debug.recording) then
if DemoRecording then if DemoRecording then
Demo:RecordEnd() Demo:endRecord()
else else
Demo:RecordStart() Demo:startRecord()
end end
end end
if Keybind:CheckPressed(Keybind.debug.playback) then if Keybind:CheckPressed(Keybind.debug.playback) then
if DemoPlayback then if DemoPlayback then
Demo:PlaybackEnd() Demo:endPlayback()
else else
Demo:PlaybackStart() Demo:startPlayback()
end end
end end
end end
function GameDraw() function drawGame()
-- prepare -- prepare
GameworldDrawPrepare() startGameworldDraw()
GameWorldUpdateLights() updateGameWorldLights()
-- background -- background
GameworldDrawBackground() drawGameworldBackground()
GameworldDrawLights() drawGameworldLights()
GameworldDrawEntitiesBackground() drawGameworldEntitiesBackground()
-- foreground -- foreground
GameworldDrawForeground() drawGameworldForeground()
GameworldDrawParticles() drawGameworldParticles()
GameworldDrawEntities() drawGameworldEntities()
if LevelData.properties.darkness then if LevelData.properties.darkness then
GameworldDrawDarkness() drawGameworldDarkness()
end end
-- end -- end
GameworldDrawEnd() endGameworldDraw()
-- hud -- hud
textScale = 1 textScale = 1
-- debug -- debug
if debug then DebugUI() end if debug then debugUI() end
if debug_collision then if debug_collision then
DebugColisions() debugColisions()
DebugEntities() debugEntities()
end end
end end

View File

@ -1,20 +1,20 @@
function GameworldDrawPrepare() function startGameworldDraw()
if game_resize then if game_resize then
Camera.height = game.height Camera.height = game.height
Camera.width = game.width Camera.width = game.width
Canvas.Darkness:Recreate() Canvas.Darkness:recreate()
end end
pcr, pcg, pcb, pca = love.graphics.getColor() pcr, pcg, pcb, pca = love.graphics.getColor()
love.graphics.setScale(game.scale,game.scale) love.graphics.setScale(game.scale,game.scale)
love.graphics.setColor(1,1,1,1) love.graphics.setColor(1,1,1,1)
end end
function GameworldDrawEnd() function endGameworldDraw()
love.graphics.setColor(pcr, pcg, pcb, pca) love.graphics.setColor(pcr, pcg, pcb, pca)
pcr, pcg, pcb, pca = nil, nil, nil, nil pcr, pcg, pcb, pca = nil, nil, nil, nil
end end
function GameworldDrawBackground() function drawGameworldBackground()
-- obscure a bit -- obscure a bit
love.graphics.setColor(0.7,0.7,0.7) love.graphics.setColor(0.7,0.7,0.7)
for i = 1, #LevelTiles do for i = 1, #LevelTiles do
@ -34,27 +34,27 @@ function GameworldDrawBackground()
end end
end end
function GameworldDrawParticles() function drawGameworldParticles()
love.graphics.setColor(0.7,0.7,0.7) love.graphics.setColor(0.7,0.7,0.7)
for _, particle in pairs(LoadedObjects.Particles) do for _, particle in pairs(LoadedObjects.Particles) do
particle:HandleAnimation() particle:handleAnimation()
end end
end end
function GameworldDrawEntitiesBackground() function drawGameworldEntitiesBackground()
for _, enty in pairs(LoadedObjects.Entities) do for _, enty in pairs(LoadedObjects.Entities) do
enty:DrawBackground() enty:drawBackground()
end end
end end
function GameworldDrawEntities() function drawGameworldEntities()
love.graphics.setColor(0.7,0.7,0.7) love.graphics.setColor(0.7,0.7,0.7)
for _, enty in pairs(LoadedObjects.Entities) do for _, enty in pairs(LoadedObjects.Entities) do
enty:HandleAnimation() enty:handleAnimation()
end end
end end
function GameworldDrawForeground() function drawGameworldForeground()
love.graphics.setColor(1,1,1) love.graphics.setColor(1,1,1)
for i = 1, #LevelTiles do for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do for j = 1, #LevelTiles[i] do
@ -73,9 +73,9 @@ function GameworldDrawForeground()
end end
end end
function GameworldDrawDarkness() function drawGameworldDarkness()
Canvas.Darkness:Reset() Canvas.Darkness:reset()
Canvas.Darkness:DrawingStart() Canvas.Darkness:startDrawing()
love.graphics.setBlendMode("replace") love.graphics.setBlendMode("replace")
love.graphics.setColor(0,0,0,0) love.graphics.setColor(0,0,0,0)
for _, light in pairs(LoadedObjects.Lights) do for _, light in pairs(LoadedObjects.Lights) do
@ -84,7 +84,7 @@ function GameworldDrawDarkness()
x = (light.pos.x - Camera.pos.x) / game.scale, x = (light.pos.x - Camera.pos.x) / game.scale,
y = (light.pos.y - Camera.pos.y) / game.scale y = (light.pos.y - Camera.pos.y) / game.scale
} }
local range = (light.range + light.flicker) / game.scale local range = (light.range + light.flicker_value) / game.scale
love.graphics.circle( love.graphics.circle(
"fill", "fill",
position.x, position.x,
@ -93,11 +93,11 @@ function GameworldDrawDarkness()
) )
end end
end end
Canvas.Darkness:DrawingEnd() Canvas.Darkness:endDrawing()
Canvas.Darkness:Draw() Canvas.Darkness:draw()
end end
function GameworldDrawLights() function drawGameworldLights()
for _, light in pairs(LoadedObjects.Lights) do for _, light in pairs(LoadedObjects.Lights) do
if light.range ~= 0 then if light.range ~= 0 then
love.graphics.setColor(light.color[1],light.color[2],light.color[3],1) love.graphics.setColor(light.color[1],light.color[2],light.color[3],1)
@ -119,8 +119,8 @@ function GameworldDrawLights()
end end
end end
function GameWorldUpdateLights() function updateGameWorldLights()
for _, light in pairs(LoadedObjects.Lights) do for _, light in pairs(LoadedObjects.Lights) do
light:Flicker() light:flicker()
end end
end end

View File

@ -35,7 +35,7 @@ function Keybind:CheckDown(action)
end end
if check then if check then
if action.demo ~= nil then if action.demo ~= nil then
Demo:RecordAction(action.demo) Demo:recordAction(action.demo)
end end
return true return true
end end

View File

@ -229,7 +229,7 @@ function SetTile(i,j,id)
LevelTiles[i][j] = InstanceTile(id) LevelTiles[i][j] = InstanceTile(id)
end end
function GridDisplay() function drawGridDisplay()
for i = 1, #LevelTiles do for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do for j = 1, #LevelTiles[i] do
love.graphics.rectangle( love.graphics.rectangle(
@ -316,7 +316,7 @@ function TileOptimizeObjects()
local base_x = tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.height) local base_x = tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.height)
local base_y = tileProperties.scale * i * tileProperties.height + tileProperties.scale * (levelProperties.offset.y - tileProperties.height) local base_y = tileProperties.scale * i * tileProperties.height + tileProperties.scale * (levelProperties.offset.y - tileProperties.height)
local col = Collision:New( local col = Collision:new(
base_x, base_x,
base_y, base_y,
base_x + tileProperties.width * tileProperties.scale * n, base_x + tileProperties.width * tileProperties.scale * n,
@ -359,7 +359,7 @@ function TileCreateObjects()
-- wholes are handled in optimization now -- wholes are handled in optimization now
--[[if type == "whole" then --[[if type == "whole" then
local col = Collision:New( local col = Collision:new(
base_x, base_x,
base_y, base_y,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -368,7 +368,7 @@ function TileCreateObjects()
table.insert(LoadedObjects.Collisions,col) table.insert(LoadedObjects.Collisions,col)
else]]if type == "half_bottom" then else]]if type == "half_bottom" then
local col = Collision:New( local col = Collision:new(
base_x, base_x,
base_y + tileProperties.height/2 * tileProperties.scale, base_y + tileProperties.height/2 * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -378,7 +378,7 @@ function TileCreateObjects()
elseif type == "half_top" then elseif type == "half_top" then
local col = Collision:New( local col = Collision:new(
base_x, base_x,
base_y , base_y ,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -388,7 +388,7 @@ function TileCreateObjects()
elseif type == "half_right" then elseif type == "half_right" then
local col = Collision:New( local col = Collision:new(
base_x + tileProperties.height/2 * tileProperties.scale, base_x + tileProperties.height/2 * tileProperties.scale,
base_y, base_y,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -398,7 +398,7 @@ function TileCreateObjects()
elseif type == "half_left" then elseif type == "half_left" then
local col = Collision:New( local col = Collision:new(
base_x, base_x,
base_y, base_y,
base_x + tileProperties.height/2 * tileProperties.scale, base_x + tileProperties.height/2 * tileProperties.scale,
@ -407,7 +407,7 @@ function TileCreateObjects()
table.insert(LoadedObjects.Collisions,col) table.insert(LoadedObjects.Collisions,col)
elseif type == "platform" then elseif type == "platform" then
local plat = Collision:New( local plat = Collision:new(
base_x, base_x,
base_y + tileProperties.scale * 2, base_y + tileProperties.scale * 2,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -418,7 +418,7 @@ function TileCreateObjects()
elseif type == "ramp2_bot_left_whole" then elseif type == "ramp2_bot_left_whole" then
for k = 1, 8 do for k = 1, 8 do
-- do ramp owo -- do ramp owo
local slope = Collision:New( local slope = Collision:new(
base_x, base_x,
base_y + k * tileProperties.scale - tileProperties.scale, base_y + k * tileProperties.scale - tileProperties.scale,
base_x + k * 2 * tileProperties.scale, base_x + k * 2 * tileProperties.scale,
@ -428,7 +428,7 @@ function TileCreateObjects()
end end
-- fill lower half -- fill lower half
local col = Collision:New( local col = Collision:new(
base_x, base_x,
base_y + tileProperties.height/2 * tileProperties.scale, base_y + tileProperties.height/2 * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -439,7 +439,7 @@ function TileCreateObjects()
elseif type == "ramp2_bot_left_half" then elseif type == "ramp2_bot_left_half" then
for k = 1, 8 do for k = 1, 8 do
-- do ramp owo -- do ramp owo
local slope = Collision:New( local slope = Collision:new(
base_x, base_x,
base_y + tileProperties.height/2 * tileProperties.scale + k * tileProperties.scale - tileProperties.scale, base_y + tileProperties.height/2 * tileProperties.scale + k * tileProperties.scale - tileProperties.scale,
base_x + k * 2 * tileProperties.scale, base_x + k * 2 * tileProperties.scale,
@ -452,7 +452,7 @@ function TileCreateObjects()
elseif type == "ramp2_top_left_whole" then elseif type == "ramp2_top_left_whole" then
for k = 1, 8 do for k = 1, 8 do
-- do ramp owo -- do ramp owo
local slope = Collision:New( local slope = Collision:new(
base_x, base_x,
base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale, base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale - (k-1) * 2 * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale - (k-1) * 2 * tileProperties.scale,
@ -462,7 +462,7 @@ function TileCreateObjects()
end end
-- fill higher half -- fill higher half
local col = Collision:New( local col = Collision:new(
base_x, base_x,
base_y, base_y,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -473,7 +473,7 @@ function TileCreateObjects()
elseif type == "ramp2_top_left_half" then elseif type == "ramp2_top_left_half" then
for k = 1, 8 do for k = 1, 8 do
-- do ramp owo -- do ramp owo
local slope = Collision:New( local slope = Collision:new(
base_x, base_x,
base_y - tileProperties.scale + k * tileProperties.scale, base_y - tileProperties.scale + k * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale - (k-1) * 2 * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale - (k-1) * 2 * tileProperties.scale,
@ -486,7 +486,7 @@ function TileCreateObjects()
elseif type == "ramp2_bot_right_whole" then elseif type == "ramp2_bot_right_whole" then
for k = 1, 8 do for k = 1, 8 do
-- do ramp owo -- do ramp owo
local slope = Collision:New( local slope = Collision:new(
base_x + (k-8) * -2 * tileProperties.scale, base_x + (k-8) * -2 * tileProperties.scale,
base_y - tileProperties.scale + k * tileProperties.scale, base_y - tileProperties.scale + k * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -496,7 +496,7 @@ function TileCreateObjects()
end end
-- fill lower half -- fill lower half
local col = Collision:New( local col = Collision:new(
base_x, base_x,
base_y + tileProperties.height/2 * tileProperties.scale, base_y + tileProperties.height/2 * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -507,7 +507,7 @@ function TileCreateObjects()
elseif type == "ramp2_bot_right_half" then elseif type == "ramp2_bot_right_half" then
for k = 1, 8 do for k = 1, 8 do
-- do ramp owo -- do ramp owo
local slope = Collision:New( local slope = Collision:new(
base_x + (k-8) * -2 * tileProperties.scale, base_x + (k-8) * -2 * tileProperties.scale,
base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale, base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -520,7 +520,7 @@ function TileCreateObjects()
elseif type == "ramp2_top_right_half" then elseif type == "ramp2_top_right_half" then
for k = 1, 8 do for k = 1, 8 do
-- do ramp owo -- do ramp owo
local slope = Collision:New( local slope = Collision:new(
base_x + (k-8) * -2 * tileProperties.scale, base_x + (k-8) * -2 * tileProperties.scale,
base_y + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale, base_y + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -533,7 +533,7 @@ function TileCreateObjects()
elseif type == "ramp2_top_right_whole" then elseif type == "ramp2_top_right_whole" then
for k = 1, 8 do for k = 1, 8 do
-- do ramp owo -- do ramp owo
local slope = Collision:New( local slope = Collision:new(
base_x + (k-8) * -2 * tileProperties.scale, base_x + (k-8) * -2 * tileProperties.scale,
base_y + tileProperties.height/2 * tileProperties.scale + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale, base_y + tileProperties.height/2 * tileProperties.scale + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -543,7 +543,7 @@ function TileCreateObjects()
end end
-- fill higher half -- fill higher half
local col = Collision:New( local col = Collision:new(
base_x, base_x,
base_y, base_y,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -555,7 +555,7 @@ function TileCreateObjects()
for k = 1, 16 do for k = 1, 16 do
-- do ramp owo -- do ramp owo
local slope = Collision:New( local slope = Collision:new(
base_x, base_x,
base_y + k * tileProperties.scale - tileProperties.scale, base_y + k * tileProperties.scale - tileProperties.scale,
base_x + k * tileProperties.scale, base_x + k * tileProperties.scale,
@ -567,7 +567,7 @@ function TileCreateObjects()
elseif type == "ladder_right" then elseif type == "ladder_right" then
local ladder = Collision:New( local ladder = Collision:new(
base_x + (tileProperties.width-4)* tileProperties.scale, base_x + (tileProperties.width-4)* tileProperties.scale,
base_y, base_y,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -577,7 +577,7 @@ function TileCreateObjects()
elseif type == "ladder_platform_right" then elseif type == "ladder_platform_right" then
local ladder = Collision:New( local ladder = Collision:new(
base_x + (tileProperties.width-4)* tileProperties.scale, base_x + (tileProperties.width-4)* tileProperties.scale,
base_y + tileProperties.scale * 2, base_y + tileProperties.scale * 2,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -585,7 +585,7 @@ function TileCreateObjects()
) )
table.insert(LoadedObjects.Ladders,ladder) table.insert(LoadedObjects.Ladders,ladder)
local plat = Collision:New( local plat = Collision:new(
base_x, base_x,
base_y + tileProperties.scale * 2, base_y + tileProperties.scale * 2,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -596,7 +596,7 @@ function TileCreateObjects()
elseif type == "ladder_left" then elseif type == "ladder_left" then
local ladder = Collision:New( local ladder = Collision:new(
base_x, base_x,
base_y, base_y,
base_x + tileProperties.scale * 4, base_x + tileProperties.scale * 4,
@ -607,7 +607,7 @@ function TileCreateObjects()
elseif type == "ladder_platform_left" then elseif type == "ladder_platform_left" then
local ladder = Collision:New( local ladder = Collision:new(
base_x, base_x,
base_y + tileProperties.scale * 2, base_y + tileProperties.scale * 2,
base_x + tileProperties.scale * 4, base_x + tileProperties.scale * 4,
@ -615,7 +615,7 @@ function TileCreateObjects()
) )
table.insert(LoadedObjects.Ladders,ladder) table.insert(LoadedObjects.Ladders,ladder)
local plat = Collision:New( local plat = Collision:new(
base_x, base_x,
base_y + tileProperties.scale * 2, base_y + tileProperties.scale * 2,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,
@ -626,7 +626,7 @@ function TileCreateObjects()
elseif type == "bottom_hazard" then elseif type == "bottom_hazard" then
local hazard = Collision:New( local hazard = Collision:new(
base_x, base_x,
base_y + tileProperties.height * 12/16 * tileProperties.scale, base_y + tileProperties.height * 12/16 * tileProperties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tileProperties.width * tileProperties.scale,

View File

@ -1,7 +1,7 @@
Light = {} Light = {}
LoadedObjects.Lights = {} LoadedObjects.Lights = {}
function Light:New(x,y,range,flicker,color,lum) function Light:new(x,y,range,flicker,color,lum)
local o = {} local o = {}
o.pos = { o.pos = {
x = x, x = x,
@ -10,8 +10,8 @@ function Light:New(x,y,range,flicker,color,lum)
o.range = range o.range = range
o.lum = lum or 1 o.lum = lum or 1
o.color = color or {1,1,1} o.color = color or {1,1,1}
o.flicker_value = flicker or 2 o.flicker_amount = flicker or 2
o.flicker = 0 o.flicker_value = 0
o.dim = 0 o.dim = 0
o.flicker_time = 60/12 o.flicker_time = 60/12
o.flicker_timer = 0 o.flicker_timer = 0
@ -24,7 +24,7 @@ function Light:New(x,y,range,flicker,color,lum)
return o return o
end end
function Light:Kill() function Light:kill()
if self.id ~= nil then if self.id ~= nil then
for _, e in pairs(LoadedObjects.Lights) do for _, e in pairs(LoadedObjects.Lights) do
if e.id > self.id then if e.id > self.id then
@ -36,12 +36,12 @@ function Light:Kill()
self = nil self = nil
end end
function Light:Flicker() function Light:flicker()
self.flicker_timer = self.flicker_timer + 1 self.flicker_timer = self.flicker_timer + 1
if self.flicker_timer >= self.flicker_time then if self.flicker_timer >= self.flicker_time then
self.flicker_timer = self.flicker_timer - self.flicker_time self.flicker_timer = self.flicker_timer - self.flicker_time
self.flicker = math.random(0,1) self.flicker_value = math.random(0,1)
self.flicker = math.min(math.max(self.flicker, -self.flicker_value), self.flicker_value) self.flicker_value = math.min(math.max(self.flicker_value, -self.flicker_amount), self.flicker_amount)
end end
end end

View File

@ -97,14 +97,14 @@ function MenuInit(menu,parameter)
end end
function MenuInitDialog(parameter) function MenuInitDialog(parameter)
DialogContainer = interfaceDialog:New() DialogContainer = interfaceDialog:new()
DialogContainer:loadSequence(parameter) DialogContainer:loadSequence(parameter)
end end
function MenuInitPauseScreen() function MenuInitPauseScreen()
local buttonStandard = {width = 200, height = 30, separation = 10} local buttonStandard = {width = 200, height = 30, separation = 10}
-- elements -- elements
PauseResume = interfaceButton:New( PauseResume = interfaceButton:new(
game.width/2, game.width/2,
game.height/2-buttonStandard.height-buttonStandard.separation, game.height/2-buttonStandard.height-buttonStandard.separation,
buttonStandard.width, buttonStandard.width,
@ -117,7 +117,7 @@ function MenuInitPauseScreen()
color2 = {1,1,1} color2 = {1,1,1}
} }
) )
PauseOptions = interfaceButton:New( PauseOptions = interfaceButton:new(
game.width/2, game.width/2,
game.height/2, game.height/2,
buttonStandard.width, buttonStandard.width,
@ -130,7 +130,7 @@ function MenuInitPauseScreen()
color2 = {1,1,1} color2 = {1,1,1}
} }
) )
PauseExit = interfaceButton:New( PauseExit = interfaceButton:new(
game.width/2, game.width/2,
game.height/2+buttonStandard.height+buttonStandard.separation, game.height/2+buttonStandard.height+buttonStandard.separation,
buttonStandard.width, buttonStandard.width,

View File

@ -1,9 +1,9 @@
LoadedObjects = {} LoadedObjects = {}
-- level functions -- level functions
function LoadedObjects.DrawCollisions() function LoadedObjects.drawCollisions()
for _, ladder in pairs(LoadedObjects.Collisions) do for _, ladder in pairs(LoadedObjects.Collisions) do
ladder:Draw(1) ladder:draw(1)
end end
for _, platform in pairs(LoadedObjects.Platforms) do for _, platform in pairs(LoadedObjects.Platforms) do
@ -12,11 +12,11 @@ function LoadedObjects.DrawCollisions()
end end
for _, ladder in pairs(LoadedObjects.Ladders) do for _, ladder in pairs(LoadedObjects.Ladders) do
ladder:Draw(2) ladder:draw(2)
end end
for _, hazard in pairs(LoadedObjects.Hazards) do for _, hazard in pairs(LoadedObjects.Hazards) do
hazard:Draw(1) hazard:draw(1)
end end
end end
@ -45,7 +45,7 @@ function isThereCollisionAt(x,y)
end end
-- flags -- flags
function SetCollisionFlags() function setCollisionFlags()
local Check = { local Check = {
LoadedObjects.Collisions, LoadedObjects.Collisions,
LoadedObjects.Ladders, LoadedObjects.Ladders,

View File

@ -1,82 +0,0 @@
Particle = Entity:New(x,y)
function Particle:New(x,y,particle_data)
local o = Entity:New(x,y)
o.pos = {x = x, y = y}
o.speed = particle_data.speed or 0
o.direction = particle_data.direction or o.direction
o.sprite_rotation = particle_data.sprite_rotation or o.sprite_rotation
o.sprite_offset = particle_data.sprite_offset or o.sprite_offset
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint
o.sprite_alpha = particle_data.sprite_alpha or o.sprite_alpha
o.sprite_alpha_base = o.sprite_alpha
o.sprite_flip = particle_data.sprite_flip or o.sprite_flip
o.animation_active = particle_data.animation_active or false
o.time = 0.5
o.timer = 0
o.vel = {
x = o.speed * math.cos(o.direction),
y = o.speed * math.sin(o.direction)
}
if particle_data.light ~= nil then
o.lightRange = particle_data.light
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
end
-- animations
o.body = Animation:New(particle_data.animation)
o:centerOffset(o.body)
if not o.animation_active then
o.body.speed = 0
end
table.insert(LoadedParticles,o)
o.id = #LoadedParticles
setmetatable(o, self)
self.__index = self
return o
end
function Particle:Kill()
if self.light ~= nil then
KillLight(self.light)
end
if self.id ~= nil then
for _, e in pairs(LoadedParticles) do
if e.id > self.id then
e.id = e.id - 1
end
end
table.remove(LoadedParticles,self.id)
end
self = nil
end
function Particle:HandleAnimation()
self.body:Animate()
self.timer = self.timer + current_dt
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
if self.light ~= nil then
self.light.range = self.lightRange * self.sprite_alpha/2
end
if self.sprite_alpha < 0 then self:Kill() end
self:Draw(self.body)
end
function Particle:DoPhysics()
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, objects.collisions) then
self.pos.x = self.pos.x + self.vel.x
end
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, objects.collisions) then
self.pos.y = self.pos.y + self.vel.y
end
end

View File

@ -1,6 +1,6 @@
Queue = {} Queue = {}
function Queue:New() function Queue:new()
local o = {head = nil, tail = nil} local o = {head = nil, tail = nil}
setmetatable(o, self) setmetatable(o, self)
@ -40,7 +40,7 @@ function Queue:Dequeue()
return item return item
end end
local tq1 = Queue:New() local tq1 = Queue:new()
tq1:Enqueue(5) tq1:Enqueue(5)
assert(tq1.head.item == 5) assert(tq1.head.item == 5)
assert(tq1:Dequeue() == 5) assert(tq1:Dequeue() == 5)
@ -48,11 +48,11 @@ assert(tq1:Dequeue() == 5)
-- queue that keeps a rolling tally of its arguments -- queue that keeps a rolling tally of its arguments
AvgQueue = {} AvgQueue = {}
function AvgQueue:New(n, initial) function AvgQueue:new(n, initial)
local o = {} local o = {}
o.n = n o.n = n
o.queue = Queue:New() o.queue = Queue:new()
o.avg = initial o.avg = initial

View File

@ -1,7 +1,7 @@
interfaceButton = {type = "Button"} InterfaceButton = {type = "Button"}
-- centered buttons -- centered buttons
function interfaceButton:New(x,y,w,h,table_values,value,style) function InterfaceButton:new(x,y,w,h,table_values,value,style)
local o = {} local o = {}
o.pos = { o.pos = {
@ -46,11 +46,11 @@ function interfaceButton:New(x,y,w,h,table_values,value,style)
return o return o
end end
function interfaceButton:getVariable() function InterfaceButton:getVariable()
return self.target_variable return self.target_variable
end end
function interfaceButton:checkMouse(mouse_x, mouse_y) function InterfaceButton:checkMouse(mouse_x, mouse_y)
if not self.clicked if not self.clicked
and mouse_x < self.pos.x + self.size.w/2 and mouse_x < self.pos.x + self.size.w/2
and mouse_x > self.pos.x - self.size.w/2 and mouse_x > self.pos.x - self.size.w/2
@ -71,7 +71,7 @@ function interfaceButton:checkMouse(mouse_x, mouse_y)
end end
end end
function interfaceButton:Draw() function InterfaceButton:Draw()
local c1, c2, c3, a = love.graphics.getColor() local c1, c2, c3, a = love.graphics.getColor()
love.graphics.setColor(self.style.color[1],self.style.color[2],self.style.color[3],self.style.alpha) love.graphics.setColor(self.style.color[1],self.style.color[2],self.style.color[3],self.style.alpha)

View File

@ -1,6 +1,6 @@
interfaceDialog = {type = "Dialog"} InterfaceDialog = {type = "Dialog"}
-- dialog boxes -- dialog boxes
function interfaceDialog:New(style) function InterfaceDialog:new(style)
local o = {} local o = {}
o.pos = { o.pos = {
@ -36,7 +36,7 @@ function interfaceDialog:New(style)
return o return o
end end
function interfaceDialog:updateContents() function InterfaceDialog:updateContents()
if self.value < self.target_value then if self.value < self.target_value then
self.contents = self.sequence[self.value] self.contents = self.sequence[self.value]
if self.contents[1] == nil then self.contents[1] = "" end if self.contents[1] == nil then self.contents[1] = "" end
@ -45,14 +45,14 @@ function interfaceDialog:updateContents()
end end
end end
function interfaceDialog:loadSequence(sequence) function InterfaceDialog:loadSequence(sequence)
self.sequence = sequence self.sequence = sequence
self.value = 1 self.value = 1
self.target_value = 1+#sequence self.target_value = 1+#sequence
self:updateContents() self:updateContents()
end end
function interfaceDialog:checkConfirm() function InterfaceDialog:checkConfirm()
if not self.clicked then if not self.clicked then
if love.mouse.isDown(1) then if love.mouse.isDown(1) then
self.clicked = true self.clicked = true
@ -65,7 +65,7 @@ function interfaceDialog:checkConfirm()
end end
end end
function interfaceDialog:Draw() function InterfaceDialog:Draw()
local c1, c2, c3, a = love.graphics.getColor() local c1, c2, c3, a = love.graphics.getColor()
love.graphics.setColor(self.style.color[1],self.style.color[2],self.style.color[3],self.style.alpha) love.graphics.setColor(self.style.color[1],self.style.color[2],self.style.color[3],self.style.alpha)

View File

@ -26,7 +26,7 @@ function love.load()
require "code/require" require "code/require"
fps_history = AvgQueue:New(30,60) fps_history = AvgQueue:new(30,60)
logPrint(loveInitLog) logPrint(loveInitLog)
@ -50,14 +50,14 @@ function love.load()
memoryUsage, dtcount = 0, 0 memoryUsage, dtcount = 0, 0
logPrint("mothback: "..collectgarbage("count").." kB, Loading time: "..os.clock().." seconds") logPrint("mothback: "..collectgarbage("count").." kB, Loading time: "..os.clock().." seconds")
main_Player = Player:New(75,50) main_Player = Player:new(75,50)
--Kupo:New(100,150) --Kupo:new(100,150)
--Kupo:New(300,150) --Kupo:new(300,150)
HookAnchor:New(200,89) HookAnchor:new(200,89)
HookAnchor:New(400,89) HookAnchor:new(400,89)
Fairy:New(200,88) Fairy:new(200,88)
--CursedBook:New(180,68) --CursedBook:new(180,68)
--love.audio.play(music.placeholder) --love.audio.play(music.placeholder)
end end
@ -71,7 +71,7 @@ function love.update(dt)
current_dt = dt current_dt = dt
game.secondsSinceStart = game.secondsSinceStart + dt game.secondsSinceStart = game.secondsSinceStart + dt
if DemoRecording or DemoPlayback then Demo:Step() end if DemoRecording or DemoPlayback then Demo:step() end
-- things per second -- things per second
dtcount = dtcount + dt dtcount = dtcount + dt
@ -100,16 +100,16 @@ function love.update(dt)
--editor --editor
if editor_mode then if editor_mode then
EditorStep() stepEditor()
else else
GameStep() stepGame()
end end
end end
function love.wheelmoved(_, y) function love.wheelmoved(_, y)
if editor_mode then if editor_mode then
EditorScroll(y) scrollEditor(y)
end end
end end
@ -123,16 +123,16 @@ function love.draw()
end end
if editor_mode then if editor_mode then
EditorDraw() drawEditor()
else else
GameDraw() drawGame()
end end
if menu_type ~= nil then MenuDraw(menu_type) end if menu_type ~= nil then MenuDraw(menu_type) end
love.graphics.print(game.scale,10,40) love.graphics.print(game.scale,10,40)
if DemoRecording or DemoPlayback then Demo:Draw() end if DemoRecording or DemoPlayback then Demo:draw() end
frameDebugFlush() frameDebugFlush()
end end