- Details of the drawSprite() function from an OpenGL perspective - OpenGL is a STATE MACHINE - Communicate w/ OpenGL by "set a bunch of global variables", then "do operation" - This can be faster since you don't send some data to the video card w/ every call. - Global state relevant for a 2D game: - Things you can't change in-between glBegin()/glEnd() - Current texture (or no texture) - Current blend mode - Current pixel shader - Things you can - Current color - Current tex coord - Current clear color - The drawSprite() function exists to avoid dealing with the state machine -- most state will change from call to call, so it's not useful anyway! - Tile based graphics strategies - Map is 2D Grid of (fixed size) tiles + object list - What is stored for a tile? - Texture - Optionally: Animation sequence - Collision info - Can be an integer for different shapes - Other game-specific info - Sound FX - Speed triggers - Level goal - etc etc. - Multiple planes of tiles can achieve cheap 3D depth feeling - I suggest at least a "front" and "back" grid - Allows paralax scrolling, too! - Have different layers scroll at different speeds for more immersive 3D feel - "Farther" planes should scroll slower - "Closer" planes should scroll faster - Can add as many paralax layers as you want! - Collision detection - Comonly used primitives - Point - AABB (Axis-Aligned Bounding Box) - Circle - Convex Polygon - Capsule - Capsule is just AABB + two circles. - Check collision w/ capsule by checking if any of the subobjects collide - Collision detection for different pairings - Point / Point - Trivial - Point / AABB - check if point is inside X range and Y range - Point / Circle - check if point dist from circle center is less than radius - Point / Convex polygon - "Half planes" algorithm - Construct a normal to each edge - Construct a vector from an edge point to the test point - Use the dot-product to see which side of the edge the test point is on - if point is on "inside" side for all edges, then INTERSECTION! - AABB / AABB - "Shrink space" algorithm - Take second AABB, and clamp it to the first AABB. - If you have a non-zero space left over, then INTERSECTION! - AABB / Circle - "Shrink space" algorithm - Take circle's center, clamp it to AABB - Calc distance from closest point to circle, if less than circle's raidus, INTERSECTION! - AABB / Convex polygon - Simplified version of Convex polygon / Convex polygon - See below. - Circle / Circle - Distance between centers, if less than sum of raidii, INTERSECTION! - Circle / Convex polygon - See below - Convex polygon / Convex polygon - VERY TIME CONSUMING - http://gpwiki.org/index.php/Polygon_Collision - "Seperating Axis" - Use Point / Polygon test on each point of one poly relative to each side of the other - If all the points are on the "outside" side of the polygon, then NO INTERSECTION! - Need to do this for both polygons! - Second way to think about it: - Project away the dimension of each edge - If line segments created don't intersect, then NO INTERSECTION - Circle / Convex polygon - Do Convex polygon / Convex polygon, but with just the center of the circle - Then check distance based on Radius, if center is less than raidus away from projected polygon, INTERSECTION