Compare commits

..

8 Commits

Author SHA1 Message Date
lustlion
d20e5392f8 Decoration now acts as parent for specific decorations better.
added candelabra decoration.
2022-03-17 00:39:47 +01:00
lustlion
d359afaf97 fixed all entities instanced an entity when grabbing functions from parent Entity. now it just sets metatable 2022-03-17 00:39:18 +01:00
lustlion
11a46e6227 spawns now also display archetype* on drawing the data
*to be replaced with actual parent once the class thing is implemented?
2022-03-17 00:38:08 +01:00
lustlion
f670f6bc87 Changes on Lights
- adjusted lights so they are called to do something, instead of it 
being handled on game world 
- lights has only coordinate arguments + a table with all other optional 
ones.
- renamed a lot of lights components to radius instaed of range, as it 
was agreed before elsewhere
2022-03-17 00:37:14 +01:00
lustlion
0486787b98 changed particle png to be white so it can be tinted 2022-03-17 00:33:52 +01:00
lustlion
6ba4f4d1c9 animations now have a flag for when they update their img frame 2022-03-17 00:33:36 +01:00
binarycat
918c63c535 removed file on the wrong branch 2022-03-16 14:37:19 -04:00
binarycat
6fa7dcbeef add missing file 2022-03-16 14:33:35 -04:00
27 changed files with 375 additions and 267 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: 89 B

After

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

View File

@@ -1,51 +0,0 @@
-- 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

@@ -100,7 +100,7 @@ function stepEditor()
if name_prompt.canceled then return end if name_prompt.canceled then return end
Prompt:new({ Prompt:new({
name = "filename", name = "filename",
input = "unnamed_level", 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)

View File

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

View File

@@ -1,6 +1,8 @@
CursedBook = Entity:new() CursedBook = {}
CursedBook.type = "CursedBook" CursedBook.type = "CursedBook"
CursedBook.supertype = Entity.type
CursedBook.display = Animation:new(animation.cursed_book.flying) CursedBook.display = Animation:new(animation.cursed_book.flying)
setmetatable(CursedBook, Entity)
function CursedBook:new(x,y) function CursedBook:new(x,y)
local o = Entity:new(x,y) local o = Entity:new(x,y)
@@ -28,8 +30,12 @@ function CursedBook:new(x,y)
o:createBox(o.body) o:createBox(o.body)
-- light -- light
o.light_range = 500 local light_data = {}
--o.light = Light:new(o.pos.x,o.pos.y,o.light_range,2,hex2rgb("#fe00d1")) 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:id() o:id()

View File

@@ -1,20 +1,22 @@
Decoration = Entity:new() Decoration = {}
Decoration.type = "Decoration" Decoration.type = "Decoration"
Decoration.display = nil Decoration.supertype = Entity.type
Decoration.display = Animation:new(animation.particle.simple)
setmetatable(Decoration, Entity)
function Decoration:new(x,y,animation,light_radius) function Decoration:new(x,y,animation,light_data)
local o = Entity:new(x,y) local o = Entity:new(x,y)
o.pos = {x = x, y = y} o.pos = {x = x, y = y}
-- animations if animation then
o.body = Animation:new(animation) o.body = Animation:new(animation)
o:centerOffset(o.body) o:centerOffset(o.body)
o:createBox(o.body) o:createBox(o.body)
end
if light_radius ~= nil then if light_data then
o.light_radius = light_radius 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)
end end
o:id() o:id()
@@ -29,5 +31,4 @@ function Decoration:handleAnimation()
self:draw(self.body) self:draw(self.body)
end end
function Decoration:doPhysics() require "code/entities/decorations/candelabra"
end

View File

@@ -0,0 +1,55 @@
Candelabra = {}
Candelabra.type = "Candelabra"
Candelabra.supertype = Decoration.type
Candelabra.display = Animation:new(animation.decoration.candelabra)
setmetatable(Candelabra, Decoration)
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,6 +1,8 @@
Fairy = Entity:new() Fairy = {}
Fairy.type = "Fairy" Fairy.type = "Fairy"
Fairy.supertype = Entity.type
Fairy.display = Animation:new(animation.fairy.flying) Fairy.display = Animation:new(animation.fairy.flying)
setmetatable(Fairy, Entity)
function Fairy:new(x,y) function Fairy:new(x,y)
local o = Entity:new(x,y) local o = Entity:new(x,y)
@@ -19,8 +21,12 @@ function Fairy:new(x,y)
o:createBox(o.body) o:createBox(o.body)
-- light -- light
o.light_radius = 80 local light_data = {}
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius,nil,hex2rgb("#fed100")) 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)
-- timer -- timer
o.particle_timer = 0 o.particle_timer = 0
@@ -88,16 +94,19 @@ function Fairy:handleAnimation()
local vector = vector(self.vel.x,self.vel.y) local vector = vector(self.vel.x,self.vel.y)
local angle = getAngleFromVector(vector) local angle = getAngleFromVector(vector)
self.particle_timer = 0 self.particle_timer = 0
local particle_data = { local particle_data = {}
animation = animation.particle.simple, particle_data.animation = animation.particle.simple
animation_speed = 1, particle_data.animation_speed = 1
sprite_tint = hex2rgb("#fed100"), particle_data.sprite_tint = hex2rgb("#fed100")
sprite_alpha_fade = true, particle_data.sprite_alpha_fade = true
direction = angle-math.rad(180+math.random(60)-30), particle_data.direction = angle-math.rad(180+math.random(60)-30)
speed = 1, particle_data.speed = 1
speed_increase = -0.01, particle_data.time = 0.75
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
Particle:new(self.pos.x,self.pos.y,particle_data) Particle:new(self.pos.x,self.pos.y,particle_data)
end end
end end

View File

@@ -1,6 +1,8 @@
HookAnchor = Entity:new() HookAnchor = {}
HookAnchor.type = "HookAnchor" HookAnchor.type = "HookAnchor"
HookAnchor.supertype = Entity.type
HookAnchor.display = Animation:new(animation.fairy.flying) HookAnchor.display = Animation:new(animation.fairy.flying)
setmetatable(HookAnchor, Entity)
function HookAnchor:new(x,y,hook_distance) function HookAnchor:new(x,y,hook_distance)
local o = Entity:new(x,y) local o = Entity:new(x,y)

View File

@@ -1,6 +1,8 @@
Kupo = Entity:new() Kupo = {}
Kupo.type = "Kupo" Kupo.type = "Kupo"
Kupo.supertype = Entity.type
Kupo.display = Animation:new(animation.kupo.body) Kupo.display = Animation:new(animation.kupo.body)
setmetatable(Kupo, Entity)
function Kupo:new(x,y) function Kupo:new(x,y)
local o = Entity:new(x,y) local o = Entity:new(x,y)
@@ -27,8 +29,13 @@ function Kupo:new(x,y)
o.bow_aim_frames = 8 o.bow_aim_frames = 8
o.hostile = true o.hostile = true
o.light_radius = o.range/2 -- light values
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius) 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:id() o:id()

