I have done so many of the regular projects out there, such as a tic tac toe, chess, hangman, asteroids, connect 4, but all of these projects felt small and I found there to not be much variety when it comes to game tutorials.
Most tutorials all cover the same games, with only variations in how they are coded. I also found that most tutorials, do not go through every element of a game, such as the start screen, all of the power ups, the score screens, etc.
I have done so many of the regular projects out there, such as a tic tac toe, chess, hangman, asteroids, connect 4, but all of these projects felt small and I found there to not be much variety when it comes to game tutorials.
Most tutorials all cover the same games, with only variations in how they are coded. I also found that most tutorials, do not go through every element of a game, such as the start screen, all of the power ups, the score screens, etc.
They usually only take you as far as the basic building blocks, and then leave you to create the rest, should you wish to continue.Most of these tutorials, have left me with a directory filled with what would be deemed as unfinished games.Hence I thought it would be great to put together a course on creating a game, with all of the game elements created and implemented in a step by step process, that leaves you at the end of the course, with a fully functional, and complete game.
My hope is that you are able to understand how each element of this game is created and implemented, so that you gain further insight when deciding to tackle a challenge of your own.
I also find the old games from the 80's and 90's as fantastic coding challenges, in particular when it comes to trying to understand how something may have been implemented.
Create the main.py file
Create the Main Class
Initialize the class with the init() method
Initialize the pygame module
Create the gameconfig file
Back in the Main class
Create the game window
Create the input() method
Create the update() method
Create the draw() method
Create the run_game() method
Insert the if Name = Main check to instantiate the main object
Run the game
Create the "game_assets.py" file
Create the "GameAssets" Class
Create the init() method
Use pygame.image.load() to load in game images
Use pygame.transform.scale() to change the size of an image
Create a method to combine the two functions above into one smooth process
Make use of default arguments in methods, in order to minimize the amount of typing/coding required.
Create a dictionary attribute, and fill that dicitionary with images, using a "for loop" and the newly created method
Import the game_assets.py file into the main.py file, in order to allow the Main class to create an instance of the GameAssets() object.
Run the game, ensuring no errors pop up.
Loading in of the 256 Tank images
Create the load_all_tank_images() method
Generate the Tank Images Dictionary
Populate the Tank Images Dictionary template using nested for loops
Create the scale_image() method
Create the sort_tanks_into_levels() method
Create the sort_tanks_into_groups() method
Create the sort_tanks_by_directions() method
Check the game for error messages, and draw a tank image to screen for testing
Input the various spritesheet coordinates for the various images.
Create a method to generate the image dictionaries, complete with various images
Create a method to get the required image from the sprite sheet.
Update the scale_image() method
Load in all of the image dictionaries with image files
Finally we at the point now where we can start coding the game into existence. The first thing we are going to create is the game object. The game object, and many of the other objects we will create will follow the same structure in terms of operation.
input()
update()
draw()
Many of the other methods we will create, will be called from within these three methods.
in the game class we create:
init()
input()
update()
draw()
Many more items will be created within these methods, but for now the base game is created.
As an aside, the reason why we are running the game in a class separate to the main class, is because the game moves through phases. We have a start screen, a game screen, and a level editor screen. So it will be easier to switch between the different phases in the main class.
Creating the characters file
Creating the Tank class.
Creating the Tank init() method
Inheriting from the pygame.sprite.Sprite() class
Creating the Tank input() method
Creating the Tank update() method
Creating the Tank draw() method
Creating the Tank.Move() method
Creating a new class PlayerTank
Inheriting from the base Tank class
Creating the input method for the PlayerTank class
Amending the game.py Game.input() method to pass inputs to the PlayerTank class
Amending the PlayerTank.input() method for two players
Creating the tank_movement_animation()
Fixing a movement bug
Drawing a rectangle to the screen
Creating the tank_on_tank_collisions() method
Checking for any collisions between the object and a sprite group
Determining the x and y coordinates of the object rectangle after colliding with another object.
Adding in the spawning star animation when a tank is created
Add spawn images to tank class
Add spawning boolean
Specify spawn star images
Create spawning timer
Create spawn star animation timer
Add spawn_animation() method
Update the tank.update() method
Update the tank.draw() method
Update the tank.move_tank() method
Creating the game_hud file
Defining the GameHud class
Creating the static Game Hud overlay image
Creating the GameHud update() method
Creating the GameHud draw() method
Calling the GameHud in the game file
Updating the GameHud object from the game file
Drawing the GameHud object in the game file
Create a player information panel that updates throughout the game.
Add Player active checks
Add Player lives for comparison in order to update the hud image
Include player checks in game object, to verify if only single player or two player.
Update game __init__() method so that player objects only created if player active
Update game input() method with player checks
Update game update() method with player checks
Update game draw() method with player checks
Create Display_player_lives method in hud object
Limit player lives variable
Display and return Grey image if player inactive
Create Tank image next to number of lives if number of lives in single digits
Create double digit image if number of lives greater than 10
Update HUD.update() method to call display_player_lives() if and only if there is a change in player lives
Blit player lives to the hud
update game input() in order to Test newly created lives display on hud
Clear game.input() of test code.
Updating the HUD screen, with the stage number
Add Attribute to Game class
Add attributes to GameHud class
Add display_stage_number() method in GameHud class
Update Attributes for GameHud class
Amend GameHud.update() method
Amend GameHud.draw() method
Test GameHud stage numbers
Finalising the GameHud object.
Adding the self.enemies attribute to game class
Declaring the STD_ENEMIES variable in gameconfig
Amending the GameHud.update() method to update the number of self.enemies
Create the draw_enemy_tanks_remaining() method
Amend the GameHud.draw() method
Define the Game Screen Coordinates in game config file
Amend the Tank class move_tank method so that tanks no longer move off of game screen.
Creating the Ammunition File
Creating the Bullet Class
Defining the init method of the Bullet Class
Adding the Bullets sprite group to the game file
Creating the Bullet.update() method
Creating the Bullet.draw() method
Creating the Tank.shoot() method
Updating the Game.input() method
Updating the Game.update() method
Updating the Game.Draw() method
Correcting the Update and draw methods of the Game Class
Creating the Bullet.move() method
Amending the Bullet.update() method
Adding bullet limiters to the Tank class
Updating the shoot method to include a bullet_sum check
Adding a Bullet collision check with the edge of the screen
Updating the Bullet owner's number of bullets fired
Creating an update owner method to update once a bullet is detroyed
Create the Collision with tanks method
Update the bullet.update() method
Amend the collision_with_tank() method, check tank owner
Update Tank.init() methods to distinguish between player tanks and computer tanks
Update PlayerTank.init() method
Amend Bullet.collide_with_tank() method, to check if bullet owner is player and tank collided is player
Add effects if player tank is hit by player tank, include paralysis attributes to tank class
Declare TANK_PARALYSIS variable in config file
Create paralyze_tank() method in tank class
Amend tank.update() method, to check for paralysis
Amend tank.move_tank() method, to check for paralysis
Update bullet.collide_with_tank() method to call tank.paralyze_tank method
Refactor collide_with_tank() method
Amend the game.input() method in order to create a computer tank
Amend the Bullet.collide_with_tank() method
Amend the Tank.init() method
Create the Tank.destroy_tank() method
Amend the Bullet.collide_with_tank() method
Create the Bullet.collision_with_bullets() method
Amend Bullet.update() method
Creating a mask for the Bullet class
Creating a mask_image for the Bullet class
Blitting that mask_image to the screen
Updating the Bullet to Bullet collisions methods with mask collisions
Updating the Bullet to Tank collision methods with mask collisions
Adding masks to the tank Class
Creating the get_varous_masks() method to tanks class
Updating the Tank.tank_movement_animation() method
Blitting the tank mask images to the screen
Amending the main.py init() method
Creating the leveleditor file
Defining the the LevelEditor Class
Defining the draw_screen() method
Defining the input() method
Defining the update() method
Defining the draw() method
Updating the main.input() method
Updating the main.update() method
Updating the main.draw() method
Create draw_grid_to_screen() method
Update draw() method
Create create_level_matrix() method
Update __init__() method
Add image Attributes
Update draw() method
Updating the input() method to move the Icon around the screen
Adding the Various Tile types into the init() method
Updating the input()method to select through the different tile types
Amending the update() method, to insert tile_types into matrix
Updating Draw() method to draw to screen the level matrix
Defining Spawn Coordinate variables in config file
Create validate_level() method
Update input() method to include validating level once created
Create level.py file
Define class LevelData()
Create LevelData init() method
Create LevelData Save_level_data() method
Create LevelData Load_level_data() method
Call levelData object in leveleditor
In this video, I will create the first level of the game. In the resources, you will find all 32 levels from the base game.
Importing LevelData to main.py
Adding start screen attributes
Amending main Input() method
Amending main update() method
New attributes to start screen class
Amending draw() method
Amending the input() method
Create _switch_options_main_menu()
Amending input() method
Create _selected_option_action()
Amending init() method
Create _animate_screen_into_position() method
Amending update() method
Create _complete_screen_position() method
Amending input() method
Create start_new_game() in main file
Create start_level_creator() in main file
Amending _selected_option_action()
Main file, init() method attribute
Main file, start_new_game() method
Create start_level_creator() method
Start screen update() method
Level Editor input() method
Main file init() method, adding a new attribute
Main file, input() method amendments
Game file, init() method attribute additions
Create create_new_stage() method.
Create load_level_data() method
Create generate_spawn_queue() method
Game config file, new variables
Game file, player objects.
Characters file, create new_stage_spawn() method
Game file, amend create_new_stage()
Game config file, new Variables
Game file, init() attributes
Game file, create spawn_enemy_tank() method
Amending update() method
Game file, init() method update
Amending create_new_stage() method
Amending base tank class.init() method
Amending base player tank class.init() method
Amending new_stage_spawn() method
Creating Tile file
Create Tile class
Create Tile init() method
Create Tile update() method
Create BrickTile class
Create BrickTile init() method
Create Tile _get_rect_and_size() method
Amending Game init() method() method
Amending the Game init() method
Tank class, create tank_collisions_with_obstacles()
Tank class, amend move_tank() method
Tank class, create grid_alignment_movement() method
Tank class, amend move_tank() method
Ammunition file, create collision_with_obstacles() method
Ammunition file, amending update() method
Tile file, create hit_by_bullet() method
Tile file, SteelTile class
Tile file, SteelTile.init() method
Tile file, SteelTile hit_by_bullet() method
Tile file, ForestTile class
Tile file, ForestTile.init() method
Tile file, IceTile class
Tile file, IceTile.init() method
Tile file, WaterTile class
Tile file, WaterTile.init() method
Tile file, WaterTile.update() method
Game file, new attributes in init() method
Create Fade_animate file
Create Fade class
Create Fade.init() method
Create Fade.update() method
Create Fade.draw() method
Game imports
Game file, amend new stage method
Game file, update() method
Game file, update draw() method
Fade animate, create move_y_fade()
Fade animate, update() method
Fade animate, amend draw() method
Fade animate, create_stage_image() method
Amend game file, init() method
Amend game file, update() method
Amend game file, create stage_transition() method
Characters file, amend player tank init() method
Ammunition file, amend collisition with tank() method
Create score screen file
Create ScoreScreen class
Create ScoreScreen.init() method
Create ScoreScreen generate_scoresheet_screen() method
Amend update() method
Amend draw() method
Amend game init() method
Create game stage_transition() method
Create game change_level() method
Amend game draw() method
Amending ScoreScreen update() method
Amending score screen file generate_score_screen() method
Create score screen number_image() method
Amending score screen init() method
Amending stage_transition() method
Amending change_level() method
Amending score screen update() method
Creating update_player_score_image() method
Amending score screen draw() method
Score SCreen create _create_top_score_and_stage_number_images() method
Amending init() method
Amending draw() method
Create update_basic_info() method
Amending stage_transition() method
Amending init() method
Amending generate_tank_kill_nums_images() method
Amending init() method
Amending draw() method
Score screen file, amending init() method
Score screen file, create update_score() method
Score screen file, update() method
Create Score screen file, clear_for_new_stage() method
Characters file amend init() file
Characters file, tank on tank collisions() method
Characters file, update() method
Characters file, spawn_star_collision_with_spawn_star() method
Characters file, create EnemyTank class
Characters file, create init() method
Game file, amending spawn_enemy_tank() method
Characters file, create ai_shooting() method
Characters file, update() method
Characters file, init() method
Characters file, input() method
Characters file, destroy tank() method
Characters file, respawn tank() method
Characters file, create ai_move() method
Characters file, create class MyRect class
Characters file, create init() method
Characters file, amend ai_move() method
Characters file, create draw() method
Characters file , amendment init() method
Characters file, create ai_move_direction() method
Characters file, create Special Tank class
Characters file, create init() method
Characters file, create update() method
Characters file, create destroy tank() method
Characters file, amending init() method
Characters file, amending destroy_tank() method
Creating the Power Ups file
Create Power Ups class
Create Power Ups init() method
Create Power Ups randomly_select_the_power_up() method
Create Power Ups update() method
Create Power Ups power_up_collected() method
Create Power Ups draw() method
Power Ups update() method
Power Ups shield() method
Power Ups init() method
Power Ups update() method
Power Ups draw() method
Power Ups Amending new_stage_spawn() method
Power Ups Amending respawn_tank() method
Power Ups - Freeze() method
Power Ups - Explosion() method
Power Ups - Extra life() method
Power Ups update() method
Power Ups power() method
Characters file method respawn tank() method
Characters file create special() method
Characters file init() method
Characters file amend tank collisions with obstacles() method
Characters file amend respawn_tank() method
Tiles file amend hit by bullet() method
Power Ups update() method
Power Ups fortify() method
Game file, amend init() method
Game file, power up fortify() method
Create explosion file
Explosion file, create Explosion class
Explosion file, create Explosion init() method
Explosion file, create Explosion update() method
Explosion file, create Explosion draw() method
Game file, amending init() method
Characters file, amending destroy tank() method
Characters file, amending destroy tank() method for players
Ammunition file, amending collide edge of screen() method
Ammunition file, amending bullet collide with tank() method
Ammunition file, amending bullet collide with obstacle() method
Creating the Scores file
Scores file, create ScoreBanner class
Score file, create init() method
Score file, create update() method
Score file, create draw() method
Game file, amend init() method
Power Ups amend power up collected()
Explosions amend init() method
Creating Eagle file
Eagle file, create Eagle class
Eagle file, create init() method
Eagle file, destroy base() method
Eagle file, update() method
Eagle file, draw() method
Amendments to game file
Characters file, create Base collision() method
Amend move tank() method
Amend update() method
Create Game Over file
Create Game Over class
Game Over file, create init() method
Game Over file, create activate() method
Game Over file, create update() method
Game Over file, draw() method
Game file, amending stage transition() method
Score screen file, amending update() method
Game file, amending update() method
Game Assets, amending init() files
Adding audio files
Removing print commands
Removing drawn rectangles
Updating level editor
OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.
Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.
Find this site helpful? Tell a friend about us.
We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.
Your purchases help us maintain our catalog and keep our servers humming without ads.
Thank you for supporting OpenCourser.