Add some object-oriented sensibilities into this mess.
This commit is contained in:
parent
2d0736fcd0
commit
27dd26bb32
3 changed files with 141 additions and 95 deletions
44
ball.lua
Normal file
44
ball.lua
Normal file
|
@ -0,0 +1,44 @@
|
|||
import "pixie"
|
||||
|
||||
class("Ball").extends(Pixie)
|
||||
|
||||
function Ball:init(width, height, color, x, y)
|
||||
Ball.super.init(self, width, height, color, x, y)
|
||||
self.dirX = -1
|
||||
self.dirY = 1
|
||||
self.vector = {}
|
||||
self.vector.x = -1
|
||||
self.vector.y = 1
|
||||
self.speed = 3
|
||||
return self
|
||||
end
|
||||
|
||||
function Ball:levelUp()
|
||||
self.speed += 1
|
||||
end
|
||||
|
||||
function Ball:move()
|
||||
-- self:moveBy(self.vector.x * self.speed,
|
||||
-- self.vector.y * self.speed)
|
||||
self:moveBy(self.dirX * self.speed,
|
||||
self.dirY * self.speed)
|
||||
end
|
||||
|
||||
function Ball:setDirection(x, y)
|
||||
x = x or self.dirX
|
||||
y = y or self.dirY
|
||||
self.dirX = x
|
||||
self.dirY = y
|
||||
end
|
||||
|
||||
function Ball:_normalizePosition()
|
||||
local changeVector = Ball.super._normalizePosition(self)
|
||||
if changeVector[1] ~= 0 then
|
||||
-- self.vector.x = changeVector[1]
|
||||
self.dirX = changeVector[1]
|
||||
end
|
||||
if changeVector[2] ~= 0 then
|
||||
-- self.vector.y = changeVector[2]
|
||||
self.dirY = changeVector[2]
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue