naming conventions act 2: the end

This commit is contained in:
lustlion 2022-03-06 09:35:45 +01:00
parent edd064c2fd
commit 05bf757ea5
29 changed files with 509 additions and 536 deletions

View File

@ -8,16 +8,16 @@ function debugUI()
love.graphics.print(light.pos.x,light.pos.x,light.pos.y+40) love.graphics.print(light.pos.x,light.pos.x,light.pos.y+40)
end end
love.graphics.print("time: ".. tostring(math.floor(100*game.secondsSinceStart)/100) .." fps: "..fps_current, 10*textScale, 0*textScale, 0, textScale) love.graphics.print("time: ".. tostring(math.floor(100*game.seconds_since_start)/100) .." fps: "..fps_current, 10*text_size, 0*text_size, 0, text_size)
love.graphics.print(--[["CPUtime: "..checkCPUTime("total")..", CPU: "..(math.floor(checkCPUTime("get")*10000)/100).."%,]] "memoryUsage: "..memoryUsage.."kB", 10*textScale, 20*textScale, 0, textScale) love.graphics.print(--[["CPUtime: "..checkCPUTime("total")..", CPU: "..(math.floor(checkCPUTime("get")*10000)/100).."%,]] "memory_usage: "..memory_usage.."kB", 10*text_size, 20*text_size, 0, text_size)
love.graphics.setColor(1,1,1) love.graphics.setColor(1,1,1)
-- lots of variables -- lots of variables
love.graphics.print("LoadedObjects",10*textScale,40*textScale, 0, textScale) love.graphics.print("LoadedObjects",10*text_size,40*text_size, 0, text_size)
local i = 1 local i = 1
for k, v in pairs(LoadedObjects) do for k, v in pairs(LoadedObjects) do
if type(v) == "table" then if type(v) == "table" then
love.graphics.print("<"..k.."> ".. #v,10*textScale,(40+(10*i))*textScale, 0, textScale) love.graphics.print("<"..k.."> ".. #v,10*text_size,(40+(10*i))*text_size, 0, text_size)
i = i + 1 i = i + 1
end end
end end
@ -34,7 +34,7 @@ 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(LoadedObjects.Particles) do
particle:debug() particle:debug()
end end
for _, enty in pairs(LoadedObjects.Entities) do for _, enty in pairs(LoadedObjects.Entities) do

View File

@ -37,8 +37,8 @@ function Demo:startRecord()
os.execute( "mkdir \"./demos\"" ) os.execute( "mkdir \"./demos\"" )
DemoFile = io.open("demos/play_demo.lua", "w+") DemoFile = io.open("demos/play_demo.lua", "w+")
--DemoFile = io.open("demo/mothbackDemo_"..os.date("%Y-%m-%d_%H-%M-%S")..".lua", "w+") --DemoFile = io.open("demo/mothbackDemo_"..os.date("%Y-%m-%d_%H-%M-%S")..".lua", "w+")
DemoFile:write("main_Player.pos.x = "..main_Player.pos.x.."\n") DemoFile:write("main_player.pos.x = "..main_player.pos.x.."\n")
DemoFile:write("main_Player.pos.y = "..main_Player.pos.y.."\n") DemoFile:write("main_player.pos.y = "..main_player.pos.y.."\n")
DemoFile:write("DemoAction = {\n") DemoFile:write("DemoAction = {\n")
DemoRecording = true DemoRecording = true
CurrentDemoFrame = 1 CurrentDemoFrame = 1

View File

@ -3,8 +3,8 @@ editor = { room_mode = false }
function stepEditor() 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
if love.keyboard.isDown("lshift") then if love.keyboard.isDown("lshift") then
editor.room_mode = "delete" editor.room_mode = "delete"
else else
@ -13,7 +13,7 @@ function stepEditor()
editor.room_points = {} editor.room_points = {}
end end
if Keybind:CheckPressed(Keybind.editor.palette) then if Keybind:checkPressed(Keybind.editor.palette) then
if palette then if palette then
palette = false palette = false
palette_scroll_x = nil palette_scroll_x = nil
@ -24,7 +24,9 @@ function stepEditor()
palette_scroll_y = 0 palette_scroll_y = 0
end end
end end
-- TODO: -- TODO:
if love.keyboard.isDown('a',"left") then if love.keyboard.isDown('a',"left") then
Camera.pos.x = Camera.pos.x - 3/game.scale Camera.pos.x = Camera.pos.x - 3/game.scale
end end
@ -39,7 +41,7 @@ function stepEditor()
end end
if palette then if palette then
if Keybind:CheckPressed(Keybind.debug.debug) then if Keybind:checkPressed(Keybind.debug.debug) then
local next = false local next = false
local export = nil local export = nil
for k, v in pairs(tileset) do for k, v in pairs(tileset) do
@ -59,12 +61,12 @@ function stepEditor()
if next then if next then
LevelData.tileset = export LevelData.tileset = export
end end
LevelGetTileData() getLevelTileData()
LevelIndexTiles() indexLevelTiles()
end end
end end
if Keybind:CheckPressed(Keybind.debug.reload) then if Keybind:checkPressed(Keybind.debug.reload) then
Prompt:new({ Prompt:new({
name = "level name", name = "level name",
input = "unnamed", input = "unnamed",
@ -75,16 +77,16 @@ function stepEditor()
input = "level.lua", input = "level.lua",
func = function(file_prompt) func = function(file_prompt)
if file_prompt.canceled then return end if file_prompt.canceled then return end
ExportLevel(name_prompt.input, file_prompt.input) exportLevel(name_prompt.input, file_prompt.input)
end, end,
}):activate() }):activate()
end, end,
}):activate() }):activate()
end end
if Keybind:CheckPressed(Keybind.debug.editor) then if Keybind:checkPressed(Keybind.debug.editor) then
editor_mode = false editor_mode = false
TileCreateObjects() createTileObjects()
end end
end end
@ -120,34 +122,34 @@ end
function doEditorEdit() 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) / tile_properties.width) + (Camera.pos.x / tile_properties.width))
local vertical = 1+math.floor(((mouse_y/game.scale) / tileProperties.height) + (Camera.pos.y / tileProperties.height)) local vertical = 1+math.floor(((mouse_y/game.scale) / tile_properties.height) + (Camera.pos.y / tile_properties.height))
local expand_h = 0 local expand_h = 0
local expand_v = 0 local expand_v = 0
local LevelWidth = LevelGetTileWidth() local level_width = getLevelTileWidth()
local LevelHeight = LevelGetTileHeight() local level_height = getLevelTileHeight()
if horizontal > LevelWidth then if horizontal > level_width then
expand_h = horizontal-LevelWidth expand_h = horizontal-level_width
elseif horizontal < 0 then elseif horizontal < 0 then
expand_h = horizontal expand_h = horizontal
end end
if vertical > LevelHeight then if vertical > level_height then
expand_v = vertical-LevelHeight expand_v = vertical-level_height
elseif vertical < 0 then elseif vertical < 0 then
expand_v = vertical expand_v = vertical
end end
love.graphics.setColor(100, 100, 100, 0.8) love.graphics.setColor(100, 100, 100, 0.8)
love.graphics.print("> " .. horizontal .. ", " .. vertical .. "; " .. math.floor(mouse_x / game.scale + Camera.pos.x) .. ", " .. math.floor(mouse_y / game.scale + Camera.pos.y)) love.graphics.print("> " .. horizontal .. ", " .. vertical .. "; " .. math.floor(mouse_x / game.scale + Camera.pos.x) .. ", " .. math.floor(mouse_y / game.scale + Camera.pos.y))
love.graphics.print("> " .. LevelWidth .. "(" .. expand_h .. "), " .. LevelHeight .. "(".. expand_v .. ")", 0, 10) love.graphics.print("> " .. level_width .. "(" .. expand_h .. "), " .. level_height .. "(".. expand_v .. ")", 0, 10)
if editor.room_mode then if editor.room_mode then
local rx = horizontal * tileProperties.width local rx = horizontal * tile_properties.width
local ry = vertical * tileProperties.height local ry = vertical * tile_properties.height
local r = editor.room_points local r = editor.room_points
if Keybind:CheckPressed(Keybind.generic.rclick) then if Keybind:checkPressed(Keybind.generic.rclick) then
editor.room_points = {} editor.room_points = {}
elseif Keybind:CheckPressed(Keybind.generic.lclick) then elseif Keybind:checkPressed(Keybind.generic.lclick) then
if editor.room_mode == "delete" then if editor.room_mode == "delete" then
for i, room in ipairs(LoadedObjects.Rooms) do for i, room in ipairs(LoadedObjects.Rooms) do
if room:containsPoint(rx, ry) then if room:containsPoint(rx, ry) then
@ -175,21 +177,21 @@ function doEditorEdit()
and love.keyboard.isDown("lshift") ~= true and love.keyboard.isDown("lshift") ~= true
and love.keyboard.isDown("lctrl") ~= true and love.keyboard.isDown("lctrl") ~= true
then then
if Keybind:CheckDown(Keybind.generic.lclick) if Keybind:checkDown(Keybind.generic.lclick)
and selecting_tile ~= nil and selecting_tile ~= nil
then then
SetTile(vertical,horizontal,selecting_tile) setTile(vertical,horizontal,selecting_tile)
elseif Keybind:CheckDown(Keybind.generic.rclick) then elseif Keybind:checkDown(Keybind.generic.rclick) then
SetTile(vertical,horizontal,0) setTile(vertical,horizontal,0)
end end
LevelReloadTiles() reloadLevelTiles()
elseif Keybind:CheckPressed(Keybind.generic.lshift) then elseif Keybind:checkPressed(Keybind.generic.lshift) then
LevelExpandCanvas(math.sign(expand_h),math.sign(expand_v)) expandLevelCanvas(math.sign(expand_h),math.sign(expand_v))
LevelReloadTiles() reloadLevelTiles()
elseif Keybind:CheckPressed(Keybind.generic.lctrl) then elseif Keybind:checkPressed(Keybind.generic.lctrl) then
LevelReduceCanvas(math.sign(expand_h),math.sign(expand_v)) reduceLevelCanvas(math.sign(expand_h),math.sign(expand_v))
LevelReloadTiles() reloadLevelTiles()
end end
end end
end end
@ -199,10 +201,10 @@ function drawSelectingPaletteTile()
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 = math.floor(((mouse_x/game.scale) / tileProperties.width) + (Camera.pos.x / tileProperties.width)) local horizontal = math.floor(((mouse_x/game.scale) / tile_properties.width) + (Camera.pos.x / tile_properties.width))
local vertical = math.floor(((mouse_y/game.scale) / tileProperties.height) + (Camera.pos.y / tileProperties.height)) local vertical = math.floor(((mouse_y/game.scale) / tile_properties.height) + (Camera.pos.y / tile_properties.height))
local draw_x = tileProperties.width * horizontal - Camera.pos.x local draw_x = tile_properties.width * horizontal - Camera.pos.x
local draw_y = tileProperties.height * vertical - Camera.pos.y local draw_y = tile_properties.height * vertical - Camera.pos.y
love.graphics.draw( love.graphics.draw(
LevelData.tileset, LevelData.tileset,
@ -215,16 +217,16 @@ end
function doEditorPalette() function doEditorPalette()
local width = LevelData.tileset:getPixelWidth()/tileProperties.width local width = LevelData.tileset:getPixelWidth()/tile_properties.width
local height = LevelData.tileset:getPixelHeight()/tileProperties.height local height = LevelData.tileset:getPixelHeight()/tile_properties.height
love.graphics.setColor(0,0,0,1) love.graphics.setColor(0,0,0,1)
love.graphics.rectangle( love.graphics.rectangle(
"fill", "fill",
(palette_scroll_x + 1) * (tileProperties.width+1), (palette_scroll_x + 1) * (tile_properties.width+1),
(palette_scroll_y + 1) * (tileProperties.height+1), (palette_scroll_y + 1) * (tile_properties.height+1),
1 + LevelData.tileset:getPixelWidth() * ((tileProperties.width+1) / tileProperties.width), 1 + LevelData.tileset:getPixelWidth() * ((tile_properties.width+1) / tile_properties.width),
1 + LevelData.tileset:getPixelHeight()* ((tileProperties.height+1) / tileProperties.height) 1 + LevelData.tileset:getPixelHeight()* ((tile_properties.height+1) / tile_properties.height)
) )
@ -233,8 +235,8 @@ function doEditorPalette()
local position_y = 1 local position_y = 1
for i = 1, #TileIndex-width-1 do for i = 1, #TileIndex-width-1 do
local tile_x = (palette_scroll_x + position_x) * (tileProperties.width+1) local tile_x = (palette_scroll_x + position_x) * (tile_properties.width+1)
local tile_y = (palette_scroll_y + position_y) * (tileProperties.height+1) local tile_y = (palette_scroll_y + position_y) * (tile_properties.height+1)
love.graphics.draw( love.graphics.draw(
LevelData.tileset, LevelData.tileset,
@ -245,14 +247,14 @@ function doEditorPalette()
1, 1,
1 1
) )
if Keybind:CheckDown(Keybind.generic.lclick) then if Keybind:checkDown(Keybind.generic.lclick) then
local mouse_x = love.mouse.getX() local mouse_x = love.mouse.getX()
local mouse_y = love.mouse.getY() local mouse_y = love.mouse.getY()
if mouse_x > (tile_x) * game.scale if mouse_x > (tile_x) * game.scale
and mouse_x < (tile_x + tileProperties.width) * game.scale and mouse_x < (tile_x + tile_properties.width) * game.scale
and mouse_y > (tile_y) * game.scale and mouse_y > (tile_y) * game.scale
and mouse_y < (tile_y + tileProperties.height) * game.scale and mouse_y < (tile_y + tile_properties.height) * game.scale
then then
selecting_tile = position_x + ((position_y-1) * width) selecting_tile = position_x + ((position_y-1) * width)
@ -260,7 +262,7 @@ function doEditorPalette()
end end
end end
if Keybind:CheckDown(Keybind.generic.rclick) then if Keybind:checkDown(Keybind.generic.rclick) then
selecting_tile = nil selecting_tile = nil
end end
@ -270,8 +272,8 @@ function doEditorPalette()
"line", "line",
tile_x, tile_x,
tile_y, tile_y,
tileProperties.width, tile_properties.width,
tileProperties.height tile_properties.height
) )
love.graphics.setColor(1,1,1,1) love.graphics.setColor(1,1,1,1)
end end
@ -287,10 +289,10 @@ function doEditorPalette()
love.graphics.rectangle( love.graphics.rectangle(
"line", "line",
(palette_scroll_x + 1) * (tileProperties.width+1), (palette_scroll_x + 1) * (tile_properties.width+1),
(palette_scroll_y + 1) * (tileProperties.height+1), (palette_scroll_y + 1) * (tile_properties.height+1),
1 + LevelData.tileset:getPixelWidth() * ((tileProperties.width+1) / tileProperties.width), 1 + LevelData.tileset:getPixelWidth() * ((tile_properties.width+1) / tile_properties.width),
1 + LevelData.tileset:getPixelHeight()* ((tileProperties.height+1) / tileProperties.height) 1 + LevelData.tileset:getPixelHeight()* ((tile_properties.height+1) / tile_properties.height)
) )
end end

