This friday I attended the first of hopefully many mini game jams at Volta Labs. The theme of the game jam was explosions. The time limit: a mere three hours. Building a working game in such a short amount of time is a lot of fun. For a recovering overthinker like myself it’s also a great exercise in rapid prototyping and not getting hung up on small details. Working so fast inevitably means that you’ll write some silly non-optimized code, but it can also lead to some clever quick solutions to problems you might have otherwise spent too much time one.
The game I wrote was a simple Bomberman clone. For those not familiar with Bomberman, the objective of the game is to explode your opponents and to not get exploded yourself. Your weapon is the ability to place bombs on the ground which explode after a few seconds in a signature cross shaped pattern. The battlefield is filled with destructible blocks which sometimes release powerups. The two basic powerups that I wanted to include in my game are one that increases the amount of bombs you can place, and one that increases the size of their explosions.
I’m pleased with the result of this game jam. I budgeted my time well and finished the game just before the deadline, including a last second bug fix and rebuild. I’m not going to write a detailed post mortem for such a simple game, but here are a few highlights:
Best Code I Wrote - The Bombs
One of the quirky things about Bomberman is that when you place a bomb it appears on the same tile you’re standing on, but once you exit that tile they block your path. I wasn’t originally going to include this feature in my clone because it seemed like sort of an odd thing to program. Then I got the idea of giving the bombs a
2DCollider component that was originally set to be a trigger, and use the
OnTriggerExit2D event to change it to a regular collider when the player exits that space. It worked exactly as I wanted it to on the very first try which is a rare and satisfying thing when experimenting with new code ideas.
I also got to use my favorite coding pattern, recursive functions, to make the cross-shaped explosions. The recursive explosion function checks the space adjacent to it in a particular direction. If the space is empty it calls itself on that space. If the space has a destructible block it destroys the block. By increasing the depth of recursion before the function collapses, I get the bigger-explosion powerup for free!
Silliest Code I Wrote - Player 2
My first goal was simply to get the game working with a single player. When that was finished and I realized I still had a bit of time left, I added a second player to make it into an actual game. The problem was that all the important game variables keeping track of things such as how many bombs you had placed were just global variables. I could’ve gone back and modified the functions to take a
player argument and keep separate variables for each player. That would’ve been the smart thing to do. It probably wouldn’t have even taken that long.
The thing that I did instead was to make a second instance of the entire game, minus the code that generated the level. So each player has it’s own copy of the entire
GameManager object including a bunch of redundant information! Anything goes in a 3 hour jam, right?
Head-On-Desk Moment - Decimal Points
The very first thing I did was create the game board. The board is a 2-dimensional array of integer values. To draw it, iterate over the array and use a dictionary object to fetch the corresponding game object for each integer. My lovely MSPaint graphics were 32 x 32 pixels each. So of course, for the position of each tile I multiplied the x and y coordinate of the array by a multiplier which I of course set to 32.
When I tested the game I saw a single tile in the middle of the screen. After some frustrated troubleshooting of code that looked perfectly fine - “how can the game be broken already I’ve barely written anything?” - I remembered that 32 Unity units != 32 pixels. My code was working just fine, it’s just that the tiles were one hundred times further apart than they ought to be, and thus only the one at [0, 0] was visible on the screen.