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

Adding gamepad support to Tetris

Andrew Smith likes nothing better than fitting oddly shaped blocks into oddly shaped holes, and a gamepad makes that much easier…

OUR EXPERT

Andrew Smith is a software developer at NHS Digital, and has qualifications in software engineering and computer networking.

T his month, we going to look at a Tetris project that’s been written in Python, and then add code to support an Xbox One controller. In theory, the code should work with other PC-based compatible controllers, but they’ve not been tested for this tutorial and so may require some adjustments and configuration changes. Your millage may vary!

Before starting this tutorial, we advise plugging your game controller (if you have one) into your computer and making sure that it works with your distro of Linux (we’re using Ubuntu). This tutorial is based on a Tetris project originally created by Luke Arnston – see www.pygame.org/project/133/166.

Tetris, a graphical puzzle game first created in 1984 by Alexey Pajitnov, it has since become available on multiple platforms and implemented using a range of programming languages. One of the most popular platforms that this video game was available on was the Nintendo Game Boy, which was released in the late 80s/early 90s. The Game Boy was a relatively cheap, hand-held device that could be easily packed away and taken and played anywhere.

Tetris involves players creating lines from shapes (Tetronimoes) that descend gradually into the game playing area. These shapes can also be manipulated (moved left to right and rotated) to fit in with other shapes to create a complete line. Once a complete line is created, the line then disappears and the player is awarded points. The game ends when new shapes generated can not descend into the game playing area. The game is deceptively simple to play, and can become maddeningly addictive.

This screenshot shows a successful installation of Python and PyGame, as an example from a previous Linux Format tutorial.

Installation and setup

We’ll install and setup Python 3.10 for the benefit of this tutorial. For those readers who have Python/PyGame already installed, Python 3.8+ should be fine to use with this tutorial. Type the following to install Python 3.10 and PyGame:

Check your versions of python and pygame. Next, git clone from repository: $ git clone https://github.com/asmith1979/lxf292_tetris/

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
Summer 2022
IN DE WINKEL BEKIJKEN

Andere artikelen in dit nummer


