CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Collision detection
Collision detection We already had to implement some basic collision detection ● in the motion example ○ I.e., to keep our square from moving out of the window ○ Checking for collisions with the boundary of the window ● Generally, games will have many objects moving around the screen, how can we check whether they've hit one another? 2
No Collision 3
No Collision 4
No Collision 5
COLLISION! 6
Colliding circles 7
Complex collisions 8
Complex collisions in action 9
Even more complex collisions 10
Really complex collisions 11
Street Fighter II Hitboxes 12
The same idea is used in 3D games 13
Back to 2D And some help from SDL ● ○ SDL_bool SDL_HasIntersection(const SDL_Rect* A, const SDL_Rect* B) ■ True if the two SDL_Rect 's intersect ■ False otherwise ○ SDL_bool SDL_IntersectRect(const SDL_Rect* A, constSDL_Rect* B, SDL_Rect* result) ■ Same returns, but will also set result to the intersection of A and B if one exists ■ result will be NULL if there is no intersection 14
Recommend
More recommend