function screen_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 num_is_pos(number) if number > 0 then return true else return false end end function ball_bounce(ball) local paddle_hit = false ball.x = ball.x + ball.x_speed ball.y = ball.y + ball.y_speed --If ball hits screen wall if ball.x >= screen.width or ball.x < 0 then ball.x_speed = ball.x_speed * -1 end --If ball hits screen top/bottom if ball.y >= screen.height or ball.y <0 then ball.y_speed = ball.y_speed * -1 end --If ball hits paddle if ball.y + 1 >= player.y and ball.x >= player.x and ball.x <= player.x + player.width then ball.y_speed = ball.y_speed *-1 paddle_hit = true end if paddle_hit == true then if ball.x < player.x + (player.width/2) and num_is_pos(ball.x_speed) then ball.x_speed = ball.x_speed *-1 elseif ball.x > player.x + (player.width/2) and not num_is_pos(ball.x_speed) then ball.x_speed = ball.x_speed *-1 end end return ball end