Compare commits

..

4 Commits

Author SHA1 Message Date
binarycat
577b7576cf added level in new format to repo 2022-03-16 14:21:35 -04:00
binarycat
fa4b2c86b5 somewhat kinda got things working again 2022-03-16 13:54:25 -04:00
binarycat
e8cef497d4 reworking level loading logic 2022-03-16 13:54:25 -04:00
binarycat
b3a12305da trying to do chunked level loading 2022-03-16 13:54:24 -04:00
31 changed files with 348 additions and 479 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 B

After

Width:  |  Height:  |  Size: 92 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 B

After

Width:  |  Height:  |  Size: 88 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 B

After

Width:  |  Height:  |  Size: 97 B

View File

@ -10,8 +10,6 @@ function Animation:new(anim_data,speed)
o.frame = 1
o.speed = speed or 1
o.was_updated = false
setmetatable(o, self)
self.__index = self
return o
@ -51,9 +49,6 @@ end
-- to linearly animate
function Animation:animate()
if self.was_updated then
self.was_updated = false
end
if self.frames[self.frame] ~= 0 then
-- try to animate
self.subframe = self.subframe + self.speed
@ -61,7 +56,6 @@ function Animation:animate()
if self.subframe > self.frames[self.frame]*game.framerate then
self.subframe = self.subframe - self.frames[self.frame]*game.framerate
self.frame = self.frame + 1
self.was_updated = true
end
-- cycle

51
code/chunk.lua Normal file
View File

@ -0,0 +1,51 @@
-- pieces of levels
Chunk = {all = {}}
Chunk.__index = Chunk
-- CLASS METHODS
-- box == nil for global chunks
function Chunk:new(filename, box)
local o = { filename = filename, box = box }
setmetatable(o, self)
self.all[o] = true
end
function Chunk:getExportList()
local r = {}
for chunk in pairs(self.all) do
table.insert(r, {chunk.filename, chunk.box})
end
return r
end
-- INSTANCE METHODS
function Chunk:containsPoint(pt)
return self.box == nil or self.box:containsPoint(pt)
end
function Chunk:load()
if self.loaded then
return
end
logPrint("loading chunk "..self.filename)
self.data = dofile(level_current.."/chunks/"..self.filename)
self.loaded = { rooms = {}, collisions = {} }
LevelTiles = self.data.tiles
indexLevelTiles()
optimizeTileObjects(self.loaded.collisions)
for _, v in ipairs(self.data.rooms or {}) do
local room = Collision:new(v[1],v[2],v[3],v[4])
table.insert(self.data.rooms, room)
table.insert(LoadedObjects.Rooms, room)
end
logPrint("loaded chunk with "..#self.loaded.collisions.." collisions")
end
function Chunk:save(chunkdir)
return love.filesystem.write(chunkdir.."/"..self.filename, "return "..serialize_lua_value(self.data))
end

View File

@ -1,17 +0,0 @@
function class(super, self)
assert(super == nil or super.__index == super)
self = self or {}
self.__index = self
setmetatable(self, super)
return self
end
function getAncestors(self)
local family = self
local list = {}
while family ~= nil do
family = getmetatable(family)
table.insert(list,family)
end
return list
end

View File

@ -1,4 +1,4 @@
Collision = class()
Collision = {}
LoadedObjects.Collisions = {}
LoadedObjects.Platforms = {}
@ -48,6 +48,7 @@ function Collision:new(ox,oy,tx,ty)
end
setmetatable(o, self)
self.__index = self
return o
end

View File

@ -100,7 +100,7 @@ function stepEditor()
if name_prompt.canceled then return end
Prompt:new({
name = "filename",
input = "level.lua",
input = "unnamed_level",
func = function(file_prompt)
if file_prompt.canceled then return end
exportLevel(name_prompt.input, file_prompt.input)

View File

@ -1,7 +1,5 @@
Arrow = class(Entity, {
type = "Arrow",
display = Animation:new(animation.kupo.arrow),
})
Arrow = Entity:new()
Arrow.type = "Arrow"
function Arrow:new(x,y,rotation,speed)

View File

@ -1,7 +1,6 @@
CursedBook = class(Entity, {
type = "CursedBook",
display = Animation:new(animation.cursed_book.flying),
})
CursedBook = Entity:new()
CursedBook.type = "CursedBook"
CursedBook.display = Animation:new(animation.cursed_book.flying)
function CursedBook:new(x,y)
local o = Entity:new(x,y)
@ -29,12 +28,10 @@ function CursedBook:new(x,y)
o:createBox(o.body)
-- light
local light_data = {}
light_data.radius = 500
light_data.shine_radius = 0
light_data.flicker = nil
light_data.color = nil
o.light = Light:new(o.pos.x,o.pos.y,light_data)
o.light_range = 500
--o.light = Light:new(o.pos.x,o.pos.y,o.light_range,2,hex2rgb("#fe00d1"))
o:id()
setmetatable(o, self)
self.__index = self

View File

@ -1,23 +1,23 @@
Decoration = class(Entity, {
type = "Decoration",
supertype = Entity.type,
display = Animation:new(animation.particle.simple),
})
Decoration = Entity:new()
Decoration.type = "Decoration"
Decoration.display = nil
function Decoration:new(x,y,animation,light_data)
function Decoration:new(x,y,animation,light_radius)
local o = Entity:new(x,y)
o.pos = {x = x, y = y}
if animation then
o.body = Animation:new(animation)
o:centerOffset(o.body)
o:createBox(o.body)
-- animations
o.body = Animation:new(animation)
o:centerOffset(o.body)
o:createBox(o.body)
if light_radius ~= nil then
o.light_radius = light_radius
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
end
if light_data then
o.light = Light:new(o.pos.x,o.pos.y,light_data)
end
o:id()
setmetatable(o, self)
self.__index = self
@ -29,4 +29,5 @@ function Decoration:handleAnimation()
self:draw(self.body)
end
require "code/entities/decorations/candelabra"
function Decoration:doPhysics()
end

View File

@ -1,54 +0,0 @@
Candelabra = class(Decoration, {
type = "Candelabra",
display = Animation:new(animation.decoration.candelabra),
})
function Candelabra:new(x,y)
local light_data = {}
light_data.radius = 100
light_data.color = hex2rgb("#fed100")
local o = Decoration:new(x,y,animation.decoration.candelabra,light_data)
o.particle_rate = 5
o.particle_count = 0
setmetatable(o, self)
self.__index = self
return o
end
function Candelabra:handleAnimation()
if self.body.was_updated then
self.particle_count = self.particle_count + 1
while self.particle_count >= self.particle_rate do
local pos = math.floor(math.random(1,3))-2
local particle_data = {}
particle_data.animation = animation.particle.simple
particle_data.sprite_tint = hex2rgb("#ffffff")
particle_data.sprite_alpha_fade = true
particle_data.direction = -math.rad(90)
particle_data.speed = 0.5 + math.random(2)*0.005
particle_data.time = 0.5+math.random(0.5)
particle_data.animation_speed = 1/particle_data.time
particle_data.func = function(self)
--COSINE WAVE FUNCTION
--init variables and constants
self.t = self.t or 0
self.phase = self.phase or math.random(2*math.pi)
local dt = 0.5
local amplitude = 0.5
local frequency = 0.5/game.framerate
--calc
self.t = self.t + dt
self:moveX(amplitude*math.cos(2*math.pi*frequency*self.t+self.phase))
end
Particle:new(self.pos.x+pos*5,self.pos.y-3,particle_data)
self.particle_count = self.particle_count - self.particle_rate
end
end
Decoration.handleAnimation(self)
end

View File

@ -1,7 +1,6 @@
Fairy = class(Entity, {
type = "Fairy",
display = Animation:new(animation.fairy.flying),
})
Fairy = Entity:new()
Fairy.type = "Fairy"
Fairy.display = Animation:new(animation.fairy.flying)
function Fairy:new(x,y)
local o = Entity:new(x,y)
@ -20,17 +19,15 @@ function Fairy:new(x,y)
o:createBox(o.body)
-- light
local light_data = {}
light_data.radius = 80
light_data.shine_radius = 80
light_data.flicker = nil
light_data.color = hex2rgb("#fed100")
o.light = Light:new(o.pos.x,o.pos.y,light_data)
o.light_radius = 80
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius,nil,hex2rgb("#fed100"))
-- timer
o.particle_timer = 0
o.particle_time = 5
o:id()
setmetatable(o, self)
self.__index = self
return o
@ -91,19 +88,16 @@ function Fairy:handleAnimation()
local vector = vector(self.vel.x,self.vel.y)
local angle = getAngleFromVector(vector)
self.particle_timer = 0
local particle_data = {}
particle_data.animation = animation.particle.simple
particle_data.animation_speed = 1
particle_data.sprite_tint = hex2rgb("#fed100")
particle_data.sprite_alpha_fade = true
particle_data.direction = angle-math.rad(180+math.random(60)-30)
particle_data.speed = 1
particle_data.time = 0.75
particle_data.func = function(self)
self.speed = self.speed - 0.01
self.vel.x = self.speed * math.cos(self.direction)
self.vel.y = self.speed * math.sin(self.direction)
end
local particle_data = {
animation = animation.particle.simple,
animation_speed = 1,
sprite_tint = hex2rgb("#fed100"),
sprite_alpha_fade = true,
direction = angle-math.rad(180+math.random(60)-30),
speed = 1,
speed_increase = -0.01,
time = 0.75
}
Particle:new(self.pos.x,self.pos.y,particle_data)
end
end

View File

@ -1,7 +1,6 @@
HookAnchor = class(Entity, {
type = "HookAnchor",
display = Animation:new(animation.fairy.flying),
})
HookAnchor = Entity:new()
HookAnchor.type = "HookAnchor"
HookAnchor.display = Animation:new(animation.fairy.flying)
function HookAnchor:new(x,y,hook_distance)
local o = Entity:new(x,y)
@ -14,6 +13,8 @@ function HookAnchor:new(x,y,hook_distance)
o:centerOffset(o.body)
o:createBox(o.body)
o:id()
setmetatable(o, self)
self.__index = self
return o

View File

@ -1,7 +1,6 @@
Kupo = class(Entity, {
type = "Kupo",
display = Animation:new(animation.kupo.body),
})
Kupo = Entity:new()
Kupo.type = "Kupo"
Kupo.display = Animation:new(animation.kupo.body)
function Kupo:new(x,y)
local o = Entity:new(x,y)
@ -28,13 +27,10 @@ function Kupo:new(x,y)
o.bow_aim_frames = 8
o.hostile = true
-- light values
local light_data = {}
light_data.radius = 100
light_data.shine_radius = 20
light_data.flicker = nil
light_data.color = nil
o.light = Light:new(o.pos.x,o.pos.y,light_data)
o.light_radius = o.range/2
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
o:id()
setmetatable(o, self)
self.__index = self

View File

@ -1,8 +1,8 @@
LoadedObjects.Particles = {}
Particle = class(Entity, {
type = "Particle",
display = Animation:new(animation.particle.simple),
})
Particle = Entity:new()
Particle.type = "Particle"
Particle.display = Animation:new(animation.particle.simple)
function Particle:new(x,y,particle_data)
local o = Entity:new(x,y)
@ -10,19 +10,18 @@ function Particle:new(x,y,particle_data)
o.pos = {x = x, y = y}
o.speed = particle_data.speed or 0
o.direction = particle_data.direction or 0
o.sprite_rotation = particle_data.sprite_rotation or 0
o.sprite_offset = particle_data.sprite_offset or vector(0,0)
o.sprite_scale = particle_data.sprite_scale or vector(1,1)
o.sprite_tint = particle_data.sprite_tint or {1,1,1}
o.sprite_alpha = particle_data.sprite_alpha or 1
o.direction = particle_data.direction or o.direction
o.sprite_rotation = particle_data.sprite_rotation or o.sprite_rotation
o.sprite_offset = particle_data.sprite_offset or o.sprite_offset
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint
o.sprite_alpha = particle_data.sprite_alpha or o.sprite_alpha
o.sprite_alpha_fade = particle_data.sprite_alpha_fade or false
o.sprite_alpha_base = o.sprite_alpha
o.sprite_flip = particle_data.sprite_flip or vector(1,1)
o.func = particle_data.func or nil
o.time = particle_data.time or nil
o.sprite_flip = particle_data.sprite_flip or o.sprite_flip
if o.time then
o.time = particle_data.time or nil
if o.time ~= nil then
if particle_data.time_unit ~= nil
and particle_data.time_unit == "frames" then
o.time = o.time
@ -37,34 +36,44 @@ function Particle:new(x,y,particle_data)
y = o.speed * math.sin(o.direction)
}
if particle_data.light then
local light_data = {}
light_data.radius = particle_data.light
light_data.shine_radius = particle_data.light_shine or nil
light_data.flicker = particle_data.light_flicer or nil
light_data.color = particle_data.light_color or nil
o.light = Light:new(o.pos.x,o.pos.y,light_data)
o.speed_increase = particle_data.speed_increase or 0
if particle_data.light ~= nil then
o.light_range = particle_data.light
local flicker = particle_data.light_flicker or nil
local color = particle_data.light_color or nil
o.light = Light:new(o.pos.x,o.pos.y,o.light_range,flicker,color)
end
-- animations
if particle_data.animation then
if particle_data.animation ~= nil then
o.body = Animation:new(particle_data.animation,particle_data.animation_speed)
o:centerOffset(o.body)
o:createBox(o.body)
end
table.remove(LoadedObjects.Entities,#LoadedObjects.Entities)
-- particle id handled differently from other entities
table.insert(LoadedObjects.Particles,o)
o.id = #LoadedObjects.Particles
setmetatable(o, self)
self.__index = self
return o
end
function Particle:kill()
if self.light then
if self.light ~= nil then
self.light:kill()
end
self.dead = true
if self.id ~= nil then
for _, e in pairs(LoadedObjects.Particles) do
if e.id > self.id then
e.id = e.id - 1
end
end
table.remove(LoadedObjects.Particles,self.id)
end
self = nil
end
function Particle:handleAnimation()
@ -74,31 +83,25 @@ function Particle:handleAnimation()
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
end
if self.body then
if self.body ~= nil then
self.body:animate()
self:draw(self.body)
end
end
function Particle:doLogic()
if self.func then
self:func()
-- adjust speed
if self.speed_increase ~= 0 then
self.speed = self.speed + self.speed_increase
self.vel.x = self.speed * math.cos(self.direction)
self.vel.y = self.speed * math.sin(self.direction)
end
if self.time then
if self.time ~= nil then
if self.timer >= self.time then self:kill() end
end
end
function cleanDeadParticles()
for i=1, #LoadedObjects.Particles do
part = LoadedObjects.Particles[i]
if part.kill then
table.remove(LoadedObjects.Particles,i)
end
end
end
function Particle:doPhysics()
-- horizontal collision
self:moveX(
@ -117,16 +120,3 @@ function Particle:debug()
love.graphics.setColor(0,1,1)
love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1)
end
---------------
function cleanDeadParticles()
for i=1, #LoadedObjects.Particles do
part = LoadedObjects.Particles[i]
if part and part.dead then
table.remove(LoadedObjects.Particles,i)
end
end
end
---------------

View File

@ -1,7 +1,6 @@
Player = class(Entity, {
type = "Player",
display = Animation:new(animation.nancy.idle),
})
Player = Entity:new()
Player.type = "Player"
Player.display = Animation:new(animation.nancy.idle)
function Player:new(x,y)
local o = Entity:new(x,y)
@ -42,6 +41,9 @@ function Player:new(x,y)
o.walljump_nodrift_amount = 12
o.walljump_impulse = { x = 2.5, y = 3.5 }
-- light values
o.light_radius = 40 -- screen pixels
-- status
o.can_jump = true
o.can_fall = true
@ -73,12 +75,9 @@ function Player:new(x,y)
o:createBox(o.body,0,4,-1,-5)
-- lights
local light_data = {}
light_data.radius = 40
light_data.shine_radius = 20
light_data.flicker = nil
light_data.color = nil
o.light = Light:new(o.pos.x,o.pos.y,light_data)
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
o:id()
setmetatable(o, self)
self.__index = self

View File

@ -1,5 +1,5 @@
Entity = {class = "Entity"}
LoadedObjects.Entities = {}
Entity = class(nil, {type = "Entity"})
function Entity:new(x,y)
local o = {}
@ -23,13 +23,19 @@ function Entity:new(x,y)
o.sprite_tint = {1,1,1}
o.sprite_alpha = 1
o.sprite_flip = { x = 1, y = 1}
o.illuminated = false
table.insert(LoadedObjects.Entities,o)
setmetatable(o, self)
self.__index = self
return o
end
function Entity:id()
table.insert(LoadedObjects.Entities,self)
self.id = #LoadedObjects.Entities
end
function Entity:checkNearest(type,maxdistance)
local return_entity = nil
local shortest = -1
@ -61,6 +67,9 @@ function Entity:checkNearest(type,maxdistance)
return return_entity
end
function Entity:doLogic()
end
function Entity:moveX(amount, func)
self.move_remainder.x = self.move_remainder.x + amount
local move = math.round(self.move_remainder.x)
@ -124,7 +133,15 @@ function Entity:kill()
if self.light ~= nil then
self.light:kill()
end
self.dead = true
if self.id ~= nil then
table.remove(LoadedObjects.Entities,self.id)
for _, e in pairs(LoadedObjects.Entities) do
if e.id > self.id then
e.id = e.id - 1
end
end
end
self = nil
end
function Entity:checkVisionLine(entity,range)
@ -292,9 +309,6 @@ function Entity:debug()
end
end
function Entity:doLogic()
end
function Entity:doPhysics()
end
@ -304,19 +318,6 @@ end
function Entity:drawBackground()
end
---------------
function cleanDeadEntities()
for i=1, #LoadedObjects.Entities do
enty = LoadedObjects.Entities[i]
if enty and enty.dead then
table.remove(LoadedObjects.Entities,i)
end
end
end
---------------
require "code/entities/kupo"
require "code/entities/arrow"
require "code/entities/decoration"

View File

@ -68,10 +68,6 @@ function stepGame()
Demo:startPlayback()
end
end
cleanDeadParticles()
cleanDeadEntities()
cleanDeadLights()
end
function drawGame()

View File

@ -20,7 +20,6 @@ function drawGameworldBackground()
for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do
if LevelTiles[i][j].id ~= 0 then
local depth = TileData[LevelTiles[i][j].id].depth
drawTile(
LevelTiles[i][j],
@ -79,7 +78,19 @@ function drawGameworldDarkness()
love.graphics.setBlendMode("replace")
love.graphics.setColor(0,0,0,0)
for _, light in pairs(LoadedObjects.Lights) do
light:drawClear()
if light.range ~= 0 then
local position = {
x = (light.pos.x - Camera.pos.x) / game.scale,
y = (light.pos.y - Camera.pos.y) / game.scale
}
local range = (light.range + light.flicker_value) / game.scale
love.graphics.circle(
"fill",
position.x,
position.y,
range
)
end
end
Canvas.Darkness:endDrawing()
Canvas.Darkness:draw()
@ -87,7 +98,23 @@ end
function drawGameworldLights()
for _, light in pairs(LoadedObjects.Lights) do
light:drawShine()
if light.range ~= 0 then
love.graphics.setColor(light.color[1],light.color[2],light.color[3],1)
shader.circle_gradient:send("pos_x",- Camera.pos.x + light.pos.x)
shader.circle_gradient:send("pos_y",- Camera.pos.y + light.pos.y)
shader.circle_gradient:send("range",light.range)
shader.circle_gradient:send("scale",game.scale)
love.graphics.setShader(shader.circle_gradient)
love.graphics.circle(
"fill",
- Camera.pos.x + light.pos.x,
- Camera.pos.y + light.pos.y,
light.range
)
love.graphics.setShader()
end
end
end

View File

@ -1,90 +1,51 @@
function exportLevel(levelname, filename)
love.filesystem.createDirectory("export")
filename = filename or "output.lua"
if string.sub(filename, 1, 1) ~= "/" then
filename = "export/"..filename
function exportLevel(levelname, dirname)
dirname = "export/"..dirname
if love.filesystem.exists(dirname) then
-- TODO: prompt to overwrite
error("file already exists")
end
local ok = love.filesystem.createDirectory(dirname)
if not ok then
logPrint("error creating directory")
end
exportFile = io.open(filename, "w+")
if exportFile then
logPrint("Exporting level \"".. levelname .. "\"...")
exportFile:write("return {")
logPrint("- level name")
exportFile:write("\n name = \"" .. levelname .. "\",")
logPrint("- tileset")
for k, v in pairs(tileset) do
if v == LevelData.tileset then
exportFile:write("\n tileset = tileset." .. k .. ",")
end
end
logPrint("- properties")
exportFile:write("\n properties = {")
logPrint(" - darkness: ".. tostring(LevelData.properties.darkness))
exportFile:write("\n darkness = " .. tostring(LevelData.properties.darkness))
exportFile:write("\n },")
logPrint("- tiles")
exportFile:write("\n tiles = {")
local rows = #LevelTiles
for i = 1, #LevelTiles do
if i > 1 then
exportFile:write(", ")
end
exportFile:write("\n { ")
for j = 1, #LevelTiles[i] do
if j ~= 1 then
exportFile:write(", ")
end
exportFile:write(tostring(LevelTiles[i][j].id))
end
exportFile:write("}")
logPrint(" - row "..i.."/"..rows.." "..math.floor(100*((i-1)*100/rows))/100 .."%")
end
exportFile:write("\n },")
logPrint("- objects")
exportFile:write("\n objects = {")
logPrint(" - spawns")
exportFile:write("\n spawns = {")
for i, v in ipairs(LoadedObjects.Spawns) do
if i > 1 then
exportFile:write(",")
end
exportFile:write("\n {")
exportFile:write(v.archetype.type)
exportFile:write(",{")
for i=1, #v.args do
if i > 1 then
exportFile:write(",")
end
exportFile:write(v.args[i])
end
exportFile:write("}}")
end
exportFile:write("\n },")
logPrint(" - rooms")
exportFile:write("\n rooms = {")
for i, room in ipairs(LoadedObjects.Rooms) do
if i > 1 then
exportFile:write(",")
end
exportFile:write("\n {{")
exportFile:write(room.from.x)
exportFile:write(",")
exportFile:write(room.from.y)
exportFile:write("},{")
exportFile:write(room.to.x)
exportFile:write(",")
exportFile:write(room.to.y)
exportFile:write("}}")
end
exportFile:write("\n },")
exportFile:write("\n },")
logPrint("Exporting complete.")
exportFile:write("\n}")
exportFile:close()
logPrint("Exporting level \"".. levelname .. "\"...")
local exportTable = {}
exportTable.name = levelname
exportTable.tileset = "library"
exportTable.properties = LevelData.properties
--exportTable.tiles = LevelTiles
--logPrint("- objects")
--exportTable.objects = { spawns = {}, rooms = {} }
--logPrint(" - spawns")
--for i, v in ipairs(LoadedObjects.Spawns) do
--exportTable.objects.spawns = {v.archetype.name,{},v.args}
--end
--logPrint(" - rooms")
--for i, room in ipairs(LoadedObjects.Rooms) do
--- table.insert(exportTable.objects.rooms,{room:asRect():getCoords()})
--end
exportTable.chunks = Chunk:getExportList()
logPrint("Writing to file...")
local ok, err = love.filesystem.write(dirname.."/level.lua", "return "..serialize_lua_value(exportTable))
if ok then
logPrint("Saving chunks...")
local chunkdir = dirname.."/chunks"
love.filesystem.createDirectory(chunkdir)
for chunk in pairs(Chunk.all) do
local ok, err = chunk:save(chunkdir)
if not ok then error(err) end
end
logPrint("Exporting complete.")
else
-- TODO: clean up created files
logPrint("Exporting failed: "..err)
end
end

View File

@ -1,7 +1,25 @@
function loadLevelTiles()
math.randomseed(3)
LevelData = dofile("data/levels/"..level_current)
level_current = "data/levels/level1"
LevelData = dofile(level_current.."/level.lua")
LoadedObjects.Collisions = {}
LoadedObjects.Platforms = {}
LoadedObjects.Ladders = {}
LoadedObjects.Hazards = {}
if type(LevelData.tileset) == "string" then
LevelData.tileset_name = LevelData.tileset
end
LevelData.tileset = tileset[LevelData.tileset_name]
getLevelTileData()
for _, v in ipairs(LevelData.chunks) do
Chunk:new(v[1], v[2])
end
local global_chunk = next(Chunk.all)
global_chunk:load()
LoadedObjects.Collisions = global_chunk.loaded.collisions
LevelTiles = global_chunk.data.tiles
--[[
on level format:
@ -12,26 +30,26 @@ function loadLevelTiles()
overlay_depth = foreground/background overlay depth
type = collision type
]]
getLevelTileData()
LevelTiles = LevelData.tiles
updateLevelDimensions()
indexLevelTiles()
createTileObjects()
createRoomObjects()
getSpawns()
--
--createTileObjects()
--createRoomObjects()
--getSpawns()
end
function createRoomObjects()
LoadedObjects.Rooms = {}
for _, v in pairs(LevelData.objects.rooms) do
table.insert(LoadedObjects.Rooms, Collision:new(v[1][1],v[1][2],v[2][1],v[2][2]))
table.insert(LoadedObjects.Rooms, Collision:new(v[1],v[2],v[3],v[4]))
end
end
function getSpawns()
LoadedObjects.Spawns = {}
for _, v in pairs(LevelData.objects.spawns) do
addSpawn(v[1],unpack(v[2]))
--addSpawn(v[1],unpack(v[2]))
end
end
@ -121,11 +139,8 @@ function reduceLevelCanvas(horizontal,vertical)
end
function getLevelTileData()
for k, v in pairs(tileset) do
if v == LevelData.tileset then
TileData = dofile("data/tileset/"..k..".lua")
end
end
TileData = dofile("data/tileset/"..LevelData.tileset_name..".lua")
end
function reloadLevelTiles()
@ -159,10 +174,10 @@ end
function indexLevelTiles()
TileIndex = {}
local this_tileset = LevelData.tileset
-- index from tileset
local width = LevelData.tileset:getPixelWidth()/tile_properties.width
local height = LevelData.tileset:getPixelHeight()/tile_properties.height
local width = this_tileset:getPixelWidth()/tile_properties.width
local height = this_tileset:getPixelHeight()/tile_properties.height
for i = 0, height do
for j = 0, width do
TileIndex[i*width+j+1] = love.graphics.newQuad(
@ -170,7 +185,7 @@ function indexLevelTiles()
i*tile_properties.height,
tile_properties.width,
tile_properties.height,
LevelData.tileset:getDimensions()
this_tileset:getDimensions()
)
end
end
@ -220,6 +235,9 @@ end
function instanceTile(id)
local tile = {}
if type(id) == "table" then
id = id.id
end
tile.id = id
local Properties = TileData[tile.id]
@ -258,7 +276,7 @@ function drawGridDisplay()
end
end
function optimizeTileObjects()
function optimizeTileObjects(dest)
logPrint("Optimizing Objects...")
local unoptimized = 0
local isTileOptimized = {}
@ -270,8 +288,9 @@ function optimizeTileObjects()
end
for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do
if LevelTiles[i][j].id ~= 0 then
local type = TileData[LevelTiles[i][j].id].type
if LevelTiles[i][j].id ~= 0 and TileData[LevelTiles[i][j].id] then
local tile_dat = TileData[LevelTiles[i][j].id]
local type = tile_dat.type
if type == "whole" and not isTileOptimized[i][j] then
isTileOptimized[i][j] = true
local n = 1
@ -337,29 +356,27 @@ function optimizeTileObjects()
base_x + tile_properties.width * tile_properties.scale * n,
base_y + tile_properties.height * tile_properties.scale * m
)
table.insert(LoadedObjects.Collisions,col)
table.insert(dest,col)
end
end
end
end
logPrint("collisions optimized from " .. unoptimized .. " to " .. #LoadedObjects.Collisions)
--logPrint("collisions optimized from " .. unoptimized .. " to " .. #LoadedObjects.Collisions)
end
function createTileObjects()
LoadedObjects.Collisions = {}
LoadedObjects.Platforms = {}
LoadedObjects.Ladders = {}
LoadedObjects.Hazards = {}
-- currently broken
function createTileObjects(dest)
optimizeTileObjects()
optimizeTileObjects(dest.collisions)
for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do
if LevelTiles[i][j].id ~= 0 then
local type = TileData[LevelTiles[i][j].id].type
local light = TileData[LevelTiles[i][j].id].light
local tile_dat = TileData[LevelTiles[i][j].id] or {}
local type = tile_dat.type
local light = tile_dat.light
local base_x = tile_properties.scale * j * tile_properties.width + tile_properties.scale * (level_properties.offset.x - tile_properties.height)
local base_y = tile_properties.scale * i * tile_properties.height + tile_properties.scale * (level_properties.offset.y - tile_properties.height)
@ -372,6 +389,9 @@ function createTileObjects()
)
end
local col
local list = dest.collisions
-- wholes are handled in optimization now
--[[if type == "whole" then
local col = Collision:new(
@ -383,33 +403,33 @@ function createTileObjects()
table.insert(LoadedObjects.Collisions,col)
else]]if type == "half_bottom" then
local col = Collision:new(
col = Collision:new(
base_x,
base_y + tile_properties.height/2 * tile_properties.scale,
base_x + tile_properties.width * tile_properties.scale,
base_y + tile_properties.height * tile_properties.scale
)
table.insert(LoadedObjects.Collisions,col)
elseif type == "half_top" then
local col = Collision:new(
col = Collision:new(
base_x,
base_y ,
base_x + tile_properties.width * tile_properties.scale,
base_y + tile_properties.height/2 * tile_properties.scale
)
table.insert(LoadedObjects.Collisions,col)
elseif type == "half_right" then
local col = Collision:new(
col = Collision:new(
base_x + tile_properties.height/2 * tile_properties.scale,
base_y,
base_x + tile_properties.width * tile_properties.scale,
base_y + tile_properties.height * tile_properties.scale
)
table.insert(LoadedObjects.Collisions,col)
elseif type == "half_left" then
@ -580,7 +600,8 @@ function createTileObjects()
end
elseif type == "ladder_right" then
-- TODO: fix ladders
--[[elseif type == "ladder_right" then
local ladder = Collision:new(
base_x + (tile_properties.width-4)* tile_properties.scale,
@ -638,7 +659,7 @@ function createTileObjects()
)
table.insert(LoadedObjects.Platforms,plat)
elseif type == "bottom_hazard" then
]]elseif type == "bottom_hazard" then
local hazard = Collision:new(
@ -647,9 +668,10 @@ function createTileObjects()
base_x + tile_properties.width * tile_properties.scale,
base_y + tile_properties.height * tile_properties.scale
)
table.insert(LoadedObjects.Hazards,hazard)
list = dest.hazards
end
table.insert(list, col)
end
end
end

View File

@ -1,30 +1,41 @@
Light = class(nil, {
type = "Light"
})
Light = {}
LoadedObjects.Lights = {}
function Light:new(x,y,data)
function Light:new(x,y,range,flicker,color,lum)
local o = {}
o.pos = {
x = x,
y = y
}
o.radius = data.radius
o.shine_radius = data.shine_radius or 0
o.lum = data.lum or 1
o.color = data.color or {1,1,1}
o.flicker_amount = data.flicker or 2
o.range = range
o.lum = lum or 1
o.color = color or {1,1,1}
o.flicker_amount = flicker or 2
o.flicker_value = 0
o.dim = 0
o.flicker_time = 60/12
o.flicker_timer = 0
table.insert(LoadedObjects.Lights,o)
o.id = #LoadedObjects.Lights
setmetatable(o, self)
self.__index = self
table.insert(LoadedObjects.Lights,o)
return o
end
function Light:kill()
if self.id ~= nil then
table.remove(LoadedObjects.Lights,self.id)
for _, e in pairs(LoadedObjects.Lights) do
if e.id > self.id then
e.id = e.id - 1
end
end
end
self = nil
end
function Light:flicker()
self.flicker_timer = self.flicker_timer + 1
@ -34,56 +45,3 @@ function Light:flicker()
self.flicker_value = math.min(math.max(self.flicker_value, -self.flicker_amount), self.flicker_amount)
end
end
function Light:drawClear()
if self.radius ~= 0 then
local position = {
x = (self.pos.x - Camera.pos.x) / game.scale,
y = (self.pos.y - Camera.pos.y) / game.scale
}
local radius = (self.radius + self.flicker_value) / game.scale
love.graphics.circle(
"fill",
position.x,
position.y,
radius
)
end
end
function Light:drawShine()
if self.radius ~= 0 then
love.graphics.setColor(self.color[1],self.color[2],self.color[3],1)
shader.circle_gradient:send("pos_x",- Camera.pos.x + self.pos.x)
shader.circle_gradient:send("pos_y",- Camera.pos.y + self.pos.y)
shader.circle_gradient:send("radius",self.shine_radius)
shader.circle_gradient:send("scale",game.scale)
love.graphics.setShader(shader.circle_gradient)
love.graphics.circle(
"fill",
- Camera.pos.x + self.pos.x,
- Camera.pos.y + self.pos.y,
self.radius
)
love.graphics.setShader()
end
end
function Light:kill()
self.dead = true
end
---------------
function cleanDeadLights()
for i=1, #LoadedObjects.Lights do
light = LoadedObjects.Lights[i]
if light and light.dead then
table.remove(LoadedObjects.Lights,i)
end
end
end
---------------

View File

@ -7,7 +7,7 @@ require "data/sfx"
require "code/locale"
-- support functions
require "code/class"
require "code/serialize"
require "code/math"
require "code/draw"
require "code/hex"
@ -16,6 +16,7 @@ require "code/in_out"
-- classes
require "code/point"
require "code/rect"
require "code/chunk"
require "code/objects"
require "code/level"
require "code/camera"

View File

@ -24,7 +24,7 @@ function selectSpawns(rect)
local x, y = rect:getPoints()
local select_rect = Rect:fromPoints(x-{x=Camera.pos.x,y=Camera.pos.y},y-{x=Camera.pos.x,y=Camera.pos.y})
select_rect:fix()
for _, spawn in pairs(LoadedObjects.Spawns) do
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
@ -244,13 +244,7 @@ function drawSpawns()
)
if spawn.selected then
local text = spawn.archetype.type .."\n("
local ancestors = getAncestors(spawn.archetype)
for i=1, #ancestors do
if i > 1 then text = text .. ", " end
text = text .. ancestors[i].type
end
text = text ..")\n---\nPosition\n["..spawn.args[1]..","..spawn.args[2].."]"
local text = spawn.archetype.type.."\n---\nPosition\n["..spawn.args[1]..","..spawn.args[2].."]"
if #spawn.args > 2 then
text = text .. "\n---\nData:\n"
for i=3, #spawn.args do

View File

@ -13,7 +13,7 @@ local function backspace(text)
return ""
end
Prompt = class(nil, {
Prompt = {
-- defaults for instance variables
pos = { x = 10, y = 10 },
input = "",
@ -23,7 +23,7 @@ Prompt = class(nil, {
color = {1,1,1,1},
background_color = {0,0,0,1},
active_prompt = nil,
})
}
function Prompt:cancelActive()
if Prompt.active_prompt then
Prompt.active_prompt.canceled = true
@ -33,6 +33,7 @@ end
function Prompt:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end

View File

@ -1,43 +0,0 @@
return {
name = "Dev Level",
tileset = tileset.library,
properties = {
darkness = true
},
tiles = {
{ 1, 4, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 4, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
},
objects = {
spawns = {
{Fairy,{100,88}},
{HookAnchor,{200,89,100}},
{HookAnchor,{400,89,120}},
{Candelabra,{328,297}}
},
rooms = {
{{96,64},{544,320}},
{{0,0},{112,176}}
},
},
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
return {[ [[tileset]] ]=[[library]],[ [[chunks]] ]={[ 1 ]={[ 1 ]=[[global.lua]],},},[ [[name]] ]=[[unnamed]],[ [[properties]] ]={[ [[darkness]] ]=false,},}

View File

@ -2,7 +2,7 @@ shader = {}
shader.circle_gradient = love.graphics.newShader[[
uniform float pos_x;
uniform float pos_y;
uniform float radius;
uniform float range;
uniform float scale;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
@ -12,13 +12,11 @@ shader.circle_gradient = love.graphics.newShader[[
float distance_x = pos_x - screen_coords.x / scale;
float distance_y = pos_y - screen_coords.y / scale;
float distance = sqrt( pow(distance_x,2) + pow(distance_y,2) ) ;
if (distance < radius){
float alpha = 1-(5*distance/radius);
if (distance < range){
float alpha = 1-(5*distance/range);
if (pixel.a > alpha){
pixel.a = alpha;
}
} else {
pixel.a = 0;
}
return pixel * color * color;
}