View File

@ -24,8 +24,7 @@ function Arrow:new(x,y,rotation,speed)
to = {x = 0.5, y = 0.5} -- gameworld pixels to = {x = 0.5, y = 0.5} -- gameworld pixels
} }
table.insert(LoadedObjects.Entities,o) o:id()
o.id = #LoadedObjects.Entities
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self

View File

@ -29,8 +29,7 @@ function CursedBook:new(x,y)
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) o:id()
o.id = #LoadedObjects.Entities
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
@ -38,8 +37,8 @@ function CursedBook:new(x,y)
end end
function CursedBook:doLogic() 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
local distance_y = self.target.y - self.pos.y local distance_y = self.target.y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y) local angle = GetAngleFromVector(distance_x,distance_y)

View File

@ -17,8 +17,7 @@ function Decoration:new(x,y,animation,light_radius)
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius) o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
end end
table.insert(LoadedObjects.Entities,o) o:id()
o.id = #LoadedObjects.Entities
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self

View File

@ -20,14 +20,13 @@ function Fairy:new(x,y)
-- light -- light
o.light_radius = 80 o.light_radius = 80
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius,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
o.particle_time = 5 o.particle_time = 5
table.insert(LoadedObjects.Entities,o) o:id()
o.id = #LoadedObjects.Entities
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
@ -36,10 +35,10 @@ end
function Fairy:doLogic() 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
local below = 1 local below = 1
while not isThereObjectAt( while not isThereObjectAt(
@ -64,7 +63,7 @@ function Fairy:doLogic()
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
local angle = GetAngleFromVector(distance_x,distance_y) local angle = getAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2) local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
if distance < self.range then if distance < self.range then
@ -80,7 +79,7 @@ function Fairy:doLogic()
local particle_data = { local particle_data = {
animation = animation.particle.simple, animation = animation.particle.simple,
sprite_tint = HEX2RGB("#fed100"), sprite_tint = hex2rgb("#fed100"),
direction = angle-math.rad(180+math.random(60)-30), direction = angle-math.rad(180+math.random(60)-30),
speed = 0.8*(distance/50), speed = 0.8*(distance/50),
speed_increase = -0.01, speed_increase = -0.01,
@ -91,7 +90,7 @@ 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
@ -111,5 +110,5 @@ 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,20 +1,18 @@
HookAnchor = Entity:new() HookAnchor = Entity:new()
function HookAnchor:new(x,y,hookDistance) function HookAnchor:new(x,y,hook_distance)
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.hook_distance = hook_distance 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:createBox(o.body) o:createBox(o.body)
o:id()
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
@ -33,7 +31,7 @@ function HookAnchor:drawBackground()
"fill", "fill",
-Camera.pos.x + self.pos.x, -Camera.pos.x + self.pos.x,
-Camera.pos.y + self.pos.y, -Camera.pos.y + self.pos.y,
self.hookDistance self.hook_distance
) )
end end

View File

@ -30,8 +30,7 @@ function Kupo:new(x,y)
o.light_radius = o.range/2 o.light_radius = o.range/2
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius) o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
table.insert(LoadedObjects.Entities,o) o:id()
o.id = #LoadedObjects.Entities
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
@ -41,12 +40,12 @@ end
function Kupo:doLogic() function Kupo:doLogic()
self:adjustLight(self.target_offset.x,self.target_offset.y) self:adjustLight(self.target_offset.x,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
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
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2) local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
local angle = GetAngleFromVector(distance_x,distance_y) local angle = getAngleFromVector(distance_x,distance_y)
self.draw_bow = false self.draw_bow = false
if distance <= self.range then if distance <= self.range then
if self.hostile == true then if self.hostile == true then

View File

