Blow bubbles and burst them in our tribute to an arcade classic. In the latest issue of Wireframe magazine, Mark Vanstone shares the code.
Released in 1986, Bubble Bobble looked quite unlike any other game available in arcades at the time. Designed by Taito’s Fukio Mitsuji, it was a cooperative game in which two players took control of a pair of dragons, Bub and Bob, and blew bubbles to trap enemies, which in turn could then be popped. This nobbled the enemy inside and released bonus items which could be collected for extra points. Unlike the various shooting, driving, and fighting games at the time, Bubble Bobble was a cartoon-like game with a broad appeal; Mitsuji said in later interviews that he wanted the game to be enjoyed by couples. Maybe this is partly why Bubble Bobble was a big hit for Taito, and remains one of its most widely ported and fondly remembered games of the 1980s.
For our Pygame Zero sample this month, we’ll concentrate on the game’s bubble mechanics and see how we can fire them, push them around, and pop them as they float around the level. To start with, we’ll need a set of platforms for our little dragon to run around on. We’ll keep it simple for this example and have a border of walls and three levels of platform that we can define with a simple nested loop. Each of the platform blocks are Actors which we put into a list before we start the main program. Our
draw() function is quite simple, drawing our background, then the platforms, our bubbles, and finally Bub, our little dragon.
To move Bub around, we can detect the arrow keys in the
update() function. We cycle through three frames to make him walk along the platforms and then apply some gravity to him so that if he walks off the end, he’ll fall down to the next level. To get Bub jumping, we use the on_
key_down() function and test to see if he’s on the ground, and if so, set the Bub Actor property ‘jump’ to 60, which will set off upward motion for 60 frames – at which point Bub will start falling back down as our gravity check takes over again.
Now for the bubbles
Now for the bubbles. We detect the
SPACE bar being pressed, create a new bubble, and add it to a list. To start with, it will fly out horizontally in the direction Bub is facing. We can check how far it has travelled with the status property of the new bubble. After the status property reaches zero, we stop the bubble moving horizontally and let it rise upwards using the
drifty properties. We can change these properties at random to give the bubble a bit more of an uncertain direction. We can also reverse the properties to make the bubble bounce off the side and top walls. We check all the bubbles each frame to make sure they aren’t colliding with any other bubbles, too.
We’ll also want to check for collision between Bub and any bubbles. If he runs into a bubble, we want him to push the bubble along, but if he jumps and hits the bubble with his spikes, the bubble will pop. There’s also a timer property on the bubbles that means after a while the bubble will burst by itself. So that’s the basics of the bubbles – you may want to add some monsters and goodies for Bub to collect, or perhaps make the platforms more complicated. As always, we’ll leave that for you to work out.
Get your copy of Wireframe issue 56
And if you’d like a handy digital version of the magazine, you can also download issue 56 for free in PDF format.