fixed arrow physics
This commit is contained in:
@@ -6,7 +6,7 @@ Arrow = Entity:New(x,y)
|
||||
o.type = "arrow"
|
||||
|
||||
o.pos = {x = x, y = y}
|
||||
o.speed = speed or 0
|
||||
o.speed = speed or 10
|
||||
o.sprite_rotation = rotation or 0
|
||||
o.vel = {
|
||||
x = o.speed * math.cos(o.sprite_rotation),
|
||||
@@ -19,6 +19,11 @@ Arrow = Entity:New(x,y)
|
||||
-- animations
|
||||
o.body = Animation:New(animation.kupo.arrow)
|
||||
|
||||
o.boxCollision = {
|
||||
from = {x = -0.5, y = -0.5}, --gameworld pixels
|
||||
to = {x = 0.5, y = 0.5} -- gameworld pixels
|
||||
}
|
||||
|
||||
table.insert(LoadedObjects.Entities,o)
|
||||
o.id = #LoadedObjects.Entities
|
||||
|
||||
@@ -27,52 +32,25 @@ Arrow = Entity:New(x,y)
|
||||
return o
|
||||
end
|
||||
|
||||
function Arrow:HandleAnimation()
|
||||
function Arrow:DrawBackground()
|
||||
self:Draw(self.body)
|
||||
end
|
||||
|
||||
function Arrow:DoPhysics()
|
||||
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,
|
||||
LoadedObjects.Collisions
|
||||
) do
|
||||
self.pos.x = self.pos.x + math.sign(self.vel.x)
|
||||
end
|
||||
self.stuck = true
|
||||
end
|
||||
-- vertical collision
|
||||
if not isThereAnyCollisionAt(
|
||||
self.pos.x,
|
||||
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),
|
||||
LoadedObjects.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
|
||||
end
|
||||
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
|
||||
end
|
||||
|
||||
@@ -89,7 +89,7 @@ function Kupo:Smart()
|
||||
if self.bow_aim_frame > self.bow_aim_frames then
|
||||
self.bow_aim_frame = self.bow_aim_frame - self.bow_aim_frames
|
||||
self.bow_frame = self.bow_frame + 1
|
||||
Arrow:New(self.pos.x,self.pos.y,self.bow_rotation,15)
|
||||
Arrow:New(self.pos.x,self.pos.y,self.bow_rotation,10)
|
||||
end
|
||||
else
|
||||
self.bow_frame = self.bow_frame + 1
|
||||
@@ -157,12 +157,5 @@ function Kupo:HandleAnimation()
|
||||
end
|
||||
|
||||
function Kupo:DoPhysics()
|
||||
|
||||
-- horizontal collisions
|
||||
if not isThereAnyCollisionAt(self.pos.x + self.vel.x, self.pos.y) then
|
||||
self.pos.x = self.pos.x + self.vel.x
|
||||
end
|
||||
if not isThereAnyCollisionAt(self.pos.x, self.pos.y + self.vel.y) then
|
||||
self.pos.y = self.pos.y + self.vel.y
|
||||
end
|
||||
self:CollisionMove()
|
||||
end
|
||||
|
||||
@@ -35,11 +35,6 @@
|
||||
y = nil
|
||||
}
|
||||
|
||||
o.boxCollision = {
|
||||
from = {x = -8, y = -16}, --gameworld pixels
|
||||
to = {x = 8, y = 0} -- gameworld pixels
|
||||
}
|
||||
|
||||
o.lightRange = 40 -- screen pixels
|
||||
|
||||
-- status
|
||||
|
||||
Reference in New Issue
Block a user