@ -5,64 +5,65 @@ function Player:new(x,y)
o.type = "player" o.type = "player"
-- physics -- physics
o.moveSpeed = 1.3 -- gameworld pixels o.zero_speed = 0.01 -- gameworld pixels
o.zeroSpeed = 0.01 -- gameworld pixels
o.move_x = 0 -- gameworld pixels o.move_x = 0 -- gameworld pixels
o.noDriftFrames = 0 -- frames o.move_speed = 1.3 -- gameworld pixels
o.airFriction = 0.01 -- gameworld pixels o.nodrift_frames = 0 -- frames
o.groundFriction = 0.3 -- gameworld pixels
o.jumpImpulse = 3.5 -- gameworld pixels o.air_friction = 0.01 -- gameworld pixels
o.ground_friction = 0.3 -- gameworld pixels
o.wall_friction = 0.3 -- gameworld pixels
o.coyoteValue = 5 -- frames o.jump_impulse = 3.5 -- gameworld pixels
o.coyoteAmount = 5 -- int
o.coyote_value = 5 -- frames
o.coyote_amount = 5 -- int
o.dashCooldownTime = 0.1 -- seconds
o.dashCooldownTimer = 0 -- seconds
-- dash values -- dash values
o.dashTimer = 0 -- seconds o.dash_timer = 0 -- seconds
o.dashTime = 0.15 -- seconds o.dash_time = 0.15 -- seconds
o.dashDistance = 40 -- gameworld pixels o.dash_distance = 40 -- gameworld pixels
o.dashSpeed = o.dashDistance / (o.dashTime*60) -- pixels o.dash_speed = o.dash_distance / (o.dash_time*60) -- pixels
o.dashCount = 1 -- int o.dash_count = 1 -- int
o.dashAmount = 10 -- int o.dash_amount = 10 -- int
o.dash_cooldown_time = 0.1 -- seconds
o.dash_cooldown_timer = 0 -- seconds
-- hook values -- hook values
o.hookSwingSpeed = math.rad(0.05) o.hook_swing_speed = math.rad(0.05)
o.hookAnchor = { o.hook_anchor = {
x = nil, x = nil,
y = nil y = nil
} }
-- walljump values -- walljump values
o.walljumpNoDriftAmount = 12 o.walljump_nodrift_amount = 12
o.walljumpImpulse = { x = 2.5, y = 3.5 } o.walljump_impulse = { x = 2.5, y = 3.5 }
o.walljumpFriction = 0.3 -- gameworld pixels
-- light values -- light values
o.light_radius = 40 -- screen pixels o.light_radius = 40 -- screen pixels
-- status -- status
o.canJump = true o.can_jump = true
o.canFall = true o.can_fall = true
o.canFriction = true o.can_friction = true
o.canHook = true o.can_hook = true
o.canWalljump = true o.can_walljump = true
o.isDashing = false o.is_dashing = false
o.isHooked = false o.is_hooked = false
o.isSliding = false o.is_sliding = false
o.isJumping = false o.is_jumping = false
o.isOnGround = false o.is_on_ground = false
o.isOnLadder = false o.is_on_ladder = false
o.maskType = animation.moth_mask o.mask_type = animation.moth_mask
o.wallHit = 0 o.wall_hit = 0
o.anchorRespawn = { o.respawn_anchor = {
x = o.pos.x, x = o.pos.x,
y = o.pos.y y = o.pos.y
} }
@ -71,14 +72,14 @@ function Player:new(x,y)
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:createBox(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.light_radius) o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
table.insert(LoadedObjects.Entities,o) o:id()
o.id = #LoadedObjects.Entities
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
@ -86,67 +87,66 @@ function Player:new(x,y)
end end
function Player:doLogic() function Player:doLogic()
self:adjustLight(self.target_offset.x,self.target_offset.y)
-- reset coyoteValue -- reset coyote_value
if self.isOnGround then if self.is_on_ground then
self.coyoteValue = self.coyoteAmount self.coyote_value = self.coyote_amount
elseif self.coyoteValue > 0 then elseif self.coyote_value > 0 then
self.coyoteValue = self.coyoteValue - 1 self.coyote_value = self.coyote_value - 1
end end
-- not dashing, normal movment -- not dashing, normal movment
if self.dashTimer <= 0 then if self.dash_timer <= 0 then
-- horizontal movement -- horizontal movement
if not self.isHooked then if not self.is_hooked then
if self.noDriftFrames > 0 then if self.nodrift_frames > 0 then
self.move_x = 0 self.move_x = 0
elseif Keybind:CheckDown(Keybind.move.left) then elseif Keybind:checkDown(Keybind.move.left) then
self.move_x = -1 self.move_x = -1
self.vel.x = math.min(self.vel.x, -self.moveSpeed) self.vel.x = math.min(self.vel.x, -self.move_speed)
elseif Keybind:CheckDown(Keybind.move.right) then elseif Keybind:checkDown(Keybind.move.right) then
self.move_x = 1 self.move_x = 1
self.vel.x = math.max(self.vel.x, self.moveSpeed) self.vel.x = math.max(self.vel.x, self.move_speed)
end end
end end
-- jump if on ground (coyotevalue) or if 0 -- jump if on ground (coyotevalue) or if 0
if self.canJump and Keybind:CheckPressed(Keybind.move.jump) then if self.can_jump and Keybind:checkPressed(Keybind.move.jump) then
if self.canWalljump and self.wallHit ~= 0 then if self.can_walljump and self.wall_hit ~= 0 then
self.isSliding = false self.is_sliding = false
self.vel.y = -self.walljumpImpulse.y self.vel.y = -self.walljump_impulse.y
self.vel.x = -self.walljumpImpulse.x * self.wallHit self.vel.x = -self.walljump_impulse.x * self.wall_hit
self.move_x = 0 self.move_x = 0
self.sprite_flip.x = -self.sprite_flip.x self.sprite_flip.x = -self.sprite_flip.x
self.noDriftFrames = self.walljumpNoDriftAmount self.nodrift_frames = self.walljump_nodrift_amount
elseif self.coyoteValue > 0 then elseif self.coyote_value > 0 then
self.vel.y = -self.jumpImpulse self.vel.y = -self.jump_impulse
self.coyoteValue = 0 self.coyote_value = 0
end end
end end
end end
-- dash timer -- dash timer
self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt) self.dash_cooldown_timer = math.max(0,self.dash_cooldown_timer - current_dt)
-- try to dash -- try to dash
if Keybind:CheckDown(Keybind.move.dash) then if Keybind:checkDown(Keybind.move.dash) then
if self.dashCooldownTimer == 0 if self.dash_cooldown_timer == 0
and not self.isDashing and not self.is_dashing
and self.dashCount > 0 then and self.dash_count > 0 then
self:unhook() self:unhook()
-- state player -- state player
self.isDashing = true self.is_dashing = true
self.dashCount = self.dashCount - 1 self.dash_count = self.dash_count - 1
-- get dash direction -- get dash direction
local vertical = 0 local vertical = 0
if Keybind:CheckDown(Keybind.move.down) then vertical = vertical + 1 end if Keybind:checkDown(Keybind.move.down) then vertical = vertical + 1 end
if Keybind:CheckDown(Keybind.move.up) then vertical = vertical - 1 end if Keybind:checkDown(Keybind.move.up) then vertical = vertical - 1 end
local horizontal = 0 local horizontal = 0
if Keybind:CheckDown(Keybind.move.right) then horizontal = horizontal + 1 end if Keybind:checkDown(Keybind.move.right) then horizontal = horizontal + 1 end
if Keybind:CheckDown(Keybind.move.left) then horizontal = horizontal - 1 end if Keybind:checkDown(Keybind.move.left) then horizontal = horizontal - 1 end
-- if no direction, then dash forward -- if no direction, then dash forward
if horizontal == 0 and vertical == 0 then if horizontal == 0 and vertical == 0 then
@ -154,23 +154,23 @@ function Player:doLogic()
end end
-- set dash values -- set dash values
self.dashDirection = GetAngleFromVector(horizontal, vertical) self.dashDirection = getAngleFromVector(horizontal, vertical)
self.dashTimer = math.floor(self.dashTime * game.framerate) self.dash_timer = math.floor(self.dash_time * game.framerate)
end end
else else
-- not dashing! -- not dashing!
self.isDashing = false self.is_dashing = false
end end
if self.canHook and Keybind:CheckPressed(Keybind.move.hook) then if self.can_hook and Keybind:checkPressed(Keybind.move.hook) then
if self.isHooked then if self.is_hooked then
self:unhook() self:unhook()
else else
local anchor = self:checkNearest("hook_anchor",self.hookDistance) local anchor = self:checkNearest("hook_anchor",self.hook_distance)
if anchor then if anchor then
self.isHooked = true self.is_hooked = true
self.hookDistance = anchor.hookDistance self.hook_distance = anchor.hook_distance
self.hookAnchor = { self.hook_anchor = {
x = anchor.pos.x, x = anchor.pos.x,
y = anchor.pos.y y = anchor.pos.y
} }
@ -180,39 +180,39 @@ function Player:doLogic()
end end
function Player:doPhysics() function Player:doPhysics()
if self.dashTimer <= 0 then if self.dash_timer <= 0 then
if self.isOnGround then if self.is_on_ground then
self.vel.x = self.vel.x * (1-self.groundFriction) self.vel.x = self.vel.x * (1-self.ground_friction)
else else
self.vel.x = self.vel.x * (1-self.airFriction) self.vel.x = self.vel.x * (1-self.air_friction)
end end
self.isSliding = false self.is_sliding = false
if self.wallHit == 0 then if self.wall_hit == 0 then
self.vel.y = self.vel.y * (1-self.airFriction) self.vel.y = self.vel.y * (1-self.air_friction)
elseif self.noDriftFrames ~= self.walljumpNoDriftAmount then elseif self.nodrift_frames ~= self.walljump_nodrift_amount then
self.isSliding = true self.is_sliding = true
self.vel.y = self.vel.y * (1-self.walljumpFriction) self.vel.y = self.vel.y * (1-self.wall_friction)
end end
if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end if math.abs(self.vel.x) < self.zero_speed then self.vel.x = 0 end
end end
-- reset state -- reset state
self.canFall = true self.can_fall = true
self.isOnGround = false self.is_on_ground = false
-- adjust timers -- adjust timers
self.dashTimer = self.dashTimer - 1 self.dash_timer = self.dash_timer - 1
self.noDriftFrames = self.noDriftFrames - 1 self.nodrift_frames = self.nodrift_frames - 1
-- DASH STATE -- DASH STATE
if self.dashTimer > 0 then if self.dash_timer > 0 then
self.canFall = false self.can_fall = false
-- dash particle -- dash particle
local particle_data = { local particle_data = {
animation = self.body, animation = self.body,
sprite_tint = HEX2RGB("#fed100"), sprite_tint = hex2rgb("#fed100"),
sprite_alpha = 0.5, sprite_alpha = 0.5,
sprite_flip = { sprite_flip = {
x = self.sprite_flip.x, x = self.sprite_flip.x,
@ -220,32 +220,32 @@ function Player:doPhysics()
} }
} }
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.dash_cooldown_timer = self.dash_cooldown_time
-- dash movement -- dash movement
self.vel.x = self.dashSpeed * math.cos(self.dashDirection) self.vel.x = self.dash_speed * math.cos(self.dashDirection)
self.vel.y = self.dashSpeed * math.sin(self.dashDirection) self.vel.y = self.dash_speed * math.sin(self.dashDirection)
end end
-- hook state -- hook state
if self.isHooked then if self.is_hooked then
self.move_x = 0 self.move_x = 0
local hook = Vector(self.pos.x, self.pos.y, self.hookAnchor.x, self.hookAnchor.y) local hook = vector(self.pos.x, self.pos.y, self.hook_anchor.x, self.hook_anchor.y)
local dist = math.min(GetVectorValue(hook), self.hookDistance) local dist = math.min(getVectorValue(hook), self.hook_distance)
local hook_angle = GetAngleFromVector(hook[1],hook[2])-math.rad(180) local hook_angle = getAngleFromVector(hook[1],hook[2])-math.rad(180)
if Keybind:CheckDown(Keybind.move.right) then if Keybind:checkDown(Keybind.move.right) then
hook_angle = hook_angle - self.hookSwingSpeed hook_angle = hook_angle - self.hook_swing_speed
end end
if Keybind:CheckDown(Keybind.move.left) then if Keybind:checkDown(Keybind.move.left) then
hook_angle = hook_angle + self.hookSwingSpeed hook_angle = hook_angle + self.hook_swing_speed
end end
local particle_data = { local particle_data = {
animation = self.body, animation = self.body,
sprite_tint = HEX2RGB("#fed100"), sprite_tint = hex2rgb("#fed100"),
sprite_alpha = 0.5, sprite_alpha = 0.5,
sprite_flip = { sprite_flip = {
x = self.sprite_flip.x, x = self.sprite_flip.x,
@ -254,8 +254,8 @@ function Player:doPhysics()
} }
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.hook_anchor.x + dist * math.cos(hook_angle)
local pos_y = self.hookAnchor.y + dist * math.sin(hook_angle) local pos_y = self.hook_anchor.y + dist * math.sin(hook_angle)
self.vel.x = self.vel.x + pos_x - self.pos.x self.vel.x = self.vel.x + pos_x - self.pos.x
self.vel.y = self.vel.y + pos_y - self.pos.y self.vel.y = self.vel.y + pos_y - self.pos.y
self.pos.x = pos_x self.pos.x = pos_x
@ -263,18 +263,18 @@ function Player:doPhysics()
end end
if self.canFall then if self.can_fall then
-- not in dash -- not in dash
self.dashTimer = 0 self.dash_timer = 0
self.vel.y = self.vel.y + gravity self.vel.y = self.vel.y + gravity
end end
-- horizontal collision -- horizontal collision
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
self.wallHit = 0 self.wall_hit = 0
else else
self.wallHit = math.sign(self.vel.x) self.wall_hit = math.sign(self.vel.x)
self.vel.x = 0 self.vel.x = 0
end end
@ -283,8 +283,8 @@ function Player:doPhysics()
self.pos.y = self.pos.y + self.vel.y self.pos.y = self.pos.y + self.vel.y
else else
if self.vel.y > 0 then if self.vel.y > 0 then
self.isOnGround = true self.is_on_ground = true
self.dashCount = self.dashAmount self.dash_count = self.dash_amount
end end
self.vel.y = 0 self.vel.y = 0
end end
@ -293,16 +293,18 @@ function Player:doPhysics()
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
self:adjustLight(self.target_offset.x,self.target_offset.y)
end end
function Player:respawn() function Player:respawn()
self.pos.x = self.anchorRespawn.x self.pos.x = self.respawn_anchor.x
self.pos.y = self.anchorRespawn.y self.pos.y = self.respawn_anchor.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.is_hooked then
if self.vel.x ~= 0 then if self.vel.x ~= 0 then
self.sprite_flip.x = math.sign(self.vel.x) self.sprite_flip.x = math.sign(self.vel.x)
end end
@ -311,18 +313,18 @@ function Player:handleAnimation()
end end
-- animation priority -- animation priority
if self.vel.y > 1.25 or self.isSliding then if self.vel.y > 1.25 or self.is_sliding then
self.body = self.body:change(animation.nancy.fall) self.body = self.body:change(animation.nancy.fall)
self.mask = self.mask:change(self.maskType.fall) self.mask = self.mask:change(self.mask_type.fall)
elseif self.vel.y < 0 then elseif self.vel.y < 0 then
self.body = self.body:change(animation.nancy.jump) self.body = self.body:change(animation.nancy.jump)
self.mask = self.mask:change(self.maskType.jump) self.mask = self.mask:change(self.mask_type.jump)
elseif self.vel.x + self.move_x ~= 0 then elseif self.vel.x + self.move_x ~= 0 then
self.body = self.body:change(animation.nancy.run) self.body = self.body:change(animation.nancy.run)
self.mask = self.mask:change(self.maskType.run) self.mask = self.mask:change(self.mask_type.run)
else else
self.body = self.body:change(animation.nancy.idle) self.body = self.body:change(animation.nancy.idle)
self.mask = self.mask:change(self.maskType.idle) self.mask = self.mask:change(self.mask_type.idle)
end end
-- special case: idle animation gets slower by time -- special case: idle animation gets slower by time
@ -332,30 +334,30 @@ function Player:handleAnimation()
end end
end end
if self.isHooked then if self.is_hooked then
love.graphics.line( love.graphics.line(
-Camera.pos.x + self.pos.x, -Camera.pos.x + self.pos.x,
-Camera.pos.y + self.pos.y, -Camera.pos.y + self.pos.y,
-Camera.pos.x + self.hookAnchor.x, -Camera.pos.x + self.hook_anchor.x,
-Camera.pos.y + self.hookAnchor.y -Camera.pos.y + self.hook_anchor.y
) )
end end
self.body:animate() self.body:animate()
self:draw(self.body) self:draw(self.body)
if self.dashCount > 0 then if self.dash_count > 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.is_hooked = false
self.hookAnchor = nil self.hook_anchor = nil
end end
function Player:debug() function Player:debug()
Entity.debug(self) Entity.debug(self)
love.graphics.print("wallHit: "..self.wallHit) love.graphics.print("wall_hit: "..self.wall_hit)
end end

View File

@ -30,6 +30,11 @@ function Entity:new(x,y)
return o return o
end end
function Entity:id()
table.insert(LoadedObjects.Entities,self)
self.id = #LoadedObjects.Entities
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
@ -107,7 +112,7 @@ function Entity:checkVisionLine(entity,range)
local distance_x = target_x - self.pos.x local distance_x = target_x - self.pos.x
local distance_y = target_y - self.pos.y local distance_y = target_y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y) local angle = getAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2) local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
local is_colliding = true local is_colliding = true
@ -211,7 +216,7 @@ function Entity:checkVisionLineDebug(entity,range)
local distance_x = target_x - self.pos.x local distance_x = target_x - self.pos.x
local distance_y = target_y - self.pos.y local distance_y = target_y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y) local angle = getAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2) local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
if distance < range then if distance < range then

