Python Project

Space Shooters Game

This project is a very simple python game I built in my first semester. It's a top-down vertical shooting game where the user controls one ship at the bottom of the screen and must shoot at five enemy ships at the top of the screen. The player can take three hits from enemy bullets before they are destroyed. The game continues until the player or all five enemy ships are destroyed, whichever comes first, and a score is displayed based on how many enemy ships were destroyed.

This is the first screen the player sees upon starting the game, it gives the player control instructions on how to play and what their goal is. To ensure the game does not begin before player is ready, the game will remain on this screen until they press the Enter key.

The main screen of the game, the player controls the blue ship and must attack the enemy red ships. To prevent visual confusion about which projectiles belong to which side, enemies will shoot yellow lasers while the player shoots white lasers.

The final screen of the game, once either the player or all enemy ships are destroyed the game will move to this screen where the player's score is displayed. The player is awarded 500 points for each ship they destroy so this example shows when the player successfully destroys all five enemy ships. Similar to the first screen, the game will remain here until the player presses the Esc key to close the game so they have time to see their score.

I used rapidly shifting random numbers to create this logic for having the enemy ships randomly move, occasionally not moving to give the player a better shot at them, and to sometimes toggle a boolean flag for them to fire lasers at the player. The numbers cycle very quickly, so even though the range for firing a laser seems small, it comes up a good, but not overwhelming, amount of times.

The bulk of the main loop logic, here the code manages collections containing the shots fired by enemies, shots fired by the player, and the enemy ships themselves. The code iterates through each of these collections and calls methods to handle each of their respective behaviours which constantly checking for game ending conditions to trigger falling out of this main loop and proceeding to the end screen of the game.

For code simplicity, the same bullet class is used by both the player and the enemies with the difference in colour caused by passing a colour hex code as a parameter when bullet objects are instantiated and the difference in behaviour determined by which class method is called on the bullet objects. Since the only real difference between the types of bullets is what direction they are fired in, it would have caused a lot of redundant code to split them into separate classes.