Presentation is loading. Please wait.

Presentation is loading. Please wait.

Determining When Two Objects Collide in a Turing Program

Similar presentations


Presentation on theme: "Determining When Two Objects Collide in a Turing Program"— Presentation transcript:

1 Determining When Two Objects Collide in a Turing Program
Collisions Determining When Two Objects Collide in a Turing Program

2 Remember all references to the position of a sprite are based on the bottom left corner of the sprite. xPlane + Pic.Width(plane), yPlane + Pic.Height (plane) xPlane, yPlane + Pic.Height(plane) xPlane + Pic.Width(plane), yPlane xPlane, yPlane

3 A collision occurs when the two sprites “touch”
A collision occurs when the two sprites “touch”. The computer determines this by comparing the coordinates of the spites and determining whether certain conditions are true (ie. whether the coordinates “cross” or “touch”). There are four ways one graphic can collide with another – from the top or bottom (y-coordinate of the sprites are compared) and from the left or right (x-coordinate of the sprites are compared).

4 yPlane < yBird + Pic.Height(bird)
In the example below, the bird collides with the plane from the bottom. A collision occurs when the y-coordinate of the bottom of the plane sprite (yPlane) is less than the y-coordinate of the top of the bird sprite (yBird + Pic.Height(bird)). yPlane < yBird + Pic.Height(bird) yPlane > yBird + Pic.Height(bird)

5 yPlane + Pic.Height(plane) > yBird
In the example below, the bird collides with the plane from the top. A collision occurs when the y-coordinate of the top of the plane sprite (yPlane + Pic.Height(plane)) is greater than the y-coordinate of the bottom of the bird sprite (yBird). yPlane + Pic.Height(plane) > yBird yPlane + Pic.Height(plane) < yBird

6 xPlane + Pic.Width(plane) > xBird
In the example below, the bird collides with the plane from the right. A collision occurs when the x-coordinate of the right of the plane sprite (xPlane + Pic.Width(plane)) is greater than the x-coordinate of the left of the bird sprite (xBird). xPlane + Pic.Width(plane) > xBird xPlane + Pic.Width(plane) < xBird

7 xPlane < xBird + Pic.Width(bird)
In the example below, the bird collides with the plane from the left. A collision occurs when the x-coordinate of the left of the plane sprite (xPlane) is less than the x-coordinate of the left of the bird sprite (xBird+ Pic.Width(plane)). xPlane < xBird + Pic.Width(bird) xPlane > xBird + Pic.Width(bird)

8 xPlane < xBird + Pic.Width(bird)
In the example below, the bird does not collide with the plane from the right even though the y-coordinate of the left of the plane sprite (xPlane) is less than the y-coordinate of the right of the bird sprite (xBird + Pic.Width(bird)) when it finishes. Why? xPlane < xBird + Pic.Width(bird) xPlane > xBird + Pic.Width(bird)

9 In order for a collision to occur, all the conditions described in the previous slides must be true. The program must therefore have the following code to check for a collision: if yPlane < yBird + Pic.Height(bird) % Checks from bottom and yPlane + Pic.Height(plane) > yBird %Checks from top and xPlane + Pic. Width(plane) > xBird % Checks from right and xPlane < xBird + Pic.Width(bird) % Checks from left then


Download ppt "Determining When Two Objects Collide in a Turing Program"

Similar presentations


Ads by Google