View File

@ -1,7 +1,7 @@
function stepGame() function stepGame()
setCollisionFlags() setCollisionFlags()
if menu_type == "no" then if menu_type == "no" then
for _, particle in pairs(LoadedParticles) do for _, particle in pairs(LoadedObjects.Particles) do
particle:doLogic() particle:doLogic()
end end
for _, enty in pairs(LoadedObjects.Entities) do for _, enty in pairs(LoadedObjects.Entities) do
@ -16,12 +16,12 @@ function stepGame()
enty:doPhysics() enty:doPhysics()
end end
AnimateTiles() animateTiles()
Camera:followPlayer(main_Player) Camera:followPlayer(main_player)
--Camera:positionCenterAt(main_Player.pos.x, main_Player.pos.y) --Camera:positionCenterAt(main_player.pos.x, main_player.pos.y)
--camera:positionAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height) --camera:positionAt(main_player.pos.x, main_player.pos.y,game.width,game.height)
if Keybind:CheckPressed(Keybind.debug.debug) then if Keybind:checkPressed(Keybind.debug.debug) then
if debug then if debug then
debug = false debug = false
debug_collision = true debug_collision = true
@ -32,23 +32,23 @@ function stepGame()
end end
end end
if Keybind:CheckPressed(Keybind.debug.reposition) then if Keybind:checkPressed(Keybind.debug.reposition) then
if not editor_mode then if not editor_mode then
main_Player.pos.x, main_Player.pos.y = 16,-10 main_player.pos.x, main_player.pos.y = 16,-10
end end
end end
if Keybind:CheckPressed(Keybind.debug.reload) then if Keybind:checkPressed(Keybind.debug.reload) then
MenuClear() MenuClear()
menu_type = "dialog" menu_type = "dialog"
MenuInit("dialog",DialogSequence.Example) MenuInit("dialog",DialogSequence.Example)
end end
if Keybind:CheckPressed(Keybind.debug.editor) then if Keybind:checkPressed(Keybind.debug.editor) then
editor_mode = true editor_mode = true
end end
if Keybind:CheckPressed(Keybind.debug.recording) then if Keybind:checkPressed(Keybind.debug.recording) then
if DemoRecording then if DemoRecording then
Demo:endRecord() Demo:endRecord()
else else
@ -56,7 +56,7 @@ function stepGame()
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:endPlayback() Demo:endPlayback()
else else
@ -88,7 +88,7 @@ function drawGame()
endGameworldDraw() endGameworldDraw()
-- hud -- hud
textScale = 1 text_size = 1
-- debug -- debug
if debug then debugUI() end if debug then debugUI() end

View File

