Compare commits

...

18 Commits

Author SHA1 Message Date
lustlion
9a20b172af fix fix
last commit
2022-03-17 11:53:48 +01:00
lustlion
a01599c001 fix last commit 2022-03-17 11:52:58 +01:00
lustlion
410c00dcd4 Replaced the id system with a simple flag for deletion 2022-03-17 11:46:10 +01:00
binarycat
8edcbe2d9b use class() in more places 2022-03-16 21:01:04 -04:00
lustlion
fa62e1428b swapped obsolete supertype for getAncestors() 2022-03-17 01:40:35 +01:00
binarycat
9be52e2b5f real real bugfix 2022-03-16 20:38:57 -04:00
binarycat
a3074acb3c real bugfix 2022-03-16 20:36:45 -04:00
binarycat
59726dc2b7 bugfix 2022-03-16 20:34:23 -04:00
lustlion
f0a9c1acf9 added getAncestors() 2022-03-17 01:26:59 +01:00
binarycat
1549976382 add class() for easy definition of classes 2022-03-16 19:59:42 -04:00
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
25 changed files with 312 additions and 186 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

17
code/class.lua Normal file
View File

@ -0,0 +1,17 @@
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 = {} Collision = class()
LoadedObjects.Collisions = {} LoadedObjects.Collisions = {}
LoadedObjects.Platforms = {} LoadedObjects.Platforms = {}
@ -48,7 +48,6 @@ function Collision:new(ox,oy,tx,ty)
end end
setmetatable(o, self) setmetatable(o, self)
self.__index = self
return o return o
end end

View File

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

View File

@ -1,6 +1,7 @@
CursedBook = Entity:new() CursedBook = class(Entity, {
CursedBook.type = "CursedBook" type = "CursedBook",
CursedBook.display = Animation:new(animation.cursed_book.flying) display = Animation:new(animation.cursed_book.flying),
})
function CursedBook:new(x,y) function CursedBook:new(x,y)
local o = Entity:new(x,y) local o = Entity:new(x,y)
@ -28,10 +29,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
o:id() light_data.flicker = nil
light_data.color = nil
o.light = Light:new(o.pos.x,o.pos.y,light_data)
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self

View File

@ -1,23 +1,23 @@
Decoration = Entity:new() Decoration = class(Entity, {
Decoration.type = "Decoration" type = "Decoration",
Decoration.display = nil supertype = Entity.type,
display = Animation:new(animation.particle.simple),
})
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)
if light_radius ~= nil then
o.light_radius = light_radius
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
end end
o:id() if light_data then
o.light = Light:new(o.pos.x,o.pos.y,light_data)
end
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
@ -29,5 +29,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,54 @@
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,6 +1,7 @@
Fairy = Entity:new() Fairy = class(Entity, {
Fairy.type = "Fairy" type = "Fairy",
Fairy.display = Animation:new(animation.fairy.flying) display = Animation:new(animation.fairy.flying),
})
function Fairy:new(x,y) function Fairy:new(x,y)
local o = Entity:new(x,y) local o = Entity:new(x,y)
@ -19,15 +20,17 @@ 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
o.particle_time = 5 o.particle_time = 5
o:id()
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
return o return o
@ -88,16 +91,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,7 @@
HookAnchor = Entity:new() HookAnchor = class(Entity, {
HookAnchor.type = "HookAnchor" type = "HookAnchor",
HookAnchor.display = Animation:new(animation.fairy.flying) display = Animation:new(animation.fairy.flying),
})
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)
@ -13,8 +14,6 @@ function HookAnchor:new(x,y,hook_distance)
o:centerOffset(o.body) o:centerOffset(o.body)
o:createBox(o.body) o:createBox(o.body)
o:id()
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
return o return o

View File

@ -1,6 +1,7 @@
Kupo = Entity:new() Kupo = class(Entity, {
Kupo.type = "Kupo" type = "Kupo",
Kupo.display = Animation:new(animation.kupo.body) display = Animation:new(animation.kupo.body),
})
function Kupo:new(x,y) function Kupo:new(x,y)
local o = Entity:new(x,y) local o = Entity:new(x,y)
@ -27,10 +28,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
o:id() 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)
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self

View File

