mike: Added function to create object; created bouncing ball
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user