@ -22,10 +22,10 @@ function drawGameworldBackground()
if LevelTiles[i][j].id ~= 0 then if LevelTiles[i][j].id ~= 0 then
local depth = TileData[LevelTiles[i][j].id].depth local depth = TileData[LevelTiles[i][j].id].depth
DrawTile( drawTile(
LevelTiles[i][j], LevelTiles[i][j],
tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.width) - Camera.pos.x, tile_properties.scale * j * tile_properties.width + tile_properties.scale * (level_properties.offset.x - tile_properties.width) - Camera.pos.x,
tileProperties.scale * i * tileProperties.height + tileProperties.scale * (levelProperties.offset.y - tileProperties.height) - Camera.pos.y, tile_properties.scale * i * tile_properties.height + tile_properties.scale * (level_properties.offset.y - tile_properties.height) - Camera.pos.y,
"background" "background"
) )
@ -61,10 +61,10 @@ function drawGameworldForeground()
if LevelTiles[i][j].id ~= 0 then if LevelTiles[i][j].id ~= 0 then
local depth = TileData[LevelTiles[i][j].id].depth local depth = TileData[LevelTiles[i][j].id].depth
DrawTile( drawTile(
LevelTiles[i][j], LevelTiles[i][j],
tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.width) - Camera.pos.x, tile_properties.scale * j * tile_properties.width + tile_properties.scale * (level_properties.offset.x - tile_properties.width) - Camera.pos.x,
tileProperties.scale * i * tileProperties.height + tileProperties.scale * (levelProperties.offset.y - tileProperties.height) - Camera.pos.y, tile_properties.scale * i * tile_properties.height + tile_properties.scale * (level_properties.offset.y - tile_properties.height) - Camera.pos.y,
"foreground" "foreground"
) )
@ -102,12 +102,12 @@ function drawGameworldLights()
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)
Shader.RadiusGradient:send("pos_x",- Camera.pos.x + light.pos.x) shader.circle_gradient:send("pos_x",- Camera.pos.x + light.pos.x)
Shader.RadiusGradient:send("pos_y",- Camera.pos.y + light.pos.y) shader.circle_gradient:send("pos_y",- Camera.pos.y + light.pos.y)
Shader.RadiusGradient:send("range",light.range) shader.circle_gradient:send("range",light.range)
Shader.RadiusGradient:send("scale",game.scale) shader.circle_gradient:send("scale",game.scale)
love.graphics.setShader(Shader.RadiusGradient) love.graphics.setShader(shader.circle_gradient)
love.graphics.circle( love.graphics.circle(
"fill", "fill",
- Camera.pos.x + light.pos.x, - Camera.pos.x + light.pos.x,

View File

@ -1,15 +1,15 @@
function HEX2RGB(color) function hex2rgb(color)
local r1 = HEX2DEX(color:sub(2,2)) local r1 = hex2dec(color:sub(2,2))
local r2 = HEX2DEX(color:sub(3,3)) local r2 = hex2dec(color:sub(3,3))
local g1 = HEX2DEX(color:sub(4,4)) local g1 = hex2dec(color:sub(4,4))
local g2 = HEX2DEX(color:sub(5,5)) local g2 = hex2dec(color:sub(5,5))
local b1 = HEX2DEX(color:sub(6,6)) local b1 = hex2dec(color:sub(6,6))
local b2 = HEX2DEX(color:sub(7,7)) local b2 = hex2dec(color:sub(7,7))
return {(r1*16 + r2)/255, (g1*16 + g2)/255, (b1*16 + b2)/255} return {(r1*16 + r2)/255, (g1*16 + g2)/255, (b1*16 + b2)/255}
end end
function HEX2DEX(hex) function hex2dec(hex)
if hex == "0" then return 0 if hex == "0" then return 0
elseif hex == "1" then return 1 elseif hex == "1" then return 1
elseif hex == "2" then return 2 elseif hex == "2" then return 2

View File

@ -1,4 +1,4 @@
function ExportLevel(levelname, filename) function exportLevel(levelname, filename)
love.filesystem.createDirectory("export") love.filesystem.createDirectory("export")
filename = filename or "output.lua" filename = filename or "output.lua"
if string.sub(filename, 1, 1) ~= "/" then if string.sub(filename, 1, 1) ~= "/" then
@ -22,7 +22,8 @@ function ExportLevel(levelname, filename)
logPrint("- properties") logPrint("- properties")
exportFile:write("\n properties = {") exportFile:write("\n properties = {")
exportFile:write("\n darkness = true") logPrint(" - darkness: ".. tostring(LevelData.properties.darkness))
exportFile:write("\n darkness = " .. tostring(LevelData.properties.darkness))
exportFile:write("\n },") exportFile:write("\n },")
logPrint("- tiles") logPrint("- tiles")
@ -40,12 +41,14 @@ function ExportLevel(levelname, filename)
if i ~= #LevelTiles then if i ~= #LevelTiles then
exportFile:write(", ") exportFile:write(", ")
end end
logPrint(" - Row "..i.."/"..rows.." "..math.floor(100*((i-1)*100/rows))/100 .."%") logPrint(" - row "..i.."/"..rows.." "..math.floor(100*((i-1)*100/rows))/100 .."%")
end end
exportFile:write("\n },") exportFile:write("\n },")
logPrint("- objects") logPrint("- objects")
exportFile:write("\n objects = {}") exportFile:write("\n objects = {")
exportFile:write("\n },")
logPrint("Exporting complete.") logPrint("Exporting complete.")
exportFile:write("\n}") exportFile:write("\n}")

View File

@ -17,7 +17,7 @@ Keybind.debug = {}
Keybind.editor = {} Keybind.editor = {}
Keybind.generic = {} Keybind.generic = {}
function Keybind:CheckDown(action) function Keybind:checkDown(action)
if DemoPlayback then if DemoPlayback then
for _, demo_action in pairs(DemoAction[CurrentDemoFrame]) do for _, demo_action in pairs(DemoAction[CurrentDemoFrame]) do
if demo_action == action.demo then if demo_action == action.demo then
@ -45,8 +45,8 @@ function Keybind:CheckDown(action)
end end
-- relies on being called exactly once per frame to be accurate. -- relies on being called exactly once per frame to be accurate.
function Keybind:CheckPressed(action) function Keybind:checkPressed(action)
if Keybind:CheckDown(action) then if Keybind:checkDown(action) then
if not action.pressed then if not action.pressed then
action.pressed = true action.pressed = true
return true return true
@ -57,7 +57,7 @@ function Keybind:CheckPressed(action)
return false return false
end end
function Keybind:CheckCollision(cat, key) function Keybind:checkCollision(cat, key)
for _, action in pairs(cat) do for _, action in pairs(cat) do
for _, keyname in pairs(action.keys) do for _, keyname in pairs(action.keys) do
if key == keyname then return true end if key == keyname then return true end
@ -66,15 +66,15 @@ function Keybind:CheckCollision(cat, key)
return false return false
end end
function Keybind:AddKey(action, key) function Keybind:addKey(action, key)
table.insert(action.keys, key) table.insert(action.keys, key)
end end
function Keybind:ChangeKey(action, position, key) function Keybind:changeKey(action, position, key)
action.keys[position] = key action.keys[position] = key
end end
function Keybind:RemoveKeys(action) function Keybind:removeKeys(action)
action.keys = {} action.keys = {}
end end
@ -89,7 +89,7 @@ function Keybind:hasKey(action, key)
return false return false
end end
function Keybind:Default() function Keybind:default()
--Menu --Menu
Keybind.menu.pause.keys = {"escape"} Keybind.menu.pause.keys = {"escape"}
Keybind.menu.confirm.keys = {"z", "space", 1} Keybind.menu.confirm.keys = {"z", "space", 1}
@ -114,6 +114,8 @@ function Keybind:Default()
-- Editor -- Editor
Keybind.editor.palette = { keys = {"tab"}} Keybind.editor.palette = { keys = {"tab"}}
Keybind.editor.room_mode = { keys = {"r"}} Keybind.editor.room_mode = { keys = {"r"}}
Keybind.editor.entity_mode = { keys = {"e"}}
Keybind.editor.properties_mode = { keys = {"p"}}
-- Generic -- Generic
Keybind.generic.lclick = { keys = {1}} Keybind.generic.lclick = { keys = {1}}
@ -123,4 +125,4 @@ function Keybind:Default()
end end
-- Set default values at start -- Set default values at start
Keybind:Default() Keybind:default()

View File

@ -1,6 +1,6 @@
function LevelLoadTiles() function loadLevelTiles()
math.randomseed(3) math.randomseed(3)
LevelData = dofile("data/levels/"..currLevel) LevelData = dofile("data/levels/"..level_current)
--[[ --[[
on level format: on level format:
@ -12,19 +12,19 @@ function LevelLoadTiles()
overlay_depth = foreground/background overlay depth overlay_depth = foreground/background overlay depth
type = collision type type = collision type
]] ]]
LevelGetTileData() getLevelTileData()
LevelTiles = LevelData.tiles LevelTiles = LevelData.tiles
LevelUpdateDimensions() updateLevelDimensions()
LevelIndexTiles() indexLevelTiles()
TileCreateObjects() createTileObjects()
end end
function LevelExpandCanvas(horizontal,vertical) function expandLevelCanvas(horizontal,vertical)
local horizontal = horizontal or 0 local horizontal = horizontal or 0
local vertical = vertical or 0 local vertical = vertical or 0
local h = LevelGetTileWidth() local h = getLevelTileWidth()
local v = LevelGetTileHeight() local v = getLevelTileHeight()
-- get new canvas size -- get new canvas size
local newCanvasH = h + math.abs(horizontal) local newCanvasH = h + math.abs(horizontal)
@ -35,7 +35,7 @@ function LevelExpandCanvas(horizontal,vertical)
for i = 1, newCanvasV do for i = 1, newCanvasV do
ExpandedLevel[i] = {} ExpandedLevel[i] = {}
for j = 1, newCanvasH do for j = 1, newCanvasH do
ExpandedLevel[i][j] = InstanceTile(0) ExpandedLevel[i][j] = instanceTile(0)
end end
end end
@ -53,7 +53,7 @@ function LevelExpandCanvas(horizontal,vertical)
-- get data from old canvas to new canvas -- get data from old canvas to new canvas
for i = 1, #LevelTiles do for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do for j = 1, #LevelTiles[i] do
ExpandedLevel[i+expand_v][j+expand_h] = InstanceTile(LevelTiles[i][j].id) ExpandedLevel[i+expand_v][j+expand_h] = instanceTile(LevelTiles[i][j].id)
end end
end end
@ -62,11 +62,11 @@ function LevelExpandCanvas(horizontal,vertical)
end end
function LevelReduceCanvas(horizontal,vertical) function reduceLevelCanvas(horizontal,vertical)
local horizontal = horizontal or 0 local horizontal = horizontal or 0
local vertical = vertical or 0 local vertical = vertical or 0
local h = LevelGetTileWidth() local h = getLevelTileWidth()
local v = LevelGetTileHeight() local v = getLevelTileHeight()
-- get new canvas size -- get new canvas size
local newCanvasH = h - math.abs(horizontal) local newCanvasH = h - math.abs(horizontal)
@ -77,7 +77,7 @@ function LevelReduceCanvas(horizontal,vertical)
for i = 1, newCanvasV do for i = 1, newCanvasV do
ExpandedLevel[i] = {} ExpandedLevel[i] = {}
for j = 1, newCanvasH do for j = 1, newCanvasH do
ExpandedLevel[i][j] = InstanceTile(0) ExpandedLevel[i][j] = instanceTile(0)
end end
end end
@ -95,17 +95,17 @@ function LevelReduceCanvas(horizontal,vertical)
-- get data from old canvas to new canvas -- get data from old canvas to new canvas
for i = 1, #ExpandedLevel do for i = 1, #ExpandedLevel do
for j = 1, #ExpandedLevel[i] do for j = 1, #ExpandedLevel[i] do
ExpandedLevel[i][j] = InstanceTile(LevelTiles[i+expand_v][j+expand_h].id) ExpandedLevel[i][j] = instanceTile(LevelTiles[i+expand_v][j+expand_h].id)
end end
end end
-- use new canvas -- use new canvas
LevelTiles = ExpandedLevel LevelTiles = ExpandedLevel
LevelExpandCanvas() expandLevelCanvas()
end end
function LevelGetTileData() function getLevelTileData()
for k, v in pairs(tileset) do for k, v in pairs(tileset) do
if v == LevelData.tileset then if v == LevelData.tileset then
TileData = dofile("data/tileset/"..k..".lua") TileData = dofile("data/tileset/"..k..".lua")
@ -113,20 +113,20 @@ function LevelGetTileData()
end end
end end
function LevelReloadTiles() function reloadLevelTiles()
LevelUpdateDimensions() updateLevelDimensions()
end end
function LevelUpdateDimensions() function updateLevelDimensions()
LevelData.Width = LevelGetWidth() LevelData.Width = getLevelWidth()
LevelData.Height = LevelGetHeight() LevelData.Height = getLevelHeight()
end end
function LevelGetTileHeight() function getLevelTileHeight()
return #LevelTiles return #LevelTiles
end end
function LevelGetTileWidth() function getLevelTileWidth()
local width = 0 local width = 0
for i = 1, #LevelTiles do for i = 1, #LevelTiles do
if width < #LevelTiles[i] then width = #LevelTiles[i] end if width < #LevelTiles[i] then width = #LevelTiles[i] end
@ -134,42 +134,42 @@ function LevelGetTileWidth()
return width return width
end end
function LevelGetHeight() function getLevelHeight()
return LevelGetTileHeight() * tileProperties.height return getLevelTileHeight() * tile_properties.height
end end
function LevelGetWidth() function getLevelWidth()
return LevelGetTileWidth() * tileProperties.width return getLevelTileWidth() * tile_properties.width
end end
function LevelIndexTiles() function indexLevelTiles()
TileIndex = {} TileIndex = {}
-- index from tileset -- index from tileset
local width = LevelData.tileset:getPixelWidth()/tileProperties.width local width = LevelData.tileset:getPixelWidth()/tile_properties.width
local height = LevelData.tileset:getPixelHeight()/tileProperties.height local height = LevelData.tileset:getPixelHeight()/tile_properties.height
for i = 0, height do for i = 0, height do
for j = 0, width do for j = 0, width do
TileIndex[i*width+j+1] = love.graphics.newQuad( TileIndex[i*width+j+1] = love.graphics.newQuad(
j*tileProperties.width, j*tile_properties.width,
i*tileProperties.height, i*tile_properties.height,
tileProperties.width, tile_properties.width,
tileProperties.height, tile_properties.height,
LevelData.tileset:getDimensions() LevelData.tileset:getDimensions()
) )
end end
end end
TileDataInitialize() initTileData()
-- instance level tiles according to the Properties -- instance level tiles according to the Properties
for i = 1, #LevelTiles do for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do for j = 1, #LevelTiles[i] do
SetTile(i,j,LevelTiles[i][j]) setTile(i,j,LevelTiles[i][j])
end end
end end
end end
function TileDataInitialize() function initTileData()
for _, Properties in pairs(TileData) do for _, Properties in pairs(TileData) do
if Properties.animation ~= nil then if Properties.animation ~= nil then
Properties.tileset = love.graphics.newImage("assets/terrain/"..Properties.animation..".png") Properties.tileset = love.graphics.newImage("assets/terrain/"..Properties.animation..".png")
@ -178,18 +178,18 @@ function TileDataInitialize()
Properties.current_subimage = 1 Properties.current_subimage = 1
local tileset = Properties.tileset local tileset = Properties.tileset
local width = tileset:getPixelWidth()/tileProperties.width local width = tileset:getPixelWidth()/tile_properties.width
local height = tileset:getPixelHeight()/tileProperties.height local height = tileset:getPixelHeight()/tile_properties.height
local image_count = 0 local image_count = 0
for i = 0, height-1 do for i = 0, height-1 do
for j = 0, width-1 do for j = 0, width-1 do
local quad = local quad =
love.graphics.newQuad( love.graphics.newQuad(
j*tileProperties.width, j*tile_properties.width,
i*tileProperties.height, i*tile_properties.height,
tileProperties.width, tile_properties.width,
tileProperties.height, tile_properties.height,
tileset:getDimensions() tileset:getDimensions()
) )
image_count = image_count + 1 image_count = image_count + 1
@ -202,7 +202,7 @@ function TileDataInitialize()
end end
end end
function InstanceTile(id) function instanceTile(id)
local tile = {} local tile = {}
tile.id = id tile.id = id
@ -225,8 +225,8 @@ function InstanceTile(id)
return tile return tile
end end
function SetTile(i,j,id) function setTile(i,j,id)
LevelTiles[i][j] = InstanceTile(id) LevelTiles[i][j] = instanceTile(id)
end end
function drawGridDisplay() function drawGridDisplay()
@ -234,16 +234,16 @@ function drawGridDisplay()
for j = 1, #LevelTiles[i] do for j = 1, #LevelTiles[i] do
love.graphics.rectangle( love.graphics.rectangle(
"line", "line",
tileProperties.scale * (j * tileProperties.width + (levelProperties.offset.x - tileProperties.width)) - Camera.pos.x, tile_properties.scale * (j * tile_properties.width + (level_properties.offset.x - tile_properties.width)) - Camera.pos.x,
tileProperties.scale * (i * tileProperties.height + (levelProperties.offset.y - tileProperties.height)) - Camera.pos.y, tile_properties.scale * (i * tile_properties.height + (level_properties.offset.y - tile_properties.height)) - Camera.pos.y,
tileProperties.scale * tileProperties.width, tile_properties.scale * tile_properties.width,
tileProperties.scale * tileProperties.height tile_properties.scale * tile_properties.height
) )
end end
end end
end end
function TileOptimizeObjects() function optimizeTileObjects()
logPrint("Optimizing Objects...") logPrint("Optimizing Objects...")
local unoptimized = 0 local unoptimized = 0
local isTileOptimized = {} local isTileOptimized = {}
@ -313,14 +313,14 @@ function TileOptimizeObjects()
logPrint("- Group size: "..m.."x"..n) logPrint("- Group size: "..m.."x"..n)
unoptimized = unoptimized + m * n unoptimized = unoptimized + m * n
local base_x = tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.height) local base_x = tile_properties.scale * j * tile_properties.width + tile_properties.scale * (level_properties.offset.x - tile_properties.height)
local base_y = tileProperties.scale * i * tileProperties.height + tileProperties.scale * (levelProperties.offset.y - tileProperties.height) local base_y = tile_properties.scale * i * tile_properties.height + tile_properties.scale * (level_properties.offset.y - tile_properties.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 + tile_properties.width * tile_properties.scale * n,
base_y + tileProperties.height * tileProperties.scale * m base_y + tile_properties.height * tile_properties.scale * m
) )
table.insert(LoadedObjects.Collisions,col) table.insert(LoadedObjects.Collisions,col)
end end
@ -331,13 +331,13 @@ function TileOptimizeObjects()
logPrint("collisions optimized from " .. unoptimized .. " to " .. #LoadedObjects.Collisions) logPrint("collisions optimized from " .. unoptimized .. " to " .. #LoadedObjects.Collisions)
end end
function TileCreateObjects() function createTileObjects()
LoadedObjects.Collisions = {} LoadedObjects.Collisions = {}
LoadedObjects.Platforms = {} LoadedObjects.Platforms = {}
LoadedObjects.Ladders = {} LoadedObjects.Ladders = {}
LoadedObjects.Hazards = {} LoadedObjects.Hazards = {}
TileOptimizeObjects() optimizeTileObjects()
for i = 1, #LevelTiles do for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do for j = 1, #LevelTiles[i] do
@ -345,14 +345,14 @@ function TileCreateObjects()
local type = TileData[LevelTiles[i][j].id].type local type = TileData[LevelTiles[i][j].id].type
local light = TileData[LevelTiles[i][j].id].light local light = TileData[LevelTiles[i][j].id].light
local base_x = tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.height) local base_x = tile_properties.scale * j * tile_properties.width + tile_properties.scale * (level_properties.offset.x - tile_properties.height)
local base_y = tileProperties.scale * i * tileProperties.height + tileProperties.scale * (levelProperties.offset.y - tileProperties.height) local base_y = tile_properties.scale * i * tile_properties.height + tile_properties.scale * (level_properties.offset.y - tile_properties.height)
if light ~= 0 and light ~= nil then if light ~= 0 and light ~= nil then
CreateLight( CreateLight(
base_x + tileProperties.width/2 * tileProperties.scale, base_x + tile_properties.width/2 * tile_properties.scale,
base_y + tileProperties.height/2 * tileProperties.scale, base_y + tile_properties.height/2 * tile_properties.scale,
light light
) )
end end
@ -362,17 +362,17 @@ function TileCreateObjects()
local col = Collision:new( local col = Collision:new(
base_x, base_x,
base_y, base_y,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height * tileProperties.scale base_y + tile_properties.height * tile_properties.scale
) )
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 + tile_properties.height/2 * tile_properties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height * tileProperties.scale base_y + tile_properties.height * tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,col) table.insert(LoadedObjects.Collisions,col)
@ -381,18 +381,18 @@ function TileCreateObjects()
local col = Collision:new( local col = Collision:new(
base_x, base_x,
base_y , base_y ,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height/2 * tileProperties.scale base_y + tile_properties.height/2 * tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,col) table.insert(LoadedObjects.Collisions,col)
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 + tile_properties.height/2 * tile_properties.scale,
base_y, base_y,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height * tileProperties.scale base_y + tile_properties.height * tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,col) table.insert(LoadedObjects.Collisions,col)
@ -401,17 +401,17 @@ function TileCreateObjects()
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 + tile_properties.height/2 * tile_properties.scale,
base_y + tileProperties.height * tileProperties.scale base_y + tile_properties.height * tile_properties.scale
) )
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 + tile_properties.scale * 2,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height/4 * tileProperties.scale + tileProperties.scale * 2 base_y + tile_properties.height/4 * tile_properties.scale + tile_properties.scale * 2
) )
table.insert(LoadedObjects.Platforms,plat) table.insert(LoadedObjects.Platforms,plat)
@ -420,9 +420,9 @@ function TileCreateObjects()
-- 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 * tile_properties.scale - tile_properties.scale,
base_x + k * 2 * tileProperties.scale, base_x + k * 2 * tile_properties.scale,
base_y + k * tileProperties.scale base_y + k * tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,slope) table.insert(LoadedObjects.Collisions,slope)
@ -430,9 +430,9 @@ function TileCreateObjects()
-- 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 + tile_properties.height/2 * tile_properties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height * tileProperties.scale base_y + tile_properties.height * tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,col) table.insert(LoadedObjects.Collisions,col)
@ -441,9 +441,9 @@ function TileCreateObjects()
-- 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 + tile_properties.height/2 * tile_properties.scale + k * tile_properties.scale - tile_properties.scale,
base_x + k * 2 * tileProperties.scale, base_x + k * 2 * tile_properties.scale,
base_y + tileProperties.height/2 * tileProperties.scale + k * tileProperties.scale base_y + tile_properties.height/2 * tile_properties.scale + k * tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,slope) table.insert(LoadedObjects.Collisions,slope)
@ -454,9 +454,9 @@ function TileCreateObjects()
-- 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 + tile_properties.height/2 * tile_properties.scale - tile_properties.scale + k * tile_properties.scale,
base_x + tileProperties.width * tileProperties.scale - (k-1) * 2 * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale - (k-1) * 2 * tile_properties.scale,
base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale + tileProperties.scale base_y + tile_properties.height/2 * tile_properties.scale - tile_properties.scale + k * tile_properties.scale + tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,slope) table.insert(LoadedObjects.Collisions,slope)
@ -465,8 +465,8 @@ function TileCreateObjects()
local col = Collision:new( local col = Collision:new(
base_x, base_x,
base_y, base_y,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height/2 * tileProperties.scale base_y + tile_properties.height/2 * tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,col) table.insert(LoadedObjects.Collisions,col)
@ -475,9 +475,9 @@ function TileCreateObjects()
-- 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 - tile_properties.scale + k * tile_properties.scale,
base_x + tileProperties.width * tileProperties.scale - (k-1) * 2 * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale - (k-1) * 2 * tile_properties.scale,
base_y - tileProperties.scale + k * tileProperties.scale + tileProperties.scale base_y - tile_properties.scale + k * tile_properties.scale + tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,slope) table.insert(LoadedObjects.Collisions,slope)
@ -487,10 +487,10 @@ function TileCreateObjects()
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 * tile_properties.scale,
base_y - tileProperties.scale + k * tileProperties.scale, base_y - tile_properties.scale + k * tile_properties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y - tileProperties.scale + k * tileProperties.scale + tileProperties.scale base_y - tile_properties.scale + k * tile_properties.scale + tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,slope) table.insert(LoadedObjects.Collisions,slope)
@ -498,9 +498,9 @@ function TileCreateObjects()
-- 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 + tile_properties.height/2 * tile_properties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height * tileProperties.scale base_y + tile_properties.height * tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,col) table.insert(LoadedObjects.Collisions,col)
@ -508,10 +508,10 @@ function TileCreateObjects()
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 * tile_properties.scale,
base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale, base_y + tile_properties.height/2 * tile_properties.scale - tile_properties.scale + k * tile_properties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height/2 * tileProperties.scale - tileProperties.scale + k * tileProperties.scale + tileProperties.scale base_y + tile_properties.height/2 * tile_properties.scale - tile_properties.scale + k * tile_properties.scale + tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,slope) table.insert(LoadedObjects.Collisions,slope)
@ -521,10 +521,10 @@ function TileCreateObjects()
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 * tile_properties.scale,
base_y + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale, base_y + tile_properties.height/2 * tile_properties.scale - k * tile_properties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale + tileProperties.scale base_y + tile_properties.height/2 * tile_properties.scale - k * tile_properties.scale + tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,slope) table.insert(LoadedObjects.Collisions,slope)
@ -534,10 +534,10 @@ function TileCreateObjects()
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 * tile_properties.scale,
base_y + tileProperties.height/2 * tileProperties.scale + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale, base_y + tile_properties.height/2 * tile_properties.scale + tile_properties.height/2 * tile_properties.scale - k * tile_properties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height/2 * tileProperties.scale + tileProperties.height/2 * tileProperties.scale - k * tileProperties.scale + tileProperties.scale base_y + tile_properties.height/2 * tile_properties.scale + tile_properties.height/2 * tile_properties.scale - k * tile_properties.scale + tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,slope) table.insert(LoadedObjects.Collisions,slope)
@ -546,8 +546,8 @@ function TileCreateObjects()
local col = Collision:new( local col = Collision:new(
base_x, base_x,
base_y, base_y,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height/2 * tileProperties.scale base_y + tile_properties.height/2 * tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,col) table.insert(LoadedObjects.Collisions,col)
@ -557,9 +557,9 @@ function TileCreateObjects()
-- 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 * tile_properties.scale - tile_properties.scale,
base_x + k * tileProperties.scale, base_x + k * tile_properties.scale,
base_y + k * tileProperties.scale base_y + k * tile_properties.scale
) )
table.insert(LoadedObjects.Collisions,slope) table.insert(LoadedObjects.Collisions,slope)
@ -568,28 +568,28 @@ 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 + (tile_properties.width-4)* tile_properties.scale,
base_y, base_y,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height * tileProperties.scale base_y + tile_properties.height * tile_properties.scale
) )
table.insert(LoadedObjects.Ladders,ladder) table.insert(LoadedObjects.Ladders,ladder)
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 + (tile_properties.width-4)* tile_properties.scale,
base_y + tileProperties.scale * 2, base_y + tile_properties.scale * 2,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height * tileProperties.scale base_y + tile_properties.height * tile_properties.scale
) )
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 + tile_properties.scale * 2,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height/4 * tileProperties.scale + tileProperties.scale * 2 base_y + tile_properties.height/4 * tile_properties.scale + tile_properties.scale * 2
) )
table.insert(LoadedObjects.Platforms,plat) table.insert(LoadedObjects.Platforms,plat)
@ -599,8 +599,8 @@ function TileCreateObjects()
local ladder = Collision:new( local ladder = Collision:new(
base_x, base_x,
base_y, base_y,
base_x + tileProperties.scale * 4, base_x + tile_properties.scale * 4,
base_y + tileProperties.height * tileProperties.scale base_y + tile_properties.height * tile_properties.scale
) )
table.insert(LoadedObjects.Ladders,ladder) table.insert(LoadedObjects.Ladders,ladder)
@ -609,17 +609,17 @@ function TileCreateObjects()
local ladder = Collision:new( local ladder = Collision:new(
base_x, base_x,
base_y + tileProperties.scale * 2, base_y + tile_properties.scale * 2,
base_x + tileProperties.scale * 4, base_x + tile_properties.scale * 4,
base_y + tileProperties.height * tileProperties.scale base_y + tile_properties.height * tile_properties.scale
) )
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 + tile_properties.scale * 2,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height/4 * tileProperties.scale + tileProperties.scale * 2 base_y + tile_properties.height/4 * tile_properties.scale + tile_properties.scale * 2
) )
table.insert(LoadedObjects.Platforms,plat) table.insert(LoadedObjects.Platforms,plat)
@ -628,9 +628,9 @@ function TileCreateObjects()
local hazard = Collision:new( local hazard = Collision:new(
base_x, base_x,
base_y + tileProperties.height * 12/16 * tileProperties.scale, base_y + tile_properties.height * 12/16 * tile_properties.scale,
base_x + tileProperties.width * tileProperties.scale, base_x + tile_properties.width * tile_properties.scale,
base_y + tileProperties.height * tileProperties.scale base_y + tile_properties.height * tile_properties.scale
) )
table.insert(LoadedObjects.Hazards,hazard) table.insert(LoadedObjects.Hazards,hazard)
@ -641,7 +641,7 @@ function TileCreateObjects()
--CreateCollisionTable() --CreateCollisionTable()
end end
function AnimateTiles() function animateTiles()
for _, Properties in pairs(TileData) do for _, Properties in pairs(TileData) do
if Properties ~= nil then if Properties ~= nil then
if Properties.animation ~= nil then if Properties.animation ~= nil then
@ -661,40 +661,7 @@ function AnimateTiles()
end end
end end
function CreateCollisionTable() function drawTile(tile,x,y,depth)
-- init table
CollisionTable = {}
for j=0, 16*LevelGetTileHeight()-1 do
CollisionTable[j] = {}
for i=0, 16*LevelGetTileWidth()-1 do
CollisionTable[j][i] = false
end
end
for _, collision in pairs(LoadedObjects.Collisions) do
for ci=0, math.floor(collision.width)-1 do
for cj=0, math.floor(collision.height)-1 do
print(ci..","..cj)
CollisionTable[collision.from.y+cj][collision.from.x+ci] = true
end
end
end
end
function DrawColisionTable()
for j=1, #CollisionTable do
for i=1, #CollisionTable[j] do
if CollisionTable[j][i] then
love.graphics.setColor(0,1,0,1)
else
love.graphics.setColor(1,0,0,1)
end
love.graphics.points(i,j)
end
end
end
function DrawTile(tile,x,y,depth)
local Properties = TileData[tile.id] local Properties = TileData[tile.id]
if Properties ~= nil then if Properties ~= nil then
@ -707,8 +674,8 @@ function DrawTile(tile,x,y,depth)
x, x,
y, y,
0, 0,
tileProperties.scale, tile_properties.scale,
tileProperties.scale tile_properties.scale
) )
end end
elseif Properties.depth == depth then elseif Properties.depth == depth then
@ -720,8 +687,8 @@ function DrawTile(tile,x,y,depth)
x, x,
y, y,
0, 0,
tileProperties.scale, tile_properties.scale,
tileProperties.scale tile_properties.scale
) )
end end
else else
@ -731,8 +698,8 @@ function DrawTile(tile,x,y,depth)
x, x,
y, y,
0, 0,
tileProperties.scale, tile_properties.scale,
tileProperties.scale tile_properties.scale
) )
end end
end end
@ -747,8 +714,8 @@ function DrawTile(tile,x,y,depth)
x, x,
y, y,
0, 0,
tileProperties.scale, tile_properties.scale,
tileProperties.scale tile_properties.scale
) )
else else
love.graphics.draw( love.graphics.draw(
@ -757,8 +724,8 @@ function DrawTile(tile,x,y,depth)
x, x,
y, y,
0, 0,
tileProperties.scale, tile_properties.scale,
tileProperties.scale tile_properties.scale
) )
end end
end end

