So far, our game objects exist only as single points (Vec2 Position
). While great for movement, it's not enough for interactions like checking if a projectile hits a character.
This lesson tackles that by introducing bounding boxes – simple rectangular shapes that represent the space an object occupies. We'll focus on Axis-Aligned Bounding Boxes (AABBs), implement a BoundingBox
class using SDL_FRect
, add it to our GameObject
, and learn how to draw these boxes for debugging purposes.
In the next lesson, we’ll learn how to use these bounding boxes to detect when they intersect, and some practical reasons why that is useful.
Finally, we’ll end the chapter by revisiting our physics system and use our new bounding boxes to let our objects physically interact with each other.
SDL_HasIntersection()
.In this lesson, we'll learn how to determine if shapes overlap in our game world, a process often called intersection testing. We'll focus on using SDL's built in functions like SDL_HasIntersection()
and SDL_IntersectRect()
to check if SDL_Rect
and SDL_FRect
objects intersect.
We'll also see how these tests are crucial for relevancy testing - optimizing our game by only updating objects that are currently important, like those near the player or visible on screen.
In this lesson, we’ll revisit our physics system and integrate our new bounding boxes and rectangle intersection tools to allow objects to interact with each other.
We'll start by adding a floor object, and we’ll use bounding box intersections to detect when our object hits the floor (or anything else).
Finally, we'll code the logic to react to these collisions appropriately, with behaviors such as preventing objects from overlapping or reducing our player’s health if they get hit by a projectile.
In this lesson, we'll explore fundamental physics principles and how to implement them in our games. We'll explore how to represent position, velocity, and acceleration using our vector system, and how these properties interact over time.
By the end, you'll understand how to create natural movement, predict object trajectories, and integrate player input with physics systems.
We’ll be working with the basic Scene
, GameObject
, and Vec2
types we created previously:
Now that we understand basic motion in our game engine, it's time to explore the forces that drive that motion. In this lesson, we'll implement several physical forces including gravity, drag, and friction.
We'll see how each affects our game objects differently based on their properties like mass and velocity. These techniques will allow you to create more realistic and engaging gameplay.
In this lesson, we’ll continue to use the basic application loop and components we introduced in the previous lesson. We’ll mostly be working in the GameObject
class in this lesson.
It currently looks like the following, with the most notable characteristics being the Position
, Velocity
, and Acceleration
vectors, and the Tick()
function that updates them:
In this lesson, we'll explore how to implement physics interactions by adding momentum and impulses to our simulations.
We'll learn we can use physics to create features requiring sudden changes to motion, such as having our characters jump or get knocked back by explosions. We’ll also learn how to modify the strength of those forces based on how far away the source of the force is.
This lesson continues to use the components and application loop we introduced earlier in the section. We’ll mostly be working in the GameObject
class.
The most relevant parts of this class to note for this lesson are its Tick()
and ApplyForce()
functions, as well as the Position
, Velocity
, Acceleration
, and Mass
variables. Those functions and variables currently look like this:
When developing games, we need a way to represent our virtual world and then transform it to display on a screen
In this lesson, we'll create a complete scene system that lets us position game objects using world coordinates, and then automatically converts those positions to screen coordinates when rendering.
We’ll be using the Vec2
struct we created in the previous chapter, as well as Window
and Image
classes using techniques we covered earlier in the course. A complete version of these are available below:
In most games, the player cannot view the entire game world at the same time. Rather, we can imagine the player moving a virtual camera around the world and what that camera sees determines what appears on the player’s screen.
In a top-down game, for example, they might move that camera by clicking and dragging their mouse. In an action game, the camera is attached to the player they’re controlling. As such, we need to show the world from the perspective of that camera. This view is another example of a space, commonly called the view space or camera space.
In this lesson, we'll explore how view space works, we’ll implement camera movement controls, and create character-following mechanics.
We’ll be using the Vec2
struct we created earlier. A complete version of it is available below:
When developing games, we frequently need to work with both continuous values (like physics positions) and discrete ones (like screen pixels).
In this lesson, we'll explore the challenges of working with floating point numbers in different coordinate spaces and learn practical techniques to avoid common pitfalls related to precision and comparison.
We’ll be using the Vec2
struct we created earlier in the course. A complete version of it is available below:
In previous lessons, we hinted at a custom type that could store a two-dimensional vector, which we can use to represent positions in a space. Such a type is typically called a vector, and they are the fundamental building block of computer graphics, simulation, and more.
Throughout the rest of this chapter, we’ll use them to represent concepts like positions, movements, directions, accelerations, and forces.
In this lesson, we'll implement a Vec2
type that can represent positions, movements, and forces in a 2D space by equipping our vector with operations like addition, subtraction, and scalar multiplication. This foundation will serve us well throughout the remainder of this chapter as we build increasingly sophisticated graphics and physics systems for our games.