View File

@@ -1,8 +1,9 @@
LoadedObjects.Particles = {} LoadedObjects.Particles = {}
Particle = {}
Particle = Entity:new()
Particle.type = "Particle" Particle.type = "Particle"
Particle.supertype = Entity.type
Particle.display = Animation:new(animation.particle.simple) Particle.display = Animation:new(animation.particle.simple)
setmetatable(Particle, Entity)
function Particle:new(x,y,particle_data) function Particle:new(x,y,particle_data)
local o = Entity:new(x,y) local o = Entity:new(x,y)
@@ -10,17 +11,18 @@ function Particle:new(x,y,particle_data)
o.pos = {x = x, y = y} o.pos = {x = x, y = y}
o.speed = particle_data.speed or 0 o.speed = particle_data.speed or 0
o.direction = particle_data.direction or o.direction o.direction = particle_data.direction or 0
o.sprite_rotation = particle_data.sprite_rotation or o.sprite_rotation o.sprite_rotation = particle_data.sprite_rotation or 0
o.sprite_offset = particle_data.sprite_offset or o.sprite_offset o.sprite_offset = particle_data.sprite_offset or vector(0,0)
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale o.sprite_scale = particle_data.sprite_scale or vector(1,1)
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint o.sprite_tint = particle_data.sprite_tint or {1,1,1}
o.sprite_alpha = particle_data.sprite_alpha or o.sprite_alpha o.sprite_alpha = particle_data.sprite_alpha or 1
o.sprite_alpha_fade = particle_data.sprite_alpha_fade or false o.sprite_alpha_fade = particle_data.sprite_alpha_fade or false
o.sprite_alpha_base = o.sprite_alpha o.sprite_alpha_base = o.sprite_alpha
o.sprite_flip = particle_data.sprite_flip or o.sprite_flip 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.time = particle_data.time or nil
if o.time ~= nil then if o.time ~= nil then
if particle_data.time_unit ~= nil if particle_data.time_unit ~= nil
and particle_data.time_unit == "frames" then and particle_data.time_unit == "frames" then
@@ -36,13 +38,13 @@ function Particle:new(x,y,particle_data)
y = o.speed * math.sin(o.direction) y = o.speed * math.sin(o.direction)
} }
o.speed_increase = particle_data.speed_increase or 0
if particle_data.light ~= nil then if particle_data.light ~= nil then
o.light_range = particle_data.light local light_data = {}
local flicker = particle_data.light_flicker or nil light_data.radius = particle_data.light
local color = particle_data.light_color or nil light_data.shine_radius = particle_data.light_shine or nil
o.light = Light:new(o.pos.x,o.pos.y,o.light_range,flicker,color) 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)
end end
-- animations -- animations
@@ -90,14 +92,11 @@ function Particle:handleAnimation()
end end
function Particle:doLogic() function Particle:doLogic()
-- adjust speed if self.func then
if self.speed_increase ~= 0 then self:func()
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 end
if self.time ~= nil then if self.time then
if self.timer >= self.time then self:kill() end if self.timer >= self.time then self:kill() end
end end
end end

View File