View File

@ -1,4 +1,4 @@
function LocaleLoad(ISO639) function loadLocale(ISO639)
local ISO639 = ISO639 or "ENG" local ISO639 = ISO639 or "ENG"
dofile("data/locale/"..ISO639..".lua") dofile("data/locale/"..ISO639..".lua")
dofile("data/dialog_sequences.lua") dofile("data/dialog_sequences.lua")

View File

@ -8,17 +8,17 @@ function math.sign(x)
end end
end end
function Vector(init_x, init_y, final_x, final_y) function vector(init_x, init_y, final_x, final_y)
local distance_x = final_x - init_x local distance_x = final_x - init_x
local distance_y = final_y - init_y local distance_y = final_y - init_y
return {distance_x, distance_y} return {distance_x, distance_y}
end end
function GetVectorValue(vector) function getVectorValue(vector)
return math.sqrt(vector[1] ^ 2 + vector[2] ^ 2) return math.sqrt(vector[1] ^ 2 + vector[2] ^ 2)
end end
function GetAngleFromVector(x,y) function getAngleFromVector(x,y)
local reduce = 0 local reduce = 0
if x < 0 then if x < 0 then
reduce = math.rad(180) reduce = math.rad(180)

View File

@ -1,4 +1,4 @@
function MenuDraw(menu) function drawMenu(menu)
local font = love.graphics.getFont() local font = love.graphics.getFont()
love.graphics.setFont(LocaleFont) love.graphics.setFont(LocaleFont)
@ -6,19 +6,19 @@ function MenuDraw(menu)
love.graphics.setScale() love.graphics.setScale()
if menu == "pause" then if menu == "pause" then
MenuDrawPauseScreen() drawMenuPauseScreen()
elseif menu == "dialog" then elseif menu == "dialog" then
MenuDrawDialog() drawMenuDialog()
end end
for _, element in pairs(UIElement) do for _, element in pairs(UIElement) do
element:Draw() element:draw()
end end
love.graphics.setFont(font) love.graphics.setFont(font)
end end
function MenuDrawPauseScreen() function drawMenuPauseScreen()
-- Parameters -- Parameters
local pauseWidth = 640 local pauseWidth = 640
local pauseHeight = 480 local pauseHeight = 480
@ -32,10 +32,10 @@ function MenuDrawPauseScreen()
love.graphics.rectangle("fill", pauseX, pauseY, pauseWidth, pauseHeight) love.graphics.rectangle("fill", pauseX, pauseY, pauseWidth, pauseHeight)
end end
function MenuDrawDialog() function drawMenuDialog()
end end
function MenuStep(menu) function stepMenu(menu)
-- first get mouse -- first get mouse
local mouse_x, mouse_y = love.mouse.getPosition() local mouse_x, mouse_y = love.mouse.getPosition()
for _, element in pairs(UIElement) do for _, element in pairs(UIElement) do
@ -47,64 +47,64 @@ function MenuStep(menu)
end end
if menu == 0 then if menu == 0 then
elseif menu == "pause" then elseif menu == "pause" then
MenuStepPauseScreen() stepMenuPauseScreen()
elseif menu == "dialog" then elseif menu == "dialog" then
MenuStepDialog() stepMenuDialog()
end end
end end
function MenuStepPauseScreen() function stepMenuPauseScreen()
if PauseResume:getVariable() == true then if PauseResume:getVariable() == true then
PauseResume = nil PauseResume = nil
PauseOptions = nil PauseOptions = nil
PauseExit = nil PauseExit = nil
MenuExit() exitMenu()
elseif PauseExit:getVariable() == true then elseif PauseExit:getVariable() == true then
love.event.quit() love.event.quit()
end end
end end
function MenuStepDialog() function stepMenuDialog()
if DialogContainer.value >= DialogContainer.target_value then if DialogContainer.value >= DialogContainer.target_value then
DialogContainer = nil DialogContainer = nil
MenuExit() exitMenu()
end end
end end
function MenuClear() function clearMenu()
for _, element in pairs(UIElement) do for _, element in pairs(UIElement) do
element = nil element = nil
end end
UIElement = {} UIElement = {}
end end
function MenuExit(to) function exitMenu(to)
MenuClear() clearMenu()
local to = to or "no" local to = to or "no"
menu_type = to menu_type = to
end end
function MenuInit(menu,parameter) function initMenu(menu,parameter)
-- main menu -- main menu
if menu == "pause" then if menu == "pause" then
MenuInitPauseScreen() initMenuPauseScreen()
elseif menu == "dialog" then elseif menu == "dialog" then
if parameter == nil then if parameter == nil then
parameter = DialogSequence.Example parameter = DialogSequence.Example
end end
MenuInitDialog(parameter) initMenuDialog(parameter)
end end
end end
function MenuInitDialog(parameter) function initMenuDialog(parameter)
DialogContainer = interfaceDialog:new() DialogContainer = interfaceDialog:new()
DialogContainer:loadSequence(parameter) DialogContainer:loadSequence(parameter)
end end
function MenuInitPauseScreen() function initMenuPauseScreen()
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

