2022-01-17 23:14:54 +00:00
|
|
|
Fairy = Entity:New(x,y)
|
|
|
|
|
|
|
|
function Fairy:New(x,y)
|
|
|
|
local o = Entity:New(x,y)
|
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
-- behaviour
|
2022-01-17 23:14:54 +00:00
|
|
|
o.pos = {x = x, y = y}
|
|
|
|
o.speed = 0.23
|
|
|
|
o.range = 20
|
|
|
|
o.target = {x = x, y = y}
|
|
|
|
|
|
|
|
-- animations
|
|
|
|
o.body = Animation:New(animation.fairy.flying)
|
|
|
|
o:centerOffset(o.body)
|
|
|
|
o:getBoundingBox(o.body)
|
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
-- light
|
|
|
|
o.light_range = 80
|
|
|
|
o.light = CreateLight(o.pos.x,o.pos.y,o.light_range,nil,HEX2RGB("#fed100"))
|
2022-01-17 23:14:54 +00:00
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
-- timer
|
|
|
|
o.particle_timer = 0
|
|
|
|
o.particle_time = 5
|
2022-01-17 23:14:54 +00:00
|
|
|
|
2022-01-19 22:29:02 +00:00
|
|
|
table.insert(LoadedEntities,o)
|
|
|
|
o.id = #LoadedEntities
|
|
|
|
|
2022-01-17 23:14:54 +00:00
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
|
|
|
function Fairy:Smart()
|
|
|
|
|
|
|
|
self.target.x = main_Player.pos.x - main_Player.target_offset.x
|
|
|
|
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 angle = GetAngleFromVector(distance_x,distance_y)
|
2022-01-19 22:29:02 +00:00
|
|
|
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
|
2022-01-17 23:14:54 +00:00
|
|
|
if distance < self.range then
|
|
|
|
self.vel.x = 0
|
|
|
|
self.vel.y = 0
|
|
|
|
else
|
2022-01-29 07:49:45 +00:00
|
|
|
self.vel.x = math.cos(angle)*self.speed*distance/8
|
|
|
|
self.vel.y = math.sin(angle)*self.speed*distance/8
|
2022-01-19 23:53:59 +00:00
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
end
|
|
|
|
self.particle_timer = self.particle_timer + 1
|
|
|
|
if self.particle_timer >= self.particle_time then
|
|
|
|
self.particle_timer = 0
|
2022-01-19 23:53:59 +00:00
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
local particle_data = {
|
|
|
|
animation = animation.particle.simple,
|
|
|
|
sprite_tint = HEX2RGB("#fe00d1"),
|
|
|
|
direction = angle-math.rad(180+math.random(60)-30),
|
|
|
|
speed = 0.8*(distance/50),
|
|
|
|
speed_increase = -0.01,
|
|
|
|
}
|
|
|
|
Particle:New(
|
|
|
|
self.pos.x,
|
|
|
|
self.pos.y,
|
|
|
|
particle_data
|
|
|
|
)
|
|
|
|
end
|
2022-01-17 23:14:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Fairy:HandleAnimation()
|
|
|
|
self.body:Animate()
|
|
|
|
--if self:isCollidingWith(main_Player) then self.sprite_tint = {1,0,0} else self.sprite_tint = {1,1,1} end
|
|
|
|
self:Draw(self.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Fairy:DoPhysics()
|
2022-01-18 19:29:43 +00:00
|
|
|
local random_x = math.random(-4, 4)/100
|
|
|
|
local random_y = math.random(-4, 4)/100
|
2022-01-17 23:14:54 +00:00
|
|
|
self.vel.x = self.vel.x + random_x
|
|
|
|
self.vel.y = self.vel.y + random_y
|
|
|
|
-- move
|
2022-01-29 07:49:45 +00:00
|
|
|
|
2022-01-22 22:10:21 +00:00
|
|
|
self:CollisionMove()
|
2022-01-29 07:49:45 +00:00
|
|
|
self:LightAdjust()
|
2022-01-17 23:14:54 +00:00
|
|
|
end
|