Give up on using a vector in a subclass for now I guess?

This commit is contained in:
Anna Rose 2023-09-27 03:05:50 -04:00
parent 27dd26bb32
commit b2cd05043e
2 changed files with 2 additions and 9 deletions

View File

@ -4,11 +4,10 @@ class("Ball").extends(Pixie)
function Ball:init(width, height, color, x, y) function Ball:init(width, height, color, x, y)
Ball.super.init(self, width, height, color, x, y) Ball.super.init(self, width, height, color, x, y)
-- trying to use a table / array for the direction vector doesn't work for bizarre reasons...
-- it fails on the init() call at runtime.
self.dirX = -1 self.dirX = -1
self.dirY = 1 self.dirY = 1
self.vector = {}
self.vector.x = -1
self.vector.y = 1
self.speed = 3 self.speed = 3
return self return self
end end
@ -18,8 +17,6 @@ function Ball:levelUp()
end end
function Ball:move() function Ball:move()
-- self:moveBy(self.vector.x * self.speed,
-- self.vector.y * self.speed)
self:moveBy(self.dirX * self.speed, self:moveBy(self.dirX * self.speed,
self.dirY * self.speed) self.dirY * self.speed)
end end
@ -34,11 +31,9 @@ end
function Ball:_normalizePosition() function Ball:_normalizePosition()
local changeVector = Ball.super._normalizePosition(self) local changeVector = Ball.super._normalizePosition(self)
if changeVector[1] ~= 0 then if changeVector[1] ~= 0 then
-- self.vector.x = changeVector[1]
self.dirX = changeVector[1] self.dirX = changeVector[1]
end end
if changeVector[2] ~= 0 then if changeVector[2] ~= 0 then
-- self.vector.y = changeVector[2]
self.dirY = changeVector[2] self.dirY = changeVector[2]
end end
end end

View File

@ -62,8 +62,6 @@ function Pixie:_normalizePosition()
end end
if changedX ~= 0 or changedY ~= 0 then if changedX ~= 0 or changedY ~= 0 then
-- call super to avoid the odd possibility that we recurse back into
-- this function
Pixie.super.moveTo(self, newX, newY) Pixie.super.moveTo(self, newX, newY)
end end