function col_detect(object, display) if not (object.x >= -1 and object.x <= (display.width - object.width)) then return false end if not (object.y >= -1 and object.y <= (display.height - object.height)) then return false end 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