@@ -1,6 +1,8 @@
Player = Entity:new() Player = {}
Player.type = "Player" Player.type = "Player"
Player.supertype = Entity.type
Player.display = Animation:new(animation.nancy.idle) Player.display = Animation:new(animation.nancy.idle)
setmetatable(Player, Entity)
function Player:new(x,y) function Player:new(x,y)
local o = Entity:new(x,y) local o = Entity:new(x,y)
@@ -41,9 +43,6 @@ function Player:new(x,y)
o.walljump_nodrift_amount = 12 o.walljump_nodrift_amount = 12
o.walljump_impulse = { x = 2.5, y = 3.5 } o.walljump_impulse = { x = 2.5, y = 3.5 }
-- light values
o.light_radius = 40 -- screen pixels
-- status -- status
o.can_jump = true o.can_jump = true
o.can_fall = true o.can_fall = true
@@ -75,7 +74,12 @@ function Player:new(x,y)
o:createBox(o.body,0,4,-1,-5) o:createBox(o.body,0,4,-1,-5)
-- lights -- lights
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius) 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:id() o:id()

View File

@@ -1,5 +1,6 @@
Entity = {class = "Entity"}
LoadedObjects.Entities = {} LoadedObjects.Entities = {}
Entity = {}
Entity.type = "Entity"
function Entity:new(x,y) function Entity:new(x,y)
local o = {} local o = {}
@@ -23,11 +24,9 @@ function Entity:new(x,y)
o.sprite_tint = {1,1,1} o.sprite_tint = {1,1,1}
o.sprite_alpha = 1 o.sprite_alpha = 1
o.sprite_flip = { x = 1, y = 1} o.sprite_flip = { x = 1, y = 1}
o.illuminated = false
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
return o return o
end end

View File

@@ -20,6 +20,7 @@ function drawGameworldBackground()
for i = 1, #LevelTiles do for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do for j = 1, #LevelTiles[i] do
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],
@@ -78,19 +79,7 @@ function drawGameworldDarkness()
love.graphics.setBlendMode("replace") love.graphics.setBlendMode("replace")
love.graphics.setColor(0,0,0,0) love.graphics.setColor(0,0,0,0)
for _, light in pairs(LoadedObjects.Lights) do for _, light in pairs(LoadedObjects.Lights) do
if light.range ~= 0 then light:drawClear()
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 end
Canvas.Darkness:endDrawing() Canvas.Darkness:endDrawing()
Canvas.Darkness:draw() Canvas.Darkness:draw()
@@ -98,23 +87,7 @@ end
function drawGameworldLights() function drawGameworldLights()
for _, light in pairs(LoadedObjects.Lights) do for _, light in pairs(LoadedObjects.Lights) do
if light.range ~= 0 then light:drawShine()
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
end end

View File

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

View File

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

View File

@@ -1,16 +1,17 @@
Light = {} Light = {}
LoadedObjects.Lights = {} LoadedObjects.Lights = {}
function Light:new(x,y,range,flicker,color,lum) function Light:new(x,y,data)
local o = {} local o = {}
o.pos = { o.pos = {
x = x, x = x,
y = y y = y
} }
o.range = range o.radius = data.radius
o.lum = lum or 1 o.shine_radius = data.shine_radius or 0
o.color = color or {1,1,1} o.lum = data.lum or 1
o.flicker_amount = flicker or 2 o.color = data.color or {1,1,1}
o.flicker_amount = data.flicker or 2
o.flicker_value = 0 o.flicker_value = 0
o.dim = 0 o.dim = 0
o.flicker_time = 60/12 o.flicker_time = 60/12
@@ -45,3 +46,39 @@ function Light:flicker()
self.flicker_value = math.min(math.max(self.flicker_value, -self.flicker_amount), self.flicker_amount) self.flicker_value = math.min(math.max(self.flicker_value, -self.flicker_amount), self.flicker_amount)
end end
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

View File

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

View File

@@ -24,7 +24,7 @@ function selectSpawns(rect)
local x, y = rect:getPoints() 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}) 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() select_rect:fix()
for _, spawn in pairs(LoadedObjects.Spawns) do for _, spawn in pairs(LoadedObjects.Spawns) do
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset() local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
@@ -244,7 +244,7 @@ function drawSpawns()
) )
if spawn.selected then if spawn.selected then
local text = spawn.archetype.type.."\n---\nPosition\n["..spawn.args[1]..","..spawn.args[2].."]" local text = spawn.archetype.type.."\n("..spawn.archetype.supertype..")\n---\nPosition\n["..spawn.args[1]..","..spawn.args[2].."]"
if #spawn.args > 2 then if #spawn.args > 2 then
text = text .. "\n---\nData:\n" text = text .. "\n---\nData:\n"
for i=3, #spawn.args do for i=3, #spawn.args do

43
data/levels/level1.lua Normal file
View File

@@ -0,0 +1,43 @@
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, 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, 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, 1, 1, 1, 1, 1, 1},
{ 1, 4, 0, 0, 0, 2, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14},
{ 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 13, 13, 13, 13, 13, 13, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13},
{ 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, 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, 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

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