mike: Added function to create object; created bouncing ball

This commit is contained in:
2017-07-22 15:45:12 -07:00
parent 3953d079d6
commit 841c7a8706
2 changed files with 32 additions and 7 deletions

View File

@@ -12,3 +12,27 @@ function col_detect(object, display)
return true
end
function create_object(start_x, start_y, width, height, speed)
local object = {}
object.x = start_x
object.y = start_y
object.width = width
object.height = height
object.speed = speed
return object
end
function ball_bounce(ball)
ball.x = ball.x + ball.x_speed
ball.y = ball.y + ball.y_speed
if ball.x >= screen.width or ball.x < 0 then
ball.x_speed = ball.x_speed * -1
end
if ball.y >= screen.height or ball.y <0 then
ball.y_speed = ball.y_speed * -1
end
return ball
end