Contra Game Using Python with Source Code using Pygame
Introduction:
Remember the super fun Contra game where you fight aliens and jump through crazy levels? Well, guess what? You can make your own version of it using Python! Yup, Python can do some cool stuff with a library called Pygame.
In this blog, I’ll show you how to make your very own Contra game step by step. Don’t worry if you’re new to programming – I’ll keep it simple and easy to understand.
And guess what? I’ll give you all the code you need! So, you can play around with it, change things up, and make your own version of Contra. It’s going to be awesome!
So, let’s get started! Grab your computer, open up Python, and let’s make some gaming magic happen!
Game Instructions:
Controls:
- A: Move Left
- D: Move Right
- S: Drop to a lower platform
- R: Quick restart
- SPACE: Jump
- Left Mouse Button: Shoots in the direction determined by the mouse position
- Right Mouse Button: Dash
- Mouse Move: Direction of shooting
Powerups:
- F: Resets cooldown of Dash
- B: +1 Health
- Bird: (Powerdown) Causes the player to drop down if taken when on a platform
Rules:
- Get to the end of the Level and defeat the bot tanks
- You will die if you lose all your health
- Each bullet hit will decrease your Health by 1
- Hitting an enemy unit will instantly kill you
Notes on mechanics:
- Running soldiers will be difficult to see underwater. (Only their head is visible)
- Jump, Right, and Dash for longer distance
- The bird powerup will trigger only if you are walking on a platform while activating. Hence jumping directly on top of the powerup will not activate as you are not on a platform. This can be used to prevent unwanted drops to death
- Trying to drop when on water will cause you to drown and die!!
- Direction of shooting is determined by the mouse position. Mouse above/below the player shoots a bullet at an angle of +/- 45 degrees from the ground.
- Right Mouse Button activates Dash when it is out of cooldown. Its cooldown is depicted in the top center of the screen. Use this ability to cross broken bridges, for example.
- A random powerup drops in front of the player every 2 seconds. If it goes out of the screen behind the player, it disappears.
- Snipers shoot only when the player is in front of them.
- Soldiers who run across the screen are generated randomly every 3 seconds in front of the player.
- All global settings are present in the ‘settings.py’. They can be changed by the player to make the game more challenging.
How to run the source Code:
To run the code, you’ll need Python 3 and pip installed on your system. Follow these steps:
Open your command line interface (Terminal on macOS/Linux or Command Prompt on Windows).
Navigate to the directory where the code files are located.
Install the required dependencies by running the following command
pip install -r requirements.txt
- Once the dependencies are installed, you can start the game by running:
python main.py
- If you want to start the game in fullscreen mode, you can pass the “-f” argument like this:
python main.py -f
Required modules:
- certifi==2019.6.16
- pipenv==2018.11.26
- pygame==1.9.6
- virtualenv==16.7.2
- virtualenv-clone==0.5.3
- Information: Certifi provides Mozilla’s CA Bundle.
- Usage: It’s commonly used in Python projects to handle SSL certificate verification.
- Information: Pipenv is a dependency manager for Python projects.
- Usage: It simplifies the process of managing project dependencies and virtual environments.
- Information: Pygame is a set of Python modules designed for writing video games.
- Usage: It’s extensively used for game development, providing functions for graphics, sound, and input handling.
- Information: Virtualenv is a tool used to create isolated Python environments.
- Usage: It’s commonly used to keep project dependencies separated and to avoid conflicts between different projects’ dependencies.
- Information: Virtualenv-clone is a tool to clone virtual environments.
- Usage: It’s useful when you want to replicate an existing virtual environment for another project, saving time on reinstalling dependencies.
Make sure you have Python 3 installed and that pip is configured correctly. Then, follow the steps above to run the game successfully. Enjoy!
Source Code:
Output:
More Projects:
Bank Management System Using Python Django
Bank Management System Using Python Django Introduction The Bank Management System V2.0.2 is a feature-rich online banking solution built using the Python Django web framework.
Pharmacy Management System Using Python Django
Pharmacy Management System Using Python Django Introduction The Pharmacy Dispensing Management System is a robust and user-friendly software solution developed using Python and the Django
Number Guessing Game Using HTML CSS And JavaScript
Build a Quiz Game Using HTML CSS and JavaScript Introduction Hello coders, you might have played various games, but were you aware that you can
Emoji Catcher Game Using HTML CSS and JavaScript
Emoji Catcher Game Using HTML CSS and JavaScript Introduction Hello Coders, Welcome to another new blog. In this article we’ve made a emoji catcher game.
Typing Challenge Using HTML CSS and JavaScript with complete source code
Typing Challenge Using HTML CSS and JavaScript Introduction Hello friends, all you developer friends are welcome to our new project. If you are also new
Breakout Game Using HTML CSS and JavaScript With Source Code
Breakout Game Using HTML CSS and JavaScript With Source Code Introduction Hello friends, welcome to today’s new blog post. All of you are welcome. Today