@ -8,7 +8,7 @@ function Queue:new()
return o return o
end end
function Queue:Enqueue(item) function Queue:enqueue(item)
local elem = {item = item} local elem = {item = item}
if self.head == nil then if self.head == nil then
self.head = elem self.head = elem
@ -22,12 +22,12 @@ function Queue:Enqueue(item)
return return
end end
function Queue:Empty() function Queue:empty()
return self.tail == nil return self.tail == nil
end end
function Queue:Dequeue() function Queue:dequeue()
if self:Empty() then if self:empty() then
return nil return nil
end end
@ -41,9 +41,9 @@ function Queue:Dequeue()
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)
-- queue that keeps a rolling tally of its arguments -- queue that keeps a rolling tally of its arguments
AvgQueue = {} AvgQueue = {}
@ -58,7 +58,7 @@ function AvgQueue:new(n, initial)
local x = initial / n local x = initial / n
for _ = 1,n do for _ = 1,n do
o.queue:Enqueue(x) o.queue:enqueue(x)
end end
setmetatable(o, self) setmetatable(o, self)
@ -66,9 +66,9 @@ function AvgQueue:new(n, initial)
return o return o
end end
function AvgQueue:Push(item) function AvgQueue:push(item)
local x = item/self.n local x = item/self.n
self.avg = self.avg + x - self.queue:Dequeue() self.avg = self.avg + x - self.queue:dequeue()
self.queue:Enqueue(x) self.queue:enqueue(x)
return self.avg return self.avg
end end

