Code: Select all
function Ball:checkDistance(paddle)
local section = paddle.w / 5
local delta = self.h
-- x[_1_|_2_|_3_|_4_|_5_]w
--i need to check if the ball is close to the center, the further away the more we will alter the horizontal velocity
--this covers 1-5, the whole paddle, always true because thats how we got to this function
if self.x >= paddle.x and self.x <= paddle.x + paddle.w then
print("1-5")
delta = self.h * 1.75
--this covers 2-4 and overrides the prior
elseif self.x >= paddle.x + section and self.x <= paddle.x + paddle.w - section then
print("2-4")
delta = self.h * 1.45
--this covers 3 and overrides the two prior conditions
elseif self.x >= paddle.x + 2*section and self.x <= paddle.x + paddle.w - 2*section then
print("3")
delta = self.h * 1.15
end
self.h = delta
if self.h >= 225 then
self.h = 225
elseif self.h <= -225 then
self.h = -225
end
end