fixed all entities instanced an entity when grabbing functions from parent Entity. now it just sets metatable
This commit is contained in:
parent
11a46e6227
commit
d359afaf97
@ -1,5 +1,8 @@
|
||||
Arrow = Entity:new()
|
||||
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)
|
||||
|
@ -1,6 +1,8 @@
|
||||
CursedBook = Entity:new()
|
||||
CursedBook = {}
|
||||
CursedBook.type = "CursedBook"
|
||||
CursedBook.supertype = Entity.type
|
||||
CursedBook.display = Animation:new(animation.cursed_book.flying)
|
||||
setmetatable(CursedBook, Entity)
|
||||
|
||||
function CursedBook:new(x,y)
|
||||
local o = Entity:new(x,y)
|
||||
@ -28,8 +30,12 @@ function CursedBook:new(x,y)
|
||||
o:createBox(o.body)
|
||||
|
||||
-- light
|
||||
o.light_range = 500
|
||||
--o.light = Light:new(o.pos.x,o.pos.y,o.light_range,2,hex2rgb("#fe00d1"))
|
||||
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:id()
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
Fairy = Entity:new()
|
||||
Fairy = {}
|
||||
Fairy.type = "Fairy"
|
||||
Fairy.supertype = Entity.type
|
||||
Fairy.display = Animation:new(animation.fairy.flying)
|
||||
setmetatable(Fairy, Entity)
|
||||
|
||||
function Fairy:new(x,y)
|
||||
local o = Entity:new(x,y)
|
||||
@ -19,8 +21,12 @@ function Fairy:new(x,y)
|
||||
o:createBox(o.body)
|
||||
|
||||
-- light
|
||||
o.light_radius = 80
|
||||
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius,nil,hex2rgb("#fed100"))
|
||||
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)
|
||||
|
||||
-- timer
|
||||
o.particle_timer = 0
|
||||
@ -88,16 +94,19 @@ function Fairy:handleAnimation()
|
||||
local vector = vector(self.vel.x,self.vel.y)
|
||||
local angle = getAngleFromVector(vector)
|
||||
self.particle_timer = 0
|
||||
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
|
||||
}
|
||||
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
|
||||
Particle:new(self.pos.x,self.pos.y,particle_data)
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,8 @@
|
||||
HookAnchor = Entity:new()
|
||||
HookAnchor = {}
|
||||
HookAnchor.type = "HookAnchor"
|
||||
HookAnchor.supertype = Entity.type
|
||||
HookAnchor.display = Animation:new(animation.fairy.flying)
|
||||
setmetatable(HookAnchor, Entity)
|
||||
|
||||
function HookAnchor:new(x,y,hook_distance)
|
||||
local o = Entity:new(x,y)
|
||||
|
@ -1,6 +1,8 @@
|
||||
Kupo = Entity:new()
|
||||
Kupo = {}
|
||||
Kupo.type = "Kupo"
|
||||
Kupo.supertype = Entity.type
|
||||
Kupo.display = Animation:new(animation.kupo.body)
|
||||
setmetatable(Kupo, Entity)
|
||||
|
||||
function Kupo:new(x,y)
|
||||
local o = Entity:new(x,y)
|
||||
@ -27,8 +29,13 @@ function Kupo:new(x,y)
|
||||
o.bow_aim_frames = 8
|
||||
o.hostile = true
|
||||
|
||||
o.light_radius = o.range/2
|
||||
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
|
||||
-- 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:id()
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
LoadedObjects.Particles = {}
|
||||
|
||||
Particle = Entity:new()
|
||||
Particle = {}
|
||||
Particle.type = "Particle"
|
||||
Particle.supertype = Entity.type
|
||||
Particle.display = Animation:new(animation.particle.simple)
|
||||
setmetatable(Particle, Entity)
|
||||
|
||||
function Particle:new(x,y,particle_data)
|
||||
local o = Entity:new(x,y)
|
||||
@ -10,17 +11,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 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.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.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 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
|
||||
|
||||
if o.time ~= nil then
|
||||
if particle_data.time_unit ~= nil
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
end
|
||||
|
||||
-- animations
|
||||
@ -90,14 +92,11 @@ function Particle:handleAnimation()
|
||||
end
|
||||
|
||||
function Particle:doLogic()
|
||||
-- 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)
|
||||
if self.func then
|
||||
self:func()
|
||||
end
|
||||
|
||||
if self.time ~= nil then
|
||||
if self.time then
|
||||
if self.timer >= self.time then self:kill() end
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,8 @@
|
||||
Player = Entity:new()
|
||||
Player = {}
|
||||
Player.type = "Player"
|
||||
Player.supertype = Entity.type
|
||||
Player.display = Animation:new(animation.nancy.idle)
|
||||
setmetatable(Player, Entity)
|
||||
|
||||
function Player: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_impulse = { x = 2.5, y = 3.5 }
|
||||
|
||||
-- light values
|
||||
o.light_radius = 40 -- screen pixels
|
||||
|
||||
-- status
|
||||
o.can_jump = true
|
||||
o.can_fall = true
|
||||
@ -75,7 +74,12 @@ function Player:new(x,y)
|
||||
o:createBox(o.body,0,4,-1,-5)
|
||||
|
||||
-- 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()
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
Entity = {class = "Entity"}
|
||||
LoadedObjects.Entities = {}
|
||||
Entity = {}
|
||||
Entity.type = "Entity"
|
||||
|
||||
function Entity:new(x,y)
|
||||
local o = {}
|
||||
@ -23,11 +24,9 @@ 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
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
|
@ -2,7 +2,7 @@ return {
|
||||
name = "Dev Level",
|
||||
tileset = tileset.library,
|
||||
properties = {
|
||||
darkness = false
|
||||
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},
|
||||
@ -32,7 +32,8 @@ return {
|
||||
spawns = {
|
||||
{Fairy,{100,88}},
|
||||
{HookAnchor,{200,89,100}},
|
||||
{HookAnchor,{400,89,120}}
|
||||
{HookAnchor,{400,89,120}},
|
||||
{Candelabra,{328,297}}
|
||||
},
|
||||
rooms = {
|
||||
{{96,64},{544,320}},
|
||||
|
Loading…
Reference in New Issue
Block a user