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 = {}
function Animation:New(anim_data)
function Animation:new(anim_data)
local o = {}
o.path = anim_data.path
@ -14,17 +14,17 @@ function Animation:New(anim_data)
return o
end
function Animation:ChangeTo(anim_data)
function Animation:change(anim_data)
if anim_data.path == self.path
then
return self
else
return Animation:New(anim_data)
return Animation:new(anim_data)
end
end
-- 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
frame = #self.frames
end
@ -43,7 +43,7 @@ function Animation:DrawFrame(frame, x, y, rotate, sx, sy)
end
-- to linearly animate
function Animation:Animate()
function Animation:animate()
if self.frames[self.frame] ~= 0 then
-- try to animate
self.subframe = self.subframe + current_dt
@ -61,7 +61,7 @@ function Animation:Animate()
end
-- 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 y = y or 0
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)
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.y = math.max(0,math.min(self.pos.y,LevelData.Height-self.height/game.scale))
end

View File

@ -1,6 +1,6 @@
Canvas = {class = "Canvas"}
function Canvas:New(name)
function Canvas:new(name)
local o = {}
o.name = name
o.width = game.width/game.scale
@ -12,12 +12,12 @@ function Canvas:New(name)
return o
end
function Canvas:Recreate()
function Canvas:recreate()
self.canvas:release()
self.canvas = love.graphics.newCanvas(self.width,self.height)
end
function Canvas:Reset()
function Canvas:reset()
love.graphics.setCanvas(self.canvas)
love.graphics.setBlendMode("replace")
love.graphics.setColor(0,0,0,0)
@ -31,18 +31,18 @@ function Canvas:Reset()
love.graphics.setCanvas()
end
function Canvas:DrawingStart()
self:Reset()
function Canvas:startDrawing()
self:reset()
love.graphics.setCanvas(self.canvas)
end
function Canvas:DrawingEnd()
function Canvas:endDrawing()
love.graphics.setCanvas()
love.graphics.setBlendMode("alpha")
love.graphics.setColor(1,1,1,1)
end
function Canvas:Draw()
function Canvas:draw()
love.graphics.draw(self.canvas)
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.setBlendMode("replace")
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
function Collision:New(ox,oy,tx,ty)
function Collision:new(ox,oy,tx,ty)
local o = {isColliding = false, isDisabled = false}
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.y = y-self.height/2
self.to.x = x+self.width/2
self.to.y = y+self.height/2
end
function Collision:PlaceAt(x, y)
function Collision:placeAt(x, y)
self.from.x = x or self.from.x
self.from.y = y or self.from.y
self.to.x = self.from.x + self.width
self.to.y = self.from.x + self.height
end
function Collision:ContainsPoint(x, y)
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)
function Collision:draw(color)
if self.isColliding == true then
love.graphics.setColor(0,1,0,0.5)
elseif color == 1 then
@ -88,10 +88,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

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

View File

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

View File

