Giter Club home page Giter Club logo

python-asteroids's Introduction

Python-Asteroids

Build Asteroids Game Project via https://boot.dev course.

[Learning Goals]

  • 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."

[Valuable Information]

Magic Numbers

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)"

View Here

Importing

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 *

Game Loops

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.

Infinite While-Loops

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")

Delta Time

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."

Sprites

"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."

View Here

Hitboxes

"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."

View Here

Unit Vector

"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."

View Here

Pygame Group Class

"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. "

View Here

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.