U bekijkt momenteel de Netherlands versie van de site.
Wilt u overschakelen naar uw lokale site?
12 MIN LEESTIJD

PYGAME

Code your own Breakout retro game

Matt Holder discovers that writing a ’70s-style classic game isn’t as simple as he first thought.

Credit: www.pygame.org

OUR EXPERT

Matt Holder has worked in IT support for over a decade, and always tries to utilise Linux alongside the other installed systems.

QUICK TIP

Get all the code for the completed game from https:// github.com/ mattmole/ LXFPaddle Smash.

Being of a certain age, we were hooked by the original Breakout. It’s one of those incredibly B simple-looking games that can become really difficult. As a challenge, we’re going to recreate Breakout, but first let’s describe the gameplay and how subsequent versions added to the original. The player moves a paddle from left to right. This paddle stays in the same vertical position on the screen and is used to ensure a ball can be bounced back up the screen. Above the paddle is an array of bricks. When these bricks are hit by the ball, they disintegrate. A level is completed when all the bricks have been hit by the ball.

It is possible to make the game more difficult by speeding up the ball, making the paddle smaller and requiring some bricks to be hit more than once before they disintegrate.

We spent many hours on an Archimedes A5000 playing Fireball 2. This game has the same gameplay as Breakout, but with extra features, such as being able to collect power-ups that drop from the bricks and give extra powers, such as two balls at once, the paddle being able to fire lasers and the ball being able to break through bricks, rather than bouncing off them. There are also power-downs, such as reversing the left-right control of the paddle and speeding up the ball to such an extent that it is impossible to keep up.

The listing in this tutorial covers the basic ideas behind the game and partial listings of the necessary data structures. Commented code is available on GitHub (see Quick Tip, left), which can be downloaded and studied, before running and playing the game.

We are using Python and the excellent PyGame library to create our project. This allows games to be written that can be windowed or full-screen, and provides all the usual features, such as keyboard and mouse control functionality, sound, screen control and the ability to draw and move sprites on the screen.

Ontgrendel dit artikel en nog veel meer met
Je kunt genieten:
Geniet volledig van deze editie
Direct toegang tot 600+ titels
Duizenden oude edities
Geen contract of verplichting
ABONNEER NU
30 dagen proberen, dan gewoon €11,99 / maand. Op elk moment opzeggen. Alleen nieuwe abonnees.


Meer informatie
Pocketmags Plus
Pocketmags Plus

Dit artikel komt uit...


View Issues
Linux Format
September 2023
IN DE WINKEL BEKIJKEN

Andere artikelen in dit nummer


MEET THE TEAM
MEET THE TEAM
This issue, we’re getting AIs to badly develop ap plications for us. Hurrah! So, what are you going to do with all the spare time your personal AI is going to free up?
Not so smart
A rtificial intelligence is like any other tool
REGULARS AT A GLANCE
Newsdesk
THIS ISSUE: EU threat to open source Plasma features face chop Gnome opens window plans Debian embraces RISC-V
JUST BUGGIN’
Jon Masters is a kernel hacker who’s been
Kernel Watch
Jon Masters keeps up with all the latest happenings in the Linux kernel, so you don’t have to.
ONGOING DEVELOPMENT…
John Ogness posted Wire Up Nbcon Consoles, which
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to answers@linuxformat.com
Mailserver
WRITE TO US Do you have a
Hot Picks
Immich
ATTACK OF THE A.I. Pi BOTS
Fun artificial intelligence projects you can build and run at home on the cheapest of hobbyist hardware!
REVIEWS
BarraCuda 8TB HDD
Cheap and cheerful – that’s not how Shane Downing parties.
GeForce RTX 4060
A good graphics card with the wrong name, ponders Chris Szewczyk.
Murena Fairphone 4
Fairest of them all, Jonni Bidwell is excited by an ethical phone with a privacy-respecting operating system.
Peppermint OS
After years of sampling Linux Mint, Nate Drake opts for something spicier in the hybrid Peppermint OS, which integrates cloud-based apps.
Fatdog64 Linux 814
Nate Drake decides to look in on Fatdog, a Puppy-based OS that’s grown into a very credible canine in its own right.
ROUNDUP
Media-creation distros
Michael Reed examines five distributions, aimed at creative types, that come packed with applications, utilities and plugins.
Customisations & extra features
How much does each distro add?
Base distro and package repros
We need a strong foundation with access to the latest software.
Using the user interface
Creative flow is paramount.
System efficiency
It’s a shame if the distro starts gobbling up resources before you’ve even started.
Audio, music and plugins
Showcasing what Linux can do in this realm and saving installation effort.
Video and graphics apps
Ready-to-go drawing and painting applications are always welcome.
Documentation and support
Information on how to get things running and overcome difficulties.
The verdict
Media-creation distributions
A.I. CODING
Matt Holder spends some time discovering how AI, ML and LLM can be used to help us with our programming – and, yes, he explains what the acronyms mean as well…
Pi USER
Pi Foundation open sources its Code Editor
Accelerating feature development and generally doing the right thing all round, hurrah!
RP2040 ETH Mini Dev
Les Pounder loves all his Pi collection, but sometimes there’s some he simply can’t love as much…
Sonic Mini 8K S
Always on the lookout for upgrades, Denise Bertacchi doubly likes it when there’s a bargain, too.
Build a flashy dice roller with NeoPixels
Les Pounder is learning to multitask but we think he misunderstood the instructions.
Smart management for smart kiosks
Tam Hanna takes a look at how Ubuntu Frame harnesses Wayland’s strengths to make smart display management more comfortable.
TUTORIALS
Best kept secrets
A man who keeps his cards close to his chest, we struggled to persuade Shashank Sharma to reveal how he protects his passwords.
Upgrade your Steam Deck SSD
Neil Mohr asked hardcore PC gamers Tony Polanco and Katie Wickens to upgrade a Linux device – what could possibly go wrong?
Access services with Nginx reverse proxy
Nick Peers discovers how to open your network services to the internet with this user-friendly implementation of Nginx.
Add Raspberry Pi GPIO to your PC
PCs don’t offer a GPIO header like the Raspberry Pi, but Mike Bedford reveals that a low-cost add-on is all you need to join in the fun.
Render real-world 3D maps in Blender
Credit: www.blender.org
ADMINISTERIA
A ROCKY ROAD AHEAD?
Stuart Burns is a Linux administrator for a
Docker is dead, long live Docker
Docker has been the king of containers but could Podman put an end to Docker’s reign?
LXD gobbled up by Canonical
LXD ownership is transferred to Canonical in the hope of making great strides.
Who installed that?
Yum is more than just a way to install applications – it can do all sorts of interesting stuff.
HostPapa
Ruby P Jane tries this paternal web host provider that offers a range of services for both personal and business use.
Cloudways
A competent host offering scalable cloud-based solutions that has Ruby P Jane loving what she sees.
IN DEPTH
AWS vs Azure
What’s the difference? Not all cloud providers are the same. Steve Cassidy compares the two biggest platforms
CODING ACADEMY
Text adventure combat mechanics
Often found making love and not war, this month Nate Drake takes our interactive text adventure down a dark, violent path.
Creating Flutter apps
David Bolton shows how to set up a Flutter development environment on Linux and then how to build a simple calculator in Flutter.
Chat
X
Pocketmags ondersteuning