@ -1,7 +1,7 @@
assert(editor == nil)
editor = { room_mode = false }
function EditorStep()
function stepEditor()
palette = palette or false
AnimateTiles()
if Keybind:CheckPressed(Keybind.editor.room_mode) then
@ -74,7 +74,7 @@ function EditorStep()
end
end
function EditorScroll(y)
function scrollEditor(y)
if palette then
if love.keyboard.isDown("lshift") then
palette_scroll_y = palette_scroll_y + y
@ -87,23 +87,23 @@ function EditorScroll(y)
end
end
function EditorDraw()
GameworldDrawPrepare()
GameworldDrawBackground()
GridDisplay()
GameworldDrawForeground()
GameworldDrawEnd()
EditorDoEdit()
function drawEditor()
startGameworldDraw()
drawGameworldBackground()
drawGridDisplay()
drawGameworldForeground()
endGameworldDraw()
doEditorEdit()
DrawRooms()
drawEditorRooms()
drawSelectingPaletteTile()
DrawSelectingPaletteTile()
if palette then
EditorDoPalette()
doEditorPalette()
end
end
function EditorDoEdit()
function doEditorEdit()
local mouse_x = love.mouse.getX()
local mouse_y = love.mouse.getY()
local horizontal = 1+math.floor(((mouse_x/game.scale) / tileProperties.width) + (Camera.pos.x / tileProperties.width))
@ -145,7 +145,7 @@ function EditorDoEdit()
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))
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
@ -180,7 +180,7 @@ function EditorDoEdit()
end
end
function DrawSelectingPaletteTile()
function drawSelectingPaletteTile()
if selecting_tile ~= nil and selecting_tile ~= 0 then
local mouse_x = love.mouse.getX()
@ -199,7 +199,7 @@ function DrawSelectingPaletteTile()
end
end
function EditorDoPalette()
function doEditorPalette()
local width = LevelData.tileset:getPixelWidth()/tileProperties.width
local height = LevelData.tileset:getPixelHeight()/tileProperties.height
@ -279,3 +279,11 @@ function EditorDoPalette()
1 + LevelData.tileset:getPixelHeight()* ((tileProperties.height+1) / tileProperties.height)
)
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)
local o = Entity:New(x,y)
function Arrow:new(x,y,rotation,speed)
local o = Entity:new(x,y)
o.type = "arrow"
@ -17,9 +17,9 @@ function Arrow:New(x,y,rotation,speed)
o.illuminated = true
-- 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
to = {x = 0.5, y = 0.5} -- gameworld pixels
}
@ -32,11 +32,11 @@ function Arrow:New(x,y,rotation,speed)
return o
end
function Arrow:DrawBackground()
self:Draw(self.body)
function Arrow:drawBackground()
self:draw(self.body)
end
function Arrow:DoPhysics()
function Arrow:doPhysics()
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
else

View File

@ -1,7 +1,7 @@
CursedBook = Entity:New()
CursedBook = Entity:new()
function CursedBook:New(x,y)
local o = Entity:New(x,y)
function CursedBook:new(x,y)
local o = Entity:new(x,y)
o.type = "cursed_book"
-- behaviour
@ -20,14 +20,14 @@ function CursedBook:New(x,y)
o.attack_range = 50
-- 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:centerOffset(o.body)
o:getBoundingBox(o.body)
o:createBox(o.body)
-- light
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)
o.id = #LoadedObjects.Entities
@ -37,7 +37,7 @@ function CursedBook:New(x,y)
return o
end
function CursedBook:Smart()
function CursedBook:doLogic()
self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y
local distance_x = self.target.x - self.pos.x
@ -66,7 +66,7 @@ function CursedBook:Smart()
end
end
function CursedBook:HandleAnimation()
function CursedBook:handleAnimation()
if self.status == 1 then
if self.body.path == "assets/entities/cursed_book/spawn" then
self.body.speed = 1/3
@ -74,7 +74,7 @@ function CursedBook:HandleAnimation()
self.sprite_tint = {tint,tint,tint}
if self.body.frame == self.body.frames then
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:getBoundingBox(self.body,2,2,-2,-2)
self:centerOffset(self.body)
@ -82,21 +82,21 @@ function CursedBook:HandleAnimation()
end
elseif self.status == 3 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:centerOffset(self.body)
if self.body.frame == self.body.frames then
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)
end
end
end
self.body:Animate()
self:Draw(self.body)
self.body:animate()
self:draw(self.body)
end
function CursedBook:DoPhysics()
function CursedBook:doPhysics()
if self.isFlying then
local random_x = math.random(-4, 4)/100
local random_y = math.random(-4, 4)/100
@ -105,11 +105,11 @@ function CursedBook:DoPhysics()
end
-- move
self:CollisionMove()
self:LightAdjust()
self:moveWithCollision()
self:adjustLight()
end
function CursedBook:Debug()
function CursedBook:debug()
-- draw center GREEN
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)

View File

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

View File