@ -1,8 +1,8 @@
LoadedObjects.Particles = {} LoadedObjects.Particles = {}
Particle = class(Entity, {
Particle = Entity:new() type = "Particle",
Particle.type = "Particle" display = Animation:new(animation.particle.simple),
Particle.display = Animation:new(animation.particle.simple) })
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,18 +10,19 @@ 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 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
o.time = o.time o.time = o.time
@ -36,44 +37,34 @@ 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 then
local light_data = {}
if particle_data.light ~= nil then light_data.radius = particle_data.light
o.light_range = particle_data.light light_data.shine_radius = particle_data.light_shine or nil
local flicker = particle_data.light_flicker or nil light_data.flicker = particle_data.light_flicer or nil
local color = particle_data.light_color or nil light_data.color = particle_data.light_color or nil
o.light = Light:new(o.pos.x,o.pos.y,o.light_range,flicker,color) o.light = Light:new(o.pos.x,o.pos.y,light_data)
end end
-- animations -- animations
if particle_data.animation ~= nil then if particle_data.animation then
o.body = Animation:new(particle_data.animation,particle_data.animation_speed) o.body = Animation:new(particle_data.animation,particle_data.animation_speed)
o:centerOffset(o.body) o:centerOffset(o.body)
o:createBox(o.body) o:createBox(o.body)
end end
-- particle id handled differently from other entities table.remove(LoadedObjects.Entities,#LoadedObjects.Entities)
table.insert(LoadedObjects.Particles,o) table.insert(LoadedObjects.Particles,o)
o.id = #LoadedObjects.Particles
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
return o return o
end end
function Particle:kill() function Particle:kill()
if self.light ~= nil then if self.light then
self.light:kill() self.light:kill()
end end
if self.id ~= nil then self.dead = true
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 end
function Particle:handleAnimation() function Particle:handleAnimation()
@ -83,25 +74,31 @@ function Particle:handleAnimation()
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
end end
if self.body ~= nil then if self.body then
self.body:animate() self.body:animate()
self:draw(self.body) self:draw(self.body)
end end
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
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() function Particle:doPhysics()
-- horizontal collision -- horizontal collision
self:moveX( self:moveX(
@ -120,3 +117,16 @@ function Particle:debug()
love.graphics.setColor(0,1,1) love.graphics.setColor(0,1,1)
love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1) love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1)
end 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,6 +1,7 @@
Player = Entity:new() Player = class(Entity, {
Player.type = "Player" type = "Player",
Player.display = Animation:new(animation.nancy.idle) display = Animation:new(animation.nancy.idle),
})
function Player:new(x,y) function Player:new(x,y)
local o = Entity:new(x,y) local o = Entity:new(x,y)
@ -41,9 +42,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,9 +73,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
o:id() 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)
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self

View File

@ -1,5 +1,5 @@
Entity = {class = "Entity"}
LoadedObjects.Entities = {} LoadedObjects.Entities = {}
Entity = class(nil, {type = "Entity"})
function Entity:new(x,y) function Entity:new(x,y)
local o = {} local o = {}
@ -23,19 +23,13 @@ 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
table.insert(LoadedObjects.Entities,o)
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
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
@ -67,9 +61,6 @@ function Entity:checkNearest(type,maxdistance)
return return_entity return return_entity
end end
function Entity:doLogic()
end
function Entity:moveX(amount, func) function Entity:moveX(amount, func)
self.move_remainder.x = self.move_remainder.x + amount self.move_remainder.x = self.move_remainder.x + amount
local move = math.round(self.move_remainder.x) local move = math.round(self.move_remainder.x)
@ -133,15 +124,7 @@ function Entity:kill()
if self.light ~= nil then if self.light ~= nil then
self.light:kill() self.light:kill()
end end
if self.id ~= nil then self.dead = true
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 end
function Entity:checkVisionLine(entity,range) function Entity:checkVisionLine(entity,range)
@ -309,6 +292,9 @@ function Entity:debug()
end end
end end
function Entity:doLogic()
end
function Entity:doPhysics() function Entity:doPhysics()
end end
@ -318,6 +304,19 @@ end
function Entity:drawBackground() function Entity:drawBackground()
end 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/kupo"
require "code/entities/arrow" require "code/entities/arrow"
require "code/entities/decoration" require "code/entities/decoration"

View File

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

View File

@ -79,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()
@ -99,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,41 +1,30 @@
Light = {} Light = class(nil, {
type = "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
o.flicker_timer = 0 o.flicker_timer = 0
table.insert(LoadedObjects.Lights,o)
o.id = #LoadedObjects.Lights
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
table.insert(LoadedObjects.Lights,o)
return o return o
end 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() function Light:flicker()
self.flicker_timer = self.flicker_timer + 1 self.flicker_timer = self.flicker_timer + 1
@ -45,3 +34,56 @@ 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
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,6 +7,7 @@ require "data/sfx"
require "code/locale" require "code/locale"
-- support functions -- support functions
require "code/class"
require "code/math" require "code/math"
require "code/draw" require "code/draw"
require "code/hex" require "code/hex"

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,13 @@ 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("
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].."]"
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

View File

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

View File

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

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;
} }