Page 31/36 Case study: 3D Tetris In this chapter I am going to give you my ideas about making a simple Tetris game with GLScene. I am not going to write only some code, I will mainly focus on structure and design of the game. I am going to keep it as simple as possible. After all this is beginner’s guide. I am sure many people would do much better 3D Tetris so don’t take my word that this is the best way how to make a 3D Tetris game. I don’t have working code for the game. This is a kind of mini game design document. I would be interested if anyone makes the game real. Please send it over to me and I will publish it with this book. Design To make it ultra-simple we are going to create a clone of old Tetris. The third dimension here is going to add only a little bit of eye candy. It is actually going to be ‘2.5D Tetris’. Camera will look at the scene from an interesting angle and perspective. That’s all. The game will take place in two dimensional grid just like old Tetris. Only the blocks will be made up of cubes instead of squares. There will be no menus. The game will start right after the program is launched or it will wait for the user to press a key. During game a label will show number of achieved points. After the game is finished a message window will show information that the game is over and player’s score. The program will then terminate. In classical Tetris the number of types and shape of blocks is defined. We are going to randomly generate shape of the block on its creation. The block will have constant descending speed. The player can move with them left and right and rotate them clockwise  and counter- clockwise. Input will be handled by keyboard. Structure We     are     going     to     need TGLScene, TGLSceneViewer, TGLCadencer and TGLWindowsBitmapFont  components. The playing field will be 11 units wide on X axis and 21 units high on Z axis. We will place the camera on negative Z axis overlooking the whole scene from top right side. One TGLPlane will form the ground at position [0,0,-0.5] and two tall TGLCubes will be standing on sides to set borders. At positions [-6,0,10] and [6,0,10], 10 units high. All of these objects together with nice camera position can be made design time. Don’t forget to add light to the scene. You can place it wherever you like. We are going to use our game logic for detecting collisions of the falling cubes. The playing field will be represented by array of singles: var FloodLevels: array[-5..5] of single; Each member of this field represents how high the stack of boxes reaches during the play. Every time the block will be securely placed in final position corresponding field will be set to new height level. This will happen only after the block will rest at the bottom, not during his fall. There are no cubes at the beginning of the game so initial values are zero. Values stored in FloodLevels GLScene beginner's guide, Jan Zizka, 2005