2021-10-24 23:41:40 +00:00
|
|
|
Arrow = Entity:New(x,y)
|
|
|
|
|
|
|
|
function Arrow:New(x,y,rotation,speed)
|
|
|
|
local o = Entity:New(x,y)
|
2022-01-18 19:24:49 +00:00
|
|
|
arrow = arrow + 1
|
2021-10-24 23:41:40 +00:00
|
|
|
o.pos = {x = x, y = y}
|
|
|
|
o.speed = speed or 0
|
|
|
|
o.sprite_rotation = rotation or 0
|
|
|
|
o.vel = {
|
|
|
|
x = o.speed * math.cos(o.sprite_rotation),
|
|
|
|
y = o.speed * math.sin(o.sprite_rotation)
|
|
|
|
}
|
|
|
|
o.sprite_offset = {x = 13, y = 1}
|
|
|
|
o.stuck = false
|
2021-10-27 09:06:08 +00:00
|
|
|
o.illuminated = true
|
2021-10-29 02:15:53 +00:00
|
|
|
|
|
|
|
-- animations
|
|
|
|
o.body = Animation:New(animation.kupo.arrow)
|
2022-01-19 22:29:02 +00:00
|
|
|
|
|
|
|
table.insert(LoadedEntities,o)
|
|
|
|
o.id = #LoadedEntities
|
2021-10-29 02:15:53 +00:00
|
|
|
|
2021-10-24 23:41:40 +00:00
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
|
|
|
function Arrow:Smart()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function Arrow:HandleAnimation()
|
2022-01-17 23:14:54 +00:00
|
|
|
self:Draw(self.body)
|
2021-10-24 23:41:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Arrow:DoPhysics()
|
2022-01-18 19:24:49 +00:00
|
|
|
if not self.stuck then
|
|
|
|
-- horizontal collisions
|
|
|
|
if not isThereAnyCollisionAt(
|
|
|
|
self.pos.x + self.vel.x,
|
|
|
|
self.pos.y
|
|
|
|
) then
|
|
|
|
self.pos.x = self.pos.x + self.vel.x
|
|
|
|
else
|
|
|
|
while not isThereObjectAt(
|
|
|
|
self.pos.x + math.sign(self.vel.x),
|
|
|
|
self.pos.y,
|
|
|
|
objects.collisions
|
|
|
|
) do
|
|
|
|
self.pos.x = self.pos.x + math.sign(self.vel.x)
|
|
|
|
end
|
|
|
|
self.stuck = true
|
2021-10-24 23:41:40 +00:00
|
|
|
end
|
2022-01-18 19:24:49 +00:00
|
|
|
-- vertical collision
|
|
|
|
if not isThereAnyCollisionAt(
|
2021-11-28 02:38:30 +00:00
|
|
|
self.pos.x,
|
2022-01-18 19:24:49 +00:00
|
|
|
self.pos.y + self.vel.y
|
|
|
|
) then
|
|
|
|
self.pos.y = self.pos.y + self.vel.y
|
|
|
|
else
|
|
|
|
while not isThereObjectAt(
|
|
|
|
self.pos.x,
|
|
|
|
self.pos.y + math.sign(self.vel.y),
|
|
|
|
objects.collisions
|
|
|
|
) do
|
|
|
|
self.pos.y = self.pos.y + math.sign(self.vel.y)
|
|
|
|
end
|
|
|
|
self.stuck = true
|
|
|
|
end
|
|
|
|
-- stuck into collisions
|
|
|
|
if self.stuck then
|
|
|
|
--lets allow the arrow to tip a bit into the thing
|
|
|
|
self.pos.x = self.pos.x + self.vel.x / 5
|
|
|
|
self.pos.y = self.pos.y + self.vel.y / 5
|
|
|
|
self.vel.x = 0
|
|
|
|
self.vel.y = 0
|
|
|
|
self.illuminated = false
|
2021-10-24 23:41:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|