Created Particles, added fairy particle, added more entity methods like kill() and entity id
This commit is contained in:
@@ -16,10 +16,12 @@ Arrow = Entity:New(x,y)
|
||||
|
||||
-- animations
|
||||
o.body = Animation:New(animation.kupo.arrow)
|
||||
|
||||
table.insert(LoadedEntities,o)
|
||||
o.id = #LoadedEntities
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
table.insert(LoadedEntities,o)
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
@@ -15,11 +15,13 @@ function Decoration:New(x,y,animation,lightRange)
|
||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange,nil,60/6)
|
||||
end
|
||||
|
||||
table.insert(LoadedEntities,o)
|
||||
o.id = #LoadedEntities
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
return o
|
||||
end
|
||||
end
|
||||
|
||||
function Decoration:Smart()
|
||||
end
|
||||
|
||||
@@ -17,9 +17,11 @@ Fairy = Entity:New(x,y)
|
||||
o.lightRange = 55
|
||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||
|
||||
table.insert(LoadedEntities,o)
|
||||
o.id = #LoadedEntities
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
@@ -31,8 +33,8 @@ function Fairy:Smart()
|
||||
self.target.y = main_Player.pos.y - main_Player.target_offset.y - 10
|
||||
local distance_x = self.target.x - self.pos.x
|
||||
local distance_y = self.target.y - self.pos.y
|
||||
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
|
||||
local angle = GetAngleFromVector(distance_x,distance_y)
|
||||
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
|
||||
if distance < self.range then
|
||||
self.vel.x = 0
|
||||
self.vel.y = 0
|
||||
@@ -40,6 +42,7 @@ function Fairy:Smart()
|
||||
self.vel.x = math.cos(angle)*self.speed*distance/(8*game.scale)
|
||||
self.vel.y = math.sin(angle)*self.speed*distance/(8*game.scale)
|
||||
end
|
||||
Particle:New(self.pos.x,self.pos.y,animation.particle.fairy,angle-math.rad(180),self.speed*distance/(16*game.scale))
|
||||
end
|
||||
|
||||
function Fairy:HandleAnimation()
|
||||
|
||||
@@ -28,9 +28,11 @@ Kupo = Entity:New(x,y)
|
||||
o.lightRange = o.range/2
|
||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||
|
||||
table.insert(LoadedEntities,o)
|
||||
o.id = #LoadedEntities
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
48
data/scripts/entities/particle.lua
Normal file
48
data/scripts/entities/particle.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
Particle = Entity:New(x,y)
|
||||
|
||||
function Particle:New(x,y,animation,rotation,speed)
|
||||
local o = Entity:New(x,y)
|
||||
|
||||
o.pos = {x = x, y = y}
|
||||
o.speed = speed or 0
|
||||
o.sprite_rotation = rotation or 0
|
||||
|
||||
o.time = 0.5
|
||||
o.timer = 0
|
||||
|
||||
o.vel = {
|
||||
x = o.speed * math.cos(o.sprite_rotation),
|
||||
y = o.speed * math.sin(o.sprite_rotation)
|
||||
}
|
||||
|
||||
-- animations
|
||||
o.body = Animation:New(animation)
|
||||
|
||||
table.insert(LoadedEntities,o)
|
||||
o.id = #LoadedEntities
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
function Particle:Smart()
|
||||
|
||||
end
|
||||
|
||||
function Particle:HandleAnimation()
|
||||
self.body:Animate()
|
||||
self.timer = self.timer + current_dt
|
||||
self.sprite_alpha = (self.time-self.timer)/self.time
|
||||
if self.sprite_alpha < 0 then self:Kill() end
|
||||
self:Draw(self.body)
|
||||
end
|
||||
|
||||
function Particle:DoPhysics()
|
||||
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, objects.collisions) then
|
||||
self.pos.x = self.pos.x + self.vel.x
|
||||
end
|
||||
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, objects.collisions) then
|
||||
self.pos.y = self.pos.y + self.vel.y
|
||||
end
|
||||
end
|
||||
@@ -53,9 +53,11 @@
|
||||
-- lights
|
||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||
|
||||
table.insert(LoadedEntities,o)
|
||||
o.id = #LoadedEntities
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user