Clones of the original TETRIS Arcade game created by TEAM TETRIS in 1988. The game is not an exact copy of the old TETRIS but shares the same concept created by Alexey Pajitnov in it's good old days. To add a little more emotion to the game, I added a new game mode. Tetris is an old game, but you can play it by installing it here. But this tetris is not simple, it's a Christmas version. Game engine: MonoGame; Plarforms: x86 or x64 Windows(7 and later), Linux.
Kindly hosted by
Tetris Tutorial: Part #5
Hello there and welcome to the fifth tutorial on how to make a decent Tetris game!
In this tutorial we will be going into some intricates of the block animations.
Warning: this is a long tutorial, so take your time reading it by parts or over again.
OK, let’s start.
Let’s take a look at a class CAnimation. It’s a template class where the passed template attribute is used as an array for custom frame data. For example, if we want each frame to refer to textureID in Textures database, we declare animation as:CAnimation<int> m_Animation;
Why as an ‘int’? Simply because textureID is an integer (or it can be an unsigned integer).
OK, moving on, we take a look into details of CAnimation class:
The only interesting thing in this class would be the Animate() function, because other procedures deals only with resetting and get/setting member variables:
The overall design is pretty simple: run the animation that many frames (and that many loops) until it has finished. Not so simple in code, but yet more to come… ?
OK, let’s add member variables for block animations,
and their get/set functions accordingly. The tAnimationFrame is a structure consisting of:
I will not go into details of CTextureManager and CMaterialManager, because those are simply wrappers around dynamic arrays they control, that also acts as databases – e.g retrieval by uid, filename or index (or more). I will say only one thing: I’ve checked them and so far they’ve proven themselves as a good measure against duplicates of materials/textures.
You can take a look at tMaterial/tTexture structures, but they are very basic (except loading functions). You can load materials from file they are stored in, or add copies of materials/textures that are already in database but with modified attributes. Note that textures can have an alpha channel which you can specify by using ‘Mask’ RGB attribute of <Texture> tag:
Right now we cannot use sub-rectangles to map parts of same texture to different frames, so we are going to use separate files as frames.
OK, let’s add some textures/materials we’re going to use with our game:
Up to material 10 (we could use 1 material and 1 texture if we could refer to sub-rectangle of the single texture file!)
OK, so far so good? Let’s now take a look at XML file containing our game data. You probably remember the size of it last tutorial, so you will be surprised now:
See, each block now has a list of animations! Please note that I didn’t put whole file here because it is too big, but the basic thing here is that EACH block will have those 3 animations! Each block in each figure! It’s not so hard to add those lines in, so let’s do it..
(Adding those lines takes time, so take your time :) )
OK, now onto the actual animations and their loading. We have 3 animations:
Block' default animation, when there’s NO animation (it sounds weird, but it’s easier to do texturing this way than adding a new variable for a texture):
Block’s default animation where it is going to.. um.. shine or flash, or whatever you can draw in animation package – you will have to expand it according to your new files for each frame (or sub-rectangles for one file) – same as above:
And finally our block’ disappearing animation – when a line is full we play this animation once (or twice, or how many times you want):
So, we’re done with our animations representations in XML file, let’s take a look at how we are going to load and use this data.
Since a user can declare ‘class T’ in class CAnimation as whatever he wants to, he’s going to have a separate functions for loading different types of data, as in here:
To load this one, he must declare and implement the following function:
int LoadAnimation(CAnimation<MyCustomData> *animation, TiXmlNode *this_node, char *filename);
So, to load our animation of type:
CAnimation<tAnimationFrame> *m_pAnimations;
We have to:
So, let’s take a look at how we’re going to do part 1: CTetrisBlock::LoadFromFile()
OK, we counted and called functions to load each animation, let’s see what does LoadAnimation() function holds:Also, to actually draw our quad(block) with texture/material, we have to modify our drawing function and add a pointer to current material (see TetrisBlock.h class):
Well, well, well… So far so good? Now let’s take a look at CTetrisBlock::Animate() function that will handle block’ animations. It is very simple:
Well. Now… What do we need now? Oh yeah, the AnimateLine() function of CTetrisGame. I’ve added more candy to it, so that our blocks will animate in order take a look for yourself).Well, here we go:
OK, what do we got left? Nothing! And that what you should be proud of – now you have a full tetris game (without scores or background) with animations and XML data files!
In Tutorial 6 we will go into bonuses and their animations/actions. See ya later!
Tetris# is an open-source multiplayer tetris clone written in C#. It will use the .NET Framework and Managed DirectX 9.0 as its base. Being a modern clone, it will feature high quality graphics and sound effects. It will support both single player and multiplayer action. Multiplayer games will be direct IP-to-IP or through selection of a game from a master game server list.
The game is being developed by members from around the world. Here is a list of currently active project members:
If you would like to join the team, please contact the project lead here.
The game is currently in development. There is a very basic single player client that supports regular tetris gameplay.
Some screenshots of the early development versions of the game can be found here.
You can download or view the source code through the project's CVS repository. Project CVS information can be viewed here.
You can download pre-compiled binaries (which require the .NET Framework and DirectX 9.0, including managed extensions) here.
If you want to talk with the development team for any reason, feel free to post on the open discussion forum here.