|
|
| I often see people asking "How to make Tetris?" or "how should I start my first game?" Well, here's a short and sweet lesson on making a simple Tetris clone. No fancy stuff this time, just the basics.
This mini-tutorial is strictly for C++. I'll assume at least basic familiarization. You must create this project as a Win32 Application project. It includes only three files, main.cpp, bitmapobject.cpp, and bitmapobject.h.
In main.cpp:
That's all you need to start off. Next, let's include some handy-dandy defines that makes editing your program a thousand times easier. Seriously.
That takes care of Windows. Now let's think ahead. What should we use if we're going to make a tetris clone? Hmm... well, seems to me map tiles would work perfectly! Let's make a size for each tile, then make a size for the map, PLUS an 8-block wide sidebar.
Easy! Now, let's have some (you can use enumerations if you prefer) variables for the future bitmap. We need 9 colors, and 1 Does Not Draw, so 10 in all.
Alright, that's done. Let's do some function prototypes. We will need Game Init, Game Loop, Game Done, Draw Tile, Draw Map, New Block, Rotate Block, Collision Test, Move Block, Remove Row, and New Game.
Pretty simple so far, eh? Now, let's throw in some global variables, bwahahahah! Global variables are preferred, because they are FAST. Speed is essential to a game. Thus, when you can, use them. But, be careful with them. The first two we need are an application handle and a main window handle.
The above are necessary for windows programming. Remember this, always. Next, let's create an array to hold the play area map's tile types. We will add one extra row for Map to make Y-movement collision detection easier. And then, let's make a little structure for a game piece, then two variables of that structure; one for the actual piece, and one for the preview piece. Then, something we *REALLY* need is for timing. Let's call it start_time, of the DWORD type. We also need a GAMESTARTED boolean.
NOW, let's leave main.cpp briefly, and visit bitmapobject.h: |
|