WELCOME
MEET THE TEAM
This issue we’re diving into the kernel’s graphic
New world order!
It can feel like desktop Linux users are
REGULARS AT A GLANCE
The complete history of Unix commits
Want to feel old? A project on GitHub gathers together over 50 years of Unix commits for your delectation
AMD FidelityFX Super Resolution goes open source
AMD’s performance-enhancing upscaling technology is now open source with version 2.0.
HP launches Linux laptop
HP Dev One comes with Linux Pop!_OS preinstalled.
SEE YOU IN VALHALL!
Alyssa Rosenzweig is a software engineer at Collabora.
CRITICAL THINKING
Keith Edmunds is MD of Tiger Computing Ltd,
Microsoft gives Gnome a boost
Thanks to Microsoft staff and its FOSS Fund.
Ubuntu Touch OTA-23 released
Supported devices getting the Ubuntu release for mobiles.
Thunderbird 102 now available
Big update for the open source email client.
Distro watch
What’s down the side of the free software sofa?
THANKS ADMINS!
Matt Yonkovit is the head of open source
GO RUST!
Jon Masters is a kernel hacker who’s been
Kernel Watch
Jon Masters summarises the latest happenings in the Linux kernel, so that you don’t have to.
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to lxf.answers@futurenet.com
Mailserver
Is there a lowlatency kernel for the Jellyfish?
LETTER OF THE MONTH
We’re not sure this is a punishment or
Mayank Sharma
After being given an offer he couldn’t refuse,
Speek
Version: 1.6.0 Web: https://speek.network S peek
zuluCrypt
Version: 6.1.0 Web :https:// mhogomchungu.github.io/zuluCrypt/ Use zuluCrypt
Bpytop
Version: 1.0.68 Web: https://github . com/aristocratos/bpytop You
Converseen
Version: 0.9.9.5 Web: https:// converseen.fasterland.net Besides
SYSTEM PROFILER inxi
Version: 3.3.16 Web: https://github . com/smxi/inxi While
Qrencode
Version: 4.1.1 Web: https://fukuchi.org/ works/qrencode Remember that
Espanso
Version: 2.1.5-beta Web: https://espanso.org Espanso has some
nudoku
Version: 2.1.0 Web: https://github.com/jubalh/nudoku If you
Powder Toy
Version: 96.2 Web: https://powdertoy.co.uk It might not
Cerebro
Version: 0.5.0 Web: https://cerebroapp.com While Cerebro is
Flatseal
Version: 1.8.0 Web: https://github.com/ tchx84/flatseal While most
CODE, SCRIPT AUTOMATE!
Make your Linux life easier with hacks, scripts and coding secrets to automate your world.
LINUX Format
The #1 open source mag Future Publishing Limited,
REVIEWS
Backblaze B2
A simple pricing model makes it easy to migrate to, says Jonas DeMuro.
Intel Core i3-12100
A lowly quad-core serves up big performance gains, finds Paul Alcorn.
GeckoLinux Static 153
Michael Reed takes a close look at GeckoLinux, a distro with a wide variety of editions that puts a friendly face on openSUSE.
MakuluLinux Shift
Michael Reed is wowed by the visual bling of MakuluLinux, a distro that claims to be ‘game ready’ thanks to its many pre-installed components.
EasyOS 4.2
Michael Reed tries a Linux distribution that’s suitable for extremely limited hardware, and finds that it breaks with conventions in some areas.
Inscryption
We’re not trapped in here with The Management, they’re trapped in here with Jody Macgregor. And that’s just the way we like it.
ROUNDUP
Software whiteboards
If you’re starting a project you’ll need to take notes, possibly for presentation down the line. Mats Tage Axelsson helps you to organise your thoughts.
Installation options
How you choose to install will make a difference when you want to upgrade.
Whiteboard or notepad?
Do you need to take notes or capture your audience’s attention?
Day-to-day usability
Choose a program to meet your needs.
File export and import options
Combining files for pleasing visuals requires more than one file format.
Variety of modules
Tools that can visualise objects are invaluable for demonstrating concepts.
Development maturity
To evaluate these packages we need to know how far along the project is.
Making live presentations
Use these programs to create a presentation or interactive discussion.
The Verdict
Software whiteboards
HACK YOUR GRAPHICS
Join pixel-eyed Jonni Bidwell on a quest to demystify the world of graphics on Linux.
In the beginning…
Linux still talks to LCD monitors via a CRT controller interface. Find out where that came from!
Into a third dimension
We add some depth to the story and learn about the first, bona fide, GPU.
MESA TODAY
OpenGL remains the biggest API supported by Mesa
Querying your 3D stack
Intel’s numbering systems make no sense, but whatever your card there’s plenty of demos to play with…
Hack your graphics
Switch drivers, interrogate GPU memory, try and keep the magic smoke from escaping into the atmosphere…
Of GPUs and APIs…
And leave us nought but grief and pain… isn’t thankfully something Linux users have to experience these days!
Pi USER
DOING MORE WITH LESS
Les Pounder works with groups such as the
Raspberry Pi Pico W
Solid hardware, good software and Wi-Fi access see this incremental update elevate the Pico to a truly versatile dev board – just how Les Pounder likes it!
Adding distance sensors to projects
Les Pounder merges two low-cost, yet complex ultrasonic sensors to create one must-have Pi-powered gadget that anyone can use.
Build light shows with multi-coloured LEDs
Use WLED firmware and a string of LEDs to create eye-catching light shows to display around your home, with Matthew Holder.
Build a “rubber ducky” device from a Pi Pico
Discover why the classic fake keyboard hacking device is ideal for the Raspberry Pi Pico and Matthew Holder’s very particular set of skills…
IN DEPTH
LOCAL LINUX FOR LOCAL USERS
You’re not from around here, says Aaron Peters but that’s fine! As he’s here to explain how your distro of choice gets to work in any language.
TUTORIALS
Feature-rich music players for minimalists
Simplicity, elegance, usefulness and sheer fun are all qualities that describe Shashank Sharma. They’re also features he values most in applications.
Enhance your photos quickly and easily
Nick Peers tracks down an image editor that strikes the right balance of features and user-friendliness for making quick-fire edits.
Relive the classic ARM-based RISC OS
RISC OS is an operating system with a fascinating history that dates back decades. Michael Reed tries it out in its current incarnation.
GIMP batch processing
Tackling mass image processing is a walk in the park when you have Karsten Günther on your side and BIMP installed alongside GIMP.
Using WordPress with OnlyOffice
With OnlyOffice Docs connected to WordPress, authors are able to insert documents into online posts. Kseniya Fedoruk explains how it works.
Online reproducible dev environments
Stuart Burns is your guide to Gitpod, a new ‘work from anywhere’ development platform that could revolutionise test environments.
Host your own secure VPS-based WireGuard
David Rutland takes the LXF VPS server for a final spin. This month, he’s protecting his privacy and watching Mexican TV with a self-hosted VPN.
TOP OF THE FOSS!
AWOOGA, AMIGA
Jonni Bidwell’s desk has become a retro gaming station, thanks to Dimitris Panokostas and his Amiberry emulator.
CODING ACADEMY
How to develop multi-threaded code
Mihalis Tsoukalos explains all you need to know about Rust and concurrency so you can assemble efficient multi-threaded tools.
Chat
X
Pocketmags ondersteuning