by Janek SQ9NIL, www.operator-paramedyk.pl
Thanks @majki09 for your contribution!
Pirates Invasion is a simple Space Invaders clone based on tutorial in Eric Matthes Python Crash Course: A Hands-On, Project-Based Introduction to Programming (2nd Edition by No Starch Press, Inc.). I followed his instructions when I started to learn Python and then made some changes:
- changed topic from alien invasion to sea battle with pirates (my son loves them!) by adding graphics by myself,
- added random distribution of pirates in the fleet,
- improve graphics by flipping ships when they reach the boarder of the screen.
You are the captain of a ship fighting the pirates fleet that wants to enter the port. Your task is to shoot all pirates ships before they cross your position.
To start the game, press Click to play button.
Use left and right arrows keys to move your ship left and right, and press spacebar to shoot the cannon. You can shoot three cannonballs at the same time.
You can quit the game by pressing q at any time.
Every time you shoot all the pirates ships, you progress to next level. This means that new pirates fleet, that is faster than the previous one, is generated, and you will get more points for every pirates ship shoot down.
if pirates ship collides with yours or reaches the bottom of the screen, you will loose one ship. Game ends if you loose three ships (by default).
You can control the game with Settings class, stored in settings.py file. Below all of them are clarified, together with the default values.
These are the settings that are set-up once for the whole game.
-
screen resolution:
self.screen_width = 1200
andself.screen_height = 720
-
background color (seawater)
self.bg_color = (0, 162, 232)
- number of lives (presented in the top-left corner of the screen):
self.ships_limit = 3
-
cannonball dimensions:
self.bullet_width = 10
andself.bullet_height = 10
-
cannonball color:
self.bullet_color = (105, 105, 105)
-
number of cannonballs that can be shoot at the same time (it wasn't so easy to load the cannon):
self.bullets_allowed = 3
-
pirates fleet vertical speed:
self.fleet_drop_speed = 20
-
probability (set as a value between 1 and 10) that position in pirates fleet is filled with a ship during fleet creation:
self.pirate_probability = 8
-
factor to increase fleet horizontal speed when the level changes:
self.speedup_scale = 1.1
-
factor to increase the score per pirates ship shoot down with the level change:
self.speedup_score = 1.5
-
horizontal speed of player's ship:
self.ship_speed = 2
-
vertical speed of player's bullets (negative as they are moving upwards):
self.bullet_speed = 2
These settings will change during the gameplay.
- horizontal speed of pirates ships:
self.pirate_speed = 0.75
- fleet's direction (changes when fleet reaches screen's boarder):
self.fleet_direction = 1
- initial points value for a pirate ship shoot down:
self.pirate_points = 20