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.
In this lesson, we’ll see some examples of how we can use our new Vec2
type to support functionality like positioning and moving objects within our game world.
We'll see how vectors provide elegant solutions for positioning and moving objects in a game world. We'll implement a character movement system that handles speed limits, direction calculations, and smooth transitions between positions. Later in the course, we’ll build on these techniques, introducing concepts like acceleration, gravity, and other forces to our movement logic.
The examples in this lesson use the Vec2
type we created in the previous section. A complete version of this struct is available below:
Every non-trivial game needs to represent positions in at least two different ways: where things are in the game world, and where they appear on the player's screen.
These different representation systems are called the world space and the screen space, and converting between them is a core skill in game development. In this lesson, we'll explore some of the main reasons why we need to work across multiple spaces, and how to transform our objects between them.
We’ll be using the Vec2
struct we created earlier in the course. A complete version of it is available below:
cmath
Math and programming go hand in hand, especially in game development. We’ll cover the core concepts throughout this chapter, starting from the basics and moving on to concepts that allow us to implement things like virtual cameras and physics systems.
In this first lesson, we're starting with the fundamentals - exponents and square roots. We'll explore how these work in C++, look at different ways to implement them, and start thinking about performance considerations. This sets the stage for the more complex math concepts we'll tackle as we move forward.
In this lesson, we'll cover coordinate systems and vectors, which form the basis of spatial representation in computer graphics. These mathematical constructs allow us to specify the positions of objects in our virtual worlds.
We'll start by defining spaces and the Cartesian coordinate system. Then, we'll examine vectors as a way to store positional data using multiple components. Finally, we'll explore how to implement these structures in C++ and understand the transformations required to convert between different coordinate spaces.
These concepts serve as building blocks for all spatial calculations in game development, from simple 2D positioning to complex 3D transformations.
This lesson introduces the core geometric concepts used in game programming. We'll cover angles and right-angled triangles before exploring the Pythagorean theorem and its applications in calculating distances.
We'll implement these mathematical principles in C++ to solve common game development problems. The lesson demonstrates how to calculate vector magnitudes and distances between objects in both 2D and 3D coordinate systems.
These techniques form the basis for many game mechanics, including collision detection and spatial positioning, which we’ll implement later in this chapter.
In this lesson, we'll build the foundational components of our Snake game. We'll implement the essential components for window management, asset handling, and user interface. This framework will serve as the backbone for our game's implementation.
In this lesson, we'll build the foundation of our Snake game by implementing a grid system. We'll create Cell
and Grid
classes to manage the game state, handle rendering, and prepare for the snake's movement.
By the end, you'll have a fully functional grid that displays the initial snake position and first apple.
In this lesson, we'll implement the core mechanics of our snake game. We'll create the game state management system, handle user input for controlling the snake's movement, and implement the snake's movement logic. By the end, you'll have a fully functional snake that responds to player controls.
We'll start by defining the fundamental data structures needed to track our snake's state, including its position, length, and direction. Then we'll expand our state system to advance the game through time.
Finally, we’ll allow our game state to respond to user input, allowing the player to control the direction their snake moves.
Now that we have our basic movement system in place, it's time to make our Snake game truly playable. We'll implement apple consumption mechanics, handle snake growth, and create a dynamic apple spawning system.
By the end of this section, our snake will be able to move around the grid eating apples, and getting longer for every apple it consumes.