After my “Building A Castle In Minecraft With Python” article I wanted to create a Minecraft game that was a bit more interactive. The “find a diamond” type game had already been done so I decided to do a slightly different version with a time limit.
“Operation Counterstrike” was born.
The script randomly places a number of TNT blocks around the map and the player has to find and destroy them all before the timers run out. As in my castle script you can dive in and start adjusting the Python code to change the game play or implement your own ideas.
Initial Setup
In order to make use of this script you will need have Minecraft installed on your Pi with the Python API ready to use. Follow these tutorials if in doubt :
Download Script
The game script needs to be placed into the directory created when setting up the API. In the API setup tutorial linked above I use /home/pi/mcpi-api. You can download the script directly to your Pi using using :
cd ~/mcpi-api wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/minecraft/counterstrike.py
Alternatively here is a link to the Python game script.
Running The Game
Launch Minecraft on the Pi and create a new world. To free the mouse cursor you can press the TAB key.
To run the game you will need to launch the script either from an LXTerminal window on the Pi or a command line on a remote machine that is connected to the Pi (i.e. using Putty).
Navigate to the API folder that you copied the script into and execute it.
cd ~/mcpi-api python counterstrike.py
Adding a number after the script will set the number of devices to generate. For example :
python counterstrike.py 7
will generate 7. If you do not specify a number the default is 3.
Playing The Game
Once the script is running you should see messages appear in your Minecraft window. You will be told how many devices are out there as well as status messages.
The devices are placed in random positions around the map. Devices on land will be buried under the surface whereas devices in water will rest on the sea-bed. Each device has a randomly generated timer ranging from 80 to 180 seconds.
The status updates will report the distance (R) to the nearest device and the lowest timer count (T). The nearest device may not always have the lowest count so you may have less time than you think to find the device that is about to explode!
When you destroy a device you will get bonus time added to all the remaining devices.
Find and destroy all the bombs before you run out of time!
PiFace Control & Display
One of my reasons for creating this script was to test my new PiFace Control & Display add-on. This allows you to easily add a 16×2 LCD screen to the Pi with switches. Within the script you will find 5 lines that relate to configuring the PiFace and outputting messages to it.
If you want to use one then remove the # symbol from the front of the following 5 lines :
#import pifacecad as pf ... #cad.lcd.clear() ... #cad.lcd.write(msg) ... #cad = pf.PiFaceCAD() #cad.lcd.backlight_on()
Have fun and happy hunting!
Possible Future Updates
- Remove all TNT blocks when player fails to find them so they aren’t left in world
- Place bonus blocks that give the player extra time or extra clues to TNT block positions
- Limit the maximum timer value due to bonuses
3 Comments
hmm, awesome, I just don’t understand what is the LCD used for? Just displaying the screen message? Coz we already had a screen ;P
The screen was just there for a bit of fun. I wanted to show beginners that you could combine hardware with your Minecraft creations and weren’t limited to the on-screen world.
You should make the tnt explode! You might be able to trigger an explosion at those coordinates, and change the default blast size. Make the world go boom!