View File

@ -1,5 +1,3 @@
-- data -- data
require "data/animations" require "data/animations"
require "data/shaders" require "data/shaders"

View File

@ -1,6 +1,6 @@
UIElement = {} UIElement = {}
function AddElement(self) function addElement(self)
table.insert(UIElement,self) table.insert(UIElement,self)
self.id = #UIElement self.id = #UIElement
end end

View File

@ -39,7 +39,7 @@ function InterfaceButton:new(x,y,w,h,table_values,value,style)
scale_proportion = 1.5 scale_proportion = 1.5
} }
AddElement(o) addElement(o)
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
@ -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

@ -29,7 +29,7 @@ function InterfaceDialog:new(style)
scale_proportion = 1 scale_proportion = 1
} }
AddElement(o) addElement(o)
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
@ -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

@ -1,6 +1,6 @@
DialogSequence = {} dialog_sequence = {}
DialogSequence.Example = { dialog_sequence.Example = {
{Locale.dialogue.example[1],Locale.name.fairy}, {Locale.dialogue.example[1],Locale.name.fairy},
{Locale.dialogue.example[2],Locale.name.chaos}, {Locale.dialogue.example[2],Locale.name.chaos},
{Locale.dialogue.example[3],Locale.name.life} {Locale.dialogue.example[3],Locale.name.life}

View File

@ -1,5 +1,5 @@
Shader = {} shader = {}
Shader.RadiusGradient = love.graphics.newShader[[ shader.circle_gradient = love.graphics.newShader[[
uniform float pos_x; uniform float pos_x;
uniform float pos_y; uniform float pos_y;
uniform float range; uniform float range;

View File

@ -1,4 +1,4 @@
levelProperties = { level_properties = {
pos = { pos = {
x = 0, x = 0,
y = 0 y = 0
@ -15,7 +15,7 @@ tileset = {
library = love.graphics.newImage("assets/tileset/library.png") library = love.graphics.newImage("assets/tileset/library.png")
} }
tileProperties = { tile_properties = {
width = 16, width = 16,
height = 16, height = 16,
scale = 1, scale = 1,

View File

@ -1,15 +1,16 @@
function love.load() function love.load()
logging = true logging = true
loveMemUsage = collectgarbage("count") local love_mem_usage = collectgarbage("count")
loveInitLog = "love: "..loveMemUsage.." kB, time: "..os.clock().." seconds" local love_init_log = "love: "..love_mem_usage.." kB, time: "..os.clock().." seconds"
arrow = 0
secs = 0
menu_type = "no" menu_type = "no"
debug = false debug = false
debug_collision = false debug_collision = false
editor_mode = false editor_mode = false
textScale = 1 text_size = 1
love.graphics.setColor(1,1,1) love.graphics.setColor(1,1,1)
@ -17,7 +18,7 @@ function love.load()
love.graphics.setDefaultFilter("nearest") -- good pixel love.graphics.setDefaultFilter("nearest") -- good pixel
game = { game = {
secondsSinceStart = 0, seconds_since_start = 0,
scale = 2, scale = 2,
width = love.graphics.getWidth(), width = love.graphics.getWidth(),
height = love.graphics.getHeight(), height = love.graphics.getHeight(),
@ -29,28 +30,28 @@ function love.load()
fps_history = AvgQueue:new(30,60) fps_history = AvgQueue:new(30,60)
logPrint(loveInitLog) logPrint(love_init_log)
loveInitLog = nil love_init_log = nil
Camera.width = game.width Camera.width = game.width
Camera.height = game.height Camera.height = game.height
levelList = scandir("./data/levels") level_list = scandir("./data/levels")
levelNum = 1 level_current_num = 1
currLevel = levelList[levelNum] level_current = level_list[level_current_num]
logPrint("currLevel: "..currLevel) logPrint("level_current: "..level_current)
LoadedParticles = {}
LevelLoadTiles() loadLevelTiles()
language = "ENG" language = "ENG"
LocaleLoad(language) loadLocale(language)
gravity = 0.14 gravity = 0.14
-- Debug and log stuff -- Debug and log stuff
memoryUsage, dtcount = 0, 0 memory_usage, 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)
@ -78,28 +79,28 @@ function love.update(dt)
-- audio update -- audio update
love.audio.update() love.audio.update()
-- fps counter -- fps counter
fps_current = fps_history:Push(1/dt) fps_current = fps_history:push(1/dt)
current_dt = dt current_dt = dt
game.secondsSinceStart = game.secondsSinceStart + dt game.seconds_since_start = game.seconds_since_start + 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
game.seconds_since_start = game.seconds_since_start + dt
if dtcount >= 1 then if dtcount >= 1 then
if secs == nil then secs = 0 end
secs = secs + 1 secs = secs + 1
dtcount = dtcount - 1 dtcount = dtcount - 1
if debug or logging then if debug or logging then
memoryUsage = math.floor(collectgarbage("count")) memory_usage = math.floor(collectgarbage("count"))
end end
logWrite("Second "..secs..": "..memoryUsage.." kB") logWrite("Second "..secs..": "..memory_usage.." kB")
end end
if Prompt.active_prompt then if Prompt.active_prompt then
-- try to stop the keypress that closed the menu from spilling into the rest of the game -- try to stop the keypress that closed the menu from spilling into the rest of the game
Keybind:CheckPressed(Keybind.menu.pause) Keybind:checkPressed(Keybind.menu.pause)
if Prompt.active_prompt.closing then if Prompt.active_prompt.closing then
Prompt.active_prompt = nil Prompt.active_prompt = nil
else else
@ -119,17 +120,17 @@ function love.update(dt)
end end
--keypressed --keypressed
if Keybind:CheckPressed(Keybind.menu.pause) then if Keybind:checkPressed(Keybind.menu.pause) then
if do_pause then if do_pause then
do_pause = false do_pause = false
else else
menu_type = "pause" menu_type = "pause"
MenuInit(menu_type) initMenu(menu_type)
end end
end end
--MenuStep --MenuStep
if menu_type ~= nil then MenuStep(menu_type) end if menu_type ~= nil then stepMenu(menu_type) end
--editor --editor
if editor_mode then if editor_mode then
@ -161,7 +162,7 @@ function love.draw()
drawGame() drawGame()
end end
if menu_type ~= nil then MenuDraw(menu_type) end if menu_type ~= nil then drawMenu(menu_type) end
love.graphics.print(game.scale,10,40) love.graphics.print(game.scale,10,40)