Build Asteroids Game Project via https://boot.dev course.
- Introduction to multi-file projects
- Seeing a real world use case for OOP (Object Oriented Programming)
- Have fun building a project and learning something new
"The goal is not to teach game development or the math required for physics simulations. As a result, there are some places where you will simply copy-paste code that we wrote for you. Don't worry about trying to understand every detail if it's not interesting to you, you will be asked to write the parts that matter most."
Games often have a lot of magic numbers to represent things like player speeds, item costs, and attack damage. We will use this file as a place to store those kind of constant values.
"In computer programming, a magic number is any of the following:
- A unique value with unexplained meaning or multiple occurrences which could (preferably) be replaced with a named constant
- A constant numerical or text value used to identify a file format or protocol (for files, see List of file signatures)
- A distinctive unique value that is unlikely to be mistaken for other meanings (e.g., Globally Unique Identifiers)"
In Python, each .py file is a module, and we can import functions, variables, and classes from one module into another with the import statement.
# import the function_hello function
# and the variable_player variable
# into the current file
from filename import function_hello, variable_player
If you want to import everything from a file, you can use the * character:
# import everything from filename
# into the current file
from filename import *
Video games are generally built using a game loop. The simplest game loop has 3 steps:
- Check for player inputs
- Update the game world
- Draw the game to the screen
To create a good user experience, these 3 steps need to happen many times per second.
It is simple to create an infinite while loop, you won't use it often but this is helpful to know:
while True:
print("foobar")
In math, the Greek letter delta (ฮ) is often used to represent a change in a value. In game development, we use "delta time" to represent the amount of time that has passed since the last frame was drawn. This value is useful to decouple the game's speed from the speed it's being drawn to the screen.
"If your computer speeds up, the asteroids shouldn't also speed up. Conversely, if your computer slows down, the asteroids shouldn't also slow down: they would just move less smoothly."
"A sprite is a two-dimensional (2D) graphical object used in computer graphics, particularly in video games. It typically consists of a bitmap image or a series of images that are combined to create an animation. A sprite can be thought of as a separate entity that exists within a larger scene, such as a video game world."
"Hit boxes are areas programmed into a video or computer game where an attack will hit and do damage. A hurt box is where a player or bot can be hurt by another's attack. Splash damage is the area where a player or bot's own attack does damage to themselves. Explosive weapons like rocket launchers and grenades usually do splash damage if they explode too close to the player or bot, even when friendly fire is on."
"In mathematics, a unit vector in a normed vector space is a vector (often a spatial vector) of length 1. A unit vector is often denoted by a lowercase letter with a circumflex, or "hat", as in v $^{\displaystyle {\hat {\mathbf {v} }}} (pronounced "v-hat")$."
"The term direction vector, commonly denoted as d, is used to describe a unit vector being used to represent spatial direction and relative direction. 2D spatial directions are numerically equivalent to points on the unit circle and spatial directions in 3D are equivalent to a point on the unit sphere."
"A simple container for Sprite objects. This class can be inherited to create containers with more specific behaviors. The constructor takes any number of Sprite arguments to add to the Group. "