IT
  
Attualmente si sta visualizzando la versione Italy del sito.
Volete passare al vostro sito locale?
13 TEMPO DI LETTURA MIN

PYTHON

Recreating the classic Bomberman

When we said “go out with a bang”, Andrew Smith took it to heart and decided to blow more than just the blinking doors off!

OUR EXPERT

Andrew Smith works as a developer for NHS Digital when he’s not updating ancient gaming code.

Grab the code for this tutorial with: git clone https:// github.com/ asmith1979/ lxf299_ bomberman/

Bomberman, developed by Hudson Soft in 1983 and currently owned by Kanomi, is a game in which a player has to eliminate every other player on the game grid to win. We’re looking at a clone of Bomberman created by Michal Sliva and Tomas Novak, the source code of which has been adapted for the benefit of this tutorial. The original source code for the project can be retrieved from https://github.com/Forestf90/Bomberman.

On a clean dev system, we need to install and set up Python 3.10. If you already have Python and PyGame installed, Python 3.8+ should be a good enough version to use with this tutorial. Type the following to install Python 3.10 and PyGame: $ sudo apt-get update $ sudo apt-get install python3.10 $ sudo apt-get install python3-pip $ python3.10 -m pip install pygame

To make sure you are calling the correct Pip version, check in the Scripts folder of the Python installation folder. There may be a version number of Pip to use – Pip 3.8, for example.

Check the Python version and PyGame version, then Git clone from the repository: $ git clone https://github.com/asmith1979/lxf299_ bomberman/

The source code and project can also be retrieved from the Linux Format archive. This tutorial focuses on the source code located in the folder called lxf299_ bomberman, so if not already in that folder, type $ cd lxf299_bomberman to get into the folder and gain access to the Python source code.

Game project

In the root of the lxf299_bomberman folder, there exist some of the Python files we will be looking at in more detail as part of this tutorial, including menu.py, game.py, enemy.py and player.py. Also in the folder is a folder called images, which stores all the images that are used in the game. The files are:

menu.py– contains all code for the mouse-driven menu system.

A successful clone from the project repository. Once cloned, all the files are present, ready to view or edit.

DEPTH-FIRST SEARCH

Depth-first search (DFS) is an algorithm for searching or traversing through graph and tree data structures. In the context of this game project, the algorithm is used to help an enemy character choose what action to take depending on the current situation. On each level of the map, various actions are attempted, such as:

• Place a bomb + move down

Sometimes these moves may not be possible because of a box crate, bomb or explosion nearby, so another move by the enemy character may be taken instead. The enemy character is placed in a corner of the game grid, allowing analysis of the row of the grid they are situated in. The code for the depth-first search algorithm is located in the Enemy class implemented in enemy.py, mainly in the methods dfs and dfs_rec. The move that the DFS enemy character chooses to undertake is mainly based on the content outlay of the map – for example, where the box crates, bombs, explosions and other enemy characters are placed on the map. In the Python script file menu.py, there is a boolean variable called show_path that by default is set to True. While this is true, the path of the enemy character is shown that the enemy character will travel along.

Sbloccate questo articolo e molto altro con
Si può godere di:
Godetevi questa edizione per intero
Accesso immediato a oltre 600 titoli
Migliaia di numeri arretrati
Nessun contratto o impegno
Prova per €1.09
ABBONATI ORA
30 giorni di accesso, poi solo €11,99 / mese. Disdetta in qualsiasi momento. Solo per i nuovi abbonati.


Per saperne di più
Pocketmags Plus
Pocketmags Plus

Questo articolo è...


View Issues
Linux Format
March 2023
VISUALIZZA IN NEGOZIO

Altri articoli in questo numero


