Occasionally I start Googling random collections of words related to video games — more usually, video game jobs, hoping some golden ticket is going to fall right out of Mountain View or something. I often end up reading lots of forum threads and blog posts about the topic and how to make yourself seem attractive to studios etc etc, and it was within one of these little quests that I read an idea that nagged me, “Just make something … Tetris or something, just show you know what you’re doing.”
So a few days later I got up and made Tetris.
All told it was maybe 6-8 hours work split across two days: Mostly production, with the final couple of hours on day two dedicated to bug squashing. Anyway, it’s super simple but I think it’s kinda neat for what it is. As ever, this game is built with Haxe NME (3.5) – to compile the source you will also need the Actuate tween library installed. Download the source here.
How it works is pretty straightforward… Each shape is a class called BlockShape, which contains individual BaseBlocks. Collision checking is performed by each BaseBlock individually against its neighboring cells. To facilitate this, the guts of the code are in the GameScene where there’s a 2D array of BaseBlocks called _map – if a neighbour cell is null all is well, but if there’s a block there we’re potentially in trouble. BaseBlocks aren’t committed to _map until they’ve collided and stopped, at which point each row used by the shape is also checked to see if it’s full and thus needs removing (the 2D array approach also makes removing a row of blocks trivial.)
The core code is a very stripped out version of my current Tower Defence code: Only four of the 10-or-so Manager classes exist and I think at least two of them are so seldom used as to be easily discardable. It is nice to feel like I have some sort of reusable base though, even if most of the code I copied over is only to facilitate an unload() function on objects to release the memory.
I leave you with a few random screenshots from earlier in development just because I can… Until next time, adieu!