Skip to content

Quickly Coding an Animated Team Picker in pygame

  • by
Screenshot of window of team picker

Pick a team for me

I’ve been known to stream on Twitch, and one of the things I do is a wee informal monthly ‘competition’ to give subscribers something to root for and cheer on. For November’s outing I wanted to assign everyone a team, which is simple enough for me to do using random.org and a list; but there’s no glamour in that- I wanted something that people could see.

Being completely ignorant of what the standards are for doing such things — animation software? special production infographics software? — I decided to create something myself. Back in September I used Godot as my ‘canvas’, but it had been so long since I used that I realised I had lost of a my knowledge of the engine. This time around I wanted to use something in a language I was more familiar with: python. Enter pygame!

Being pressed for time, I whipped something together in a couple of hours, not-quite-hackathon-style. It’s not the fanciest, the code is hasty in parts, and there are additional features I would have liked to have added; but it got the job done and I was pleased with it.

Having to be quick also meant I needed to quickly focus on what I actually needed and wanted as a priority from the picker. I settled on:

  • be visually consistent with the other elements I was going to use for the stream
  • show teams and subscribers clearly
  • have a mechanism to pick one team at a time
  • visually indicate the process is random

There’s not a lot to it, but enough to spent a few hours bringing together. My main resources were the pygame docs and a flappy bird clone by russs123. Do note there are quite a few such clones; while I am grateful for the one I looked at there are other which might be more illuminating for the purposes of pedagogy (such as this clone by TimoWilken, discussed on the CodeReview Stack). Sometimes though all you need is an answer to the question “how do I do X” with an implicit (“because it needs to be done in the next fifteen minutes!”).

For anyone who is interested or for further pedagogy, my code is hosted on my own Gitea instance at present.

Tell us what's on your mind

Discover more from Rob's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading