I’ve been itching to start Tetris for a while, and since the Snake codebase is in a reasonable state, it’s time to have a stab at implementing this archetypal puzzle game. The first step was to clone the Snake project and then recommit as a new git repository. I then cleared out all of the Snake specific bits which left me with just the basic drawing and coordinate system. However, I realised that there were some domain-specific peculiarities to parts of the coordinate system which I’ll have to work out.
Lana chose the palette for this a while ago, opting this time for a set of brighter, higher contrast colours and once the basic project compiled, I fitted the new palette in and updated the start screen. I also experimented with drawing bordered rectangles for this, as I’ll be wanting to use several of these in the gameplay layout. The character map that Lana designed was carried straight over and is definitely appropriate considering how retro the original game is.
Wanting to get into the gameplay coding as soon as possible I needed a UI for it. Snake had been massively simple as the only things that were ever drawn on screen during gameplay were the snake, a single pickup and the pause symbol. Tetris will involve UI elements that will delineate the gameplay field and also give the player information - for example score and next shape. I did a rubbish sketch of what I wanted the gameplay UI to look like and then got stuck straight into putting it together and fairly quickly the sketch:
The most difficult part was finding paper to sketch on, as I seem to have completely forsaken the stuff these days. As I coded, I refactored the drawing coordinate system as well as overloading some of the text and shape drawing functionality from Snake to allow for colours and positioning. The end result leaves me in a pretty good position after an evening of work, and I want to start with the gameplay next.
As I’m very new to C++, I haven’t been paying due care and attention to memory management. I know this is going to bite me soon as I’m instantiating more and more objects without really doing any manual garbage collection, so another task high on the to do list is to go through what I’ve got so far and make sure all pointers are correctly cleaned up. I also need to investigate profiling tools.