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:
Complain Management using Python With a Graphical User Interface (GUI)
Complain Management using Python with a Graphical User Interface (GUI) Introduction: The Complain Management using Python program designed to manage complaints effectively within an organization.
COVID 19 Hospital Management Using Python | Covid 19 Hospital management using Django Graphical User Interface covid 19 hospital management django
COVID 19 Hospital Management Using Python [Django Framework] Introduction: The COVID-19 Hospital Management is a Python-based application that tracks web applications for Hospitals. This project helps
Drawing Ganesha Using Python Turtle Graphics [Drawing Ganpati Using Python]
Drawing Ganesha Using Python Turtle Graphics[Drawing Ganapati Using Python] Introduction In this blog post, we will learn how to draw Lord Ganesha using Python! We’ll
Contact Management System In PYTHON with complete source code
Contact Management System in Python with a Graphical User Interface (GUI) Introduction: The Contact Management System is a Python-based application designed to manage and organize
KBC Game Using Python With Source Code
KBC Game using Python with Source Code Introduction : Welcome to this blog post on building a “Kaun Banega Crorepati” (KBC) game using Python! This
Basic Logging System in C++ With Source Code
Basic Logging System in C++ With Source Code Introduction : It is one of the most important practices in software development. Logging is immensely helpful