Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How to create reflection and detect when ui objects touch and where they intersect

I am trying to create a ping-pong game. I have already set up most of the logic (game start, game information, quit option, working paddles, and scorekeeper) and I am stuck on the main game functions (ball reflection off of the walls and paddles, and ball rotation in the direction of its movement).

I'm not looking for you to code for me. I'm asking for you to guide me in the right direction on how I should perform these functions.

This is where I am at with detecting whether or not rectangles are touching (paddles touching ball ext.) And I assume it doesn't work when the rectangles are rotated but I haven't tried.

func doOverlap(l1:Point, r1:Point, l2:Point, r2:Point) -> Bool {
    if (l1.x > r2.x || l2.x > r1.x || l1.y < r2.y || l2.y < r1.y) {
        return false
    }
    return true
}

If anyone chooses to respond to my question with an answer, don't spoil my practice with a full-fledged ping-pong game already programmed. I am only doing this for practice.

Main Question: Is there a way to detect rectangles collisions and determine where they intersect based on the direction of one of the rectangles in Xcode?

Comments