2022-02-26 18:21:52 +00:00
|
|
|
Arrow = Entity:New()
|
2021-10-24 23:41:40 +00:00
|
|
|
|
2022-02-26 02:56:53 +00:00
|
|
|
function Arrow:New(x,y,rotation,speed)
|
|
|
|
local o = Entity:New(x,y)
|
|
|
|
|
|
|
|
o.type = "arrow"
|
|
|
|
|
|
|
|
o.pos = {x = x, y = y}
|
|
|
|
o.speed = speed or 10
|
|
|
|
o.sprite_rotation = rotation or 0
|
|
|
|
o.vel = {
|
|
|
|
x = o.speed * math.cos(o.sprite_rotation),
|
|
|
|
y = o.speed * math.sin(o.sprite_rotation)
|
|
|
|
}
|
2021-10-24 23:41:40 +00:00
|
|
|
o.sprite_offset = {x = 13, y = 1}
|
2022-02-26 02:56:53 +00:00
|
|
|
o.stuck = false
|
|
|
|
o.illuminated = true
|
2021-10-29 02:15:53 +00:00
|
|
|
|
2022-02-26 02:56:53 +00:00
|
|
|
-- animations
|
|
|
|
o.body = Animation:New(animation.kupo.arrow)
|
2022-01-19 23:53:59 +00:00
|
|
|
|
2022-02-26 02:56:53 +00:00
|
|
|
o.boxCollision = {
|
|
|
|
from = {x = -0.5, y = -0.5}, --gameworld pixels
|
|
|
|
to = {x = 0.5, y = 0.5} -- gameworld pixels
|
|
|
|
}
|
2022-02-22 00:14:38 +00:00
|
|
|
|
2022-02-10 17:18:37 +00:00
|
|
|
table.insert(LoadedObjects.Entities,o)
|
|
|
|
o.id = #LoadedObjects.Entities
|
2021-10-29 02:15:53 +00:00
|
|
|
|
2022-02-26 02:56:53 +00:00
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
return o
|
|
|
|
end
|
2021-10-24 23:41:40 +00:00
|
|
|
|
2022-02-22 00:14:38 +00:00
|
|
|
function Arrow:DrawBackground()
|
2022-02-26 02:56:53 +00:00
|
|
|
self:Draw(self.body)
|
2021-10-24 23:41:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Arrow:DoPhysics()
|
2022-02-26 02:56:53 +00:00
|
|
|
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then
|
|
|
|
self.pos.x = self.pos.x + self.vel.x
|
|
|
|
else
|
|
|
|
self.stuck = true
|
|
|
|
end
|
|
|
|
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, LoadedObjects.Collisions) then
|
|
|
|
self.pos.y = self.pos.y + self.vel.y
|
|
|
|
else
|
|
|
|
self.stuck = true
|
|
|
|
end
|
|
|
|
if self.stuck then
|
|
|
|
self.pos.x = self.pos.x + self.vel.x * (2/3)
|
|
|
|
self.pos.y = self.pos.y + self.vel.y * (2/3)
|
|
|
|
self.vel.x = 0
|
|
|
|
self.vel.y = 0
|
|
|
|
end
|
2021-10-24 23:41:40 +00:00
|
|
|
end
|