@ -1,7 +1,7 @@
Fairy = Entity:New()
Fairy = Entity:new()
function Fairy:New(x,y)
local o = Entity:New(x,y)
function Fairy:new(x,y)
local o = Entity:new(x,y)
o.type = "fairy"
@ -14,13 +14,13 @@ function Fairy:New(x,y)
o.hover_distance = 60
-- animations
o.body = Animation:New(animation.fairy.flying)
o.body = Animation:new(animation.fairy.flying)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
o:createBox(o.body)
-- light
o.light_range = 80
o.light = Light:New(o.pos.x,o.pos.y,o.light_range,nil,HEX2RGB("#fed100"))
o.light_radius = 80
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius,nil,HEX2RGB("#fed100"))
-- timer
o.particle_timer = 0
@ -34,9 +34,9 @@ function Fairy:New(x,y)
return o
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.y = main_Player.pos.y + main_Player.target_offset.y
@ -85,31 +85,31 @@ function Fairy:Smart()
speed = 0.8*(distance/50),
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
function Fairy:HandleAnimation()
self.body:Animate()
function Fairy:handleAnimation()
self.body:animate()
--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
function Fairy:DoPhysics()
function Fairy:doPhysics()
local random_x = math.random(-4, 4)/10
local random_y = math.random(-4, 4)/10
self.vel.x = self.vel.x + random_x
self.vel.y = self.vel.y + random_y
self:CollisionMove()
self:moveWithCollision()
self.vel.x = 0
self.vel.y = 0
self:LightAdjust()
self:adjustLight()
end
function Fairy:Debug()
Entity.Debug(self)
self:CheckVisionLineDebug(main_Player,self.vision_range)
function Fairy:debug()
Entity.debug(self)
self:checkVisionLineDebug(main_Player,self.vision_range)
end

View File

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

View File

@ -1,7 +1,7 @@
Kupo = Entity:New()
Kupo = Entity:new()
function Kupo:New(x,y)
local o = Entity:New(x,y)
function Kupo:new(x,y)
local o = Entity:new(x,y)
o.type = "kupo"
@ -12,8 +12,8 @@ function Kupo:New(x,y)
o.sprite_offset = {x = 8, y = 5}
-- animations
o.body = Animation:New(animation.kupo.body)
o.bow = Animation:New(animation.kupo.bow)
o.body = Animation:new(animation.kupo.body)
o.bow = Animation:new(animation.kupo.bow)
-- bow
o.bow_flip = 1
@ -27,8 +27,8 @@ function Kupo:New(x,y)
o.bow_aim_frames = 8
o.hostile = true
o.lightRange = o.range/2
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
o.light_radius = o.range/2
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
@ -38,9 +38,8 @@ function Kupo:New(x,y)
return o
end
function Kupo:Smart()
self.light.pos.x = self.pos.x-self.target_offset.x
self.light.pos.y = self.pos.y-self.target_offset.y
function Kupo:doLogic()
self:adjustLight(self.target_offset.x,self.target_offset.y)
self.target.x = main_Player.pos.x - main_Player.target_offset.x
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
self.bow_aim_frame = self.bow_aim_frame - self.bow_aim_frames
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
else
self.bow_frame = self.bow_frame + 1
@ -130,7 +129,7 @@ function Kupo:Smart()
self.angle = angle
end
function Kupo:HandleAnimation()
function Kupo:handleAnimation()
local distance_x = self.target.x - self.pos.x
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
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)
if self.draw_bow == true then
self.bow:DrawFrame(
self.bow:drawFrame(
math.min(self.bow_frame,self.bow_frames),
self.pos.x + ( 8 * math.sin(self.bow_rotation)),
self.pos.y + (2 - 6 * math.cos(self.bow_rotation)),
@ -156,6 +155,6 @@ function Kupo:HandleAnimation()
end
end
function Kupo:DoPhysics()
self:CollisionMove()
function Kupo:doPhysics()
self:moveWithCollision()
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,9 @@
LoadedObjects = {}
-- level functions
function LoadedObjects.DrawCollisions()
function LoadedObjects.drawCollisions()
for _, ladder in pairs(LoadedObjects.Collisions) do
ladder:Draw(1)
ladder:draw(1)
end
for _, platform in pairs(LoadedObjects.Platforms) do
@ -12,11 +12,11 @@ function LoadedObjects.DrawCollisions()
end
for _, ladder in pairs(LoadedObjects.Ladders) do
ladder:Draw(2)
ladder:draw(2)
end
for _, hazard in pairs(LoadedObjects.Hazards) do
hazard:Draw(1)
hazard:draw(1)
end
end
@ -45,7 +45,7 @@ function isThereCollisionAt(x,y)
end
-- flags
function SetCollisionFlags()
function setCollisionFlags()
local Check = {
LoadedObjects.Collisions,
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 = {}
function Queue:New()
function Queue:new()
local o = {head = nil, tail = nil}
setmetatable(o, self)
@ -40,7 +40,7 @@ function Queue:Dequeue()
return item
end
local tq1 = Queue:New()
local tq1 = Queue:new()
tq1:Enqueue(5)
assert(tq1.head.item == 5)
assert(tq1:Dequeue() == 5)
@ -48,11 +48,11 @@ assert(tq1:Dequeue() == 5)
-- queue that keeps a rolling tally of its arguments
AvgQueue = {}
function AvgQueue:New(n, initial)
function AvgQueue:new(n, initial)
local o = {}
o.n = n
o.queue = Queue:New()
o.queue = Queue:new()
o.avg = initial

View File

@ -1,7 +1,7 @@
interfaceButton = {type = "Button"}
InterfaceButton = {type = "Button"}
-- 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 = {}
o.pos = {
@ -46,11 +46,11 @@ function interfaceButton:New(x,y,w,h,table_values,value,style)
return o
end
function interfaceButton:getVariable()
function InterfaceButton:getVariable()
return self.target_variable
end
function interfaceButton:checkMouse(mouse_x, mouse_y)
function InterfaceButton:checkMouse(mouse_x, mouse_y)
if not self.clicked
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
function interfaceButton:Draw()
function InterfaceButton:Draw()
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)

View File

@ -1,6 +1,6 @@
interfaceDialog = {type = "Dialog"}
InterfaceDialog = {type = "Dialog"}
-- dialog boxes
function interfaceDialog:New(style)
function InterfaceDialog:new(style)
local o = {}
o.pos = {
@ -36,7 +36,7 @@ function interfaceDialog:New(style)
return o
end
function interfaceDialog:updateContents()
function InterfaceDialog:updateContents()
if self.value < self.target_value then
self.contents = self.sequence[self.value]
if self.contents[1] == nil then self.contents[1] = "" end
@ -45,14 +45,14 @@ function interfaceDialog:updateContents()
end
end
function interfaceDialog:loadSequence(sequence)
function InterfaceDialog:loadSequence(sequence)
self.sequence = sequence
self.value = 1
self.target_value = 1+#sequence
self:updateContents()
end
function interfaceDialog:checkConfirm()
function InterfaceDialog:checkConfirm()
if not self.clicked then
if love.mouse.isDown(1) then
self.clicked = true
@ -65,7 +65,7 @@ function interfaceDialog:checkConfirm()
end
end
function interfaceDialog:Draw()
function InterfaceDialog:Draw()
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)

View File

@ -26,7 +26,7 @@ function love.load()
require "code/require"
fps_history = AvgQueue:New(30,60)
fps_history = AvgQueue:new(30,60)
logPrint(loveInitLog)
@ -50,14 +50,14 @@ function love.load()
memoryUsage, dtcount = 0, 0
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(300,150)
HookAnchor:New(200,89)
HookAnchor:New(400,89)
Fairy:New(200,88)
--CursedBook:New(180,68)
--Kupo:new(100,150)
--Kupo:new(300,150)
HookAnchor:new(200,89)
HookAnchor:new(400,89)
Fairy:new(200,88)
--CursedBook:new(180,68)
--love.audio.play(music.placeholder)
end
@ -71,7 +71,7 @@ function love.update(dt)
current_dt = 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
dtcount = dtcount + dt
@ -100,16 +100,16 @@ function love.update(dt)
--editor
if editor_mode then
EditorStep()
stepEditor()
else
GameStep()
stepGame()
end
end
function love.wheelmoved(_, y)
if editor_mode then
EditorScroll(y)
scrollEditor(y)
end
end
@ -123,16 +123,16 @@ function love.draw()
end
if editor_mode then
EditorDraw()
drawEditor()
else
GameDraw()
drawGame()
end
if menu_type ~= nil then MenuDraw(menu_type) end
love.graphics.print(game.scale,10,40)
if DemoRecording or DemoPlayback then Demo:Draw() end
if DemoRecording or DemoPlayback then Demo:draw() end
frameDebugFlush()
end