WELCOME
Right to repair
When work was insisting on twofactor authentication for
REGULARS AT A GLANCE
Valve driving Linux open source development
Gaming giant has approached the open source community to enhance graphics support and compatibility of Steam Deck and SteamOS.
Killing Google Maps
Four tech giants ally with the Linux Foundation to source open map data.
Cooler Master to go open source?
MasterPlus+ to get cool open source overhaul.
THE ART OF AI
Donnie Berkholz is senior vice president, Product, at
FOLLOW ME!
Keith Edmonds is MD of Tiger Computing, which
Debian kicks out Py thon 2
The sun has finally set on Python 2 for Debian.
Google to add RISC-V suppor t
Android could turn to open source ARM alternative.
Vulkan Video
VIDEO Khronos finalises Vulkan video extensions. I nApril
Distro watch
What’s behind the free software sofa?
WINE ON WAYLAND
Alexandros Frantzis is a senior software engineer at
HI, 2023!
Jon Masters is a kernel hacker who’s been
Kernel Watch
Jon Masters keeps an eye out for all the latest happenings in the Linux kernel, so you don’t have to.
»ONGOING DEVELOPMENT
A lengthy thread was started last autumn titled
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to answers@linuxformat.com
Mailserver
Did we get too distracted by the shiny
HotPicks
THE BEST NEW OPEN SOURCE SOF T WARE ON THE PLANET
Fotoxx
Version: 22.50 Web: https:// kornelix.net/fotoxx/fotoxx.html
Saber
Version: 0.4.3 Web: https://github . com/adil192/saber
Upscayl
Version: 1.5.5 Web: https://upscayl.github.io
LibreWolf
Version: 108 Web: https://librewolf.net
Mprocs
Version: 0.6.4 Web: https://github . com/pvolok/mprocs
Junction
Version: 1.6 Web: https://github.com/ sonnyp/Junction
Myuzi
Version: 1.13.3 Web: https://gitlab . com/zehkira/myuzi
Libre TrainSim
Version: 0.8 Web: www.libretrainsim.org
Infinite Shooter
Version: 0.4.3 Web: https:// pastthepixels.itch.io/infiniteshooter
OTPClient
Version: 3.0.0 Web: https://github . com/paolostivanin/OTPClient
HydraPaper
Version: 3.3.1 Web: https://hydrapaper.gabmus.org
REVIEWS
Kingston NV2
Cheap but not cheerful, bemoans Shane Downing.
AMD Ryzen 7950X
Dave James pens these words and takes complete blame for saying: Zen 4 and the art of CPU maintenance.
Rocky 9.1
Nate Drake goes head to head with Red Hat-based distros this month, so is glad to have the heavyweight Rocky in his corner.
Linux Mint 2 1.1 Vera
Nate Drake meets Linux Mint’s latest offering, code-named Vera, and comes away bowled over by its stunning looks and ease of use.
Return to Monkey Island
The Management thinks three decades is a perfectly fine amount of time for Will Freeman to wait to get an under-inflation pay rise.
ROUNDUP
Packaging formats
There’s a number of ways of getting software on to your Linux-powered computer, and Michael Reed is comparing them to find out which is best.
Basic tools and utilities
A robust feature set is top of our list.
Portability of your packages
Are packages fixed to one distro?
Repositories and shops
Locating and adding apps from the GUI.
Sandboxing and system separation
Can you protect your system from a misbehaving program?
System integration
We want an installed app to fit in with the rest of the user experience.
Component installation
How easy is it to install components?
Other pros and cons
Any features that stand out?
The Verdict
Packaging formats
FREE YOUR PHONE!
Lesser-spotted Jonni Bidwell climbs to the top of a 5G mast to extol the benefits of running Linux on your phone.
The issue with Android
Android is a hodge-podge of free and proprietary components.
Jump to LineageOS
Enjoy fully featured Android without all the proprietary bits.
Get to know LineageOS
We take a quick tour of the latest OS to power your mobile device.
Install GNU/Linux
Touch base with Ubuntu Touch or branch out into PostmarketOS.
Open source apps
Get into the F-Droid store and find fun and functional tools (that don’t send all your data Borg-wards).
Pi USER
Millions and millions of RP2040s!
How to turn 500 tasty wafers into 10 million Pis! Is everything food related around here?
More Pis in store
Unfortunately, we’re talking bricks and mortar, not silicon.
SAY CHEESE!
Les Pounder works with groups such as the
Arduino 2.0.3
The Arduino IDE, used by makers and hackers
Pi Camera Module v3
The latest version of Pi’s mainstream camera module has autofocus, HDR and wide angle, proclaims Les Pounder!
Pico GPIO control with JavaScript
Les Pounder strays from Python to show us that JavaScript, the language of the web, is a viable Pico alternative.
Add and monitor control sensors
Making sense of the situation, Les Pounder shows us how to use sensors with a robot to get about town!
TOP OF THE FOSS!
No changes allowed!
Matt Holder explores immutable operating systems, containerised apps and containers to see if they describe the future of the Linux distro.
TUTORIALS
Super system monitor
No sniggering at the back as Shashank Sharma shows you his bottom.
Batch convert and optimise your images
Nick Peers reveals how to quickly apply the same changes to multiple images at once with the simple-to-configure Converseen.
Giving praise to the TempleOS
Michael Reed delves into one of the most unusual operating systems he’s ever seen and explores the story behind its creation.
Using enhanced layer features with G’MIC
Karsten Günther takes a look beyond GIMP’s standard layer functions. Besides special GIMP operations, tasks provided by G’MIC loom into view.
Getting creative with algorithmic art
Mike Bedford demonstrates how you can exercise your left and right brain simultaneously by generating algorithmic art.
Making Git so easy, we say it’s Magit!
Aaron Peters uses the Emacs Git client Magit to perform a long overdue update of his LXF repository.
IN DEPTH
Deck the hardware
We revisit and trick out the Valve Steam Deck a year on from release.
CODING ACADEMY
How to trace code directly with eBPF
Mihalis Tsoukalos explains how to take advantage of eBFP with a range of different programming languages.
Chat
X
Supporto Pocketmags