Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #pragma once
00027 #ifndef __TETRISPIECE_H__
00028 #define __TETRISPIECE_H__
00029
00030 #include <gctypes.h>
00031
00032 #include "mt.h"
00033 #include "defines_Powerup.h"
00034
00035 #define DEFAULT_BLOCKS_PER_PIECE 4
00036
00037
00038 enum TetrisPieceId
00039 {
00040 TETRISPIECE_ID_NONE = -1,
00041 TETRISPIECE_ID_O,
00042 TETRISPIECE_ID_I,
00043 TETRISPIECE_ID_S,
00044 TETRISPIECE_ID_Z,
00045 TETRISPIECE_ID_L,
00046 TETRISPIECE_ID_J,
00047 TETRISPIECE_ID_T,
00048 TETRISPIECE_ID_JUNK,
00049 TETRISPIECE_ID_MAX,
00050 TETRISPIECE_ID_RAND_MAX = 7
00051 };
00052
00053
00054 struct TetrisPieceDesc
00055 {
00056 u8 map[4][4];
00057 };
00058
00059
00060 extern TetrisPieceDesc g_pieceDesc[TETRISPIECE_ID_MAX][4];
00061
00062
00063 class TetrisPiece
00064 {
00065 public:
00066 const TetrisPieceDesc& GetPieceDescription() { return *desc; }
00067 TetrisPieceId GetPieceId() { return pieceId; }
00068 PowerupId GetPowerupId() { return powerupId; }
00069 int GetRotation() { return rotation; }
00070 int GetX() { return x; }
00071 int GetY() { return y; }
00072
00073 void InitPiece(TetrisPieceId id, int width = 0)
00074 {
00075 pieceId = id;
00076 rotation = 0;
00077 _ResetDesc();
00078 downctr = 0;
00079 if (width)
00080 {
00081 x = (width >> 1) - 2;
00082 y = -1;
00083 }
00084 }
00085 void SetPowerupId(PowerupId id) { powerupId = id; }
00086 void SetRotation(int rot) { rotation = rot, _ResetDesc(); }
00087 void SetX(int xval) { x = xval; }
00088 void SetY(int yval) { y = yval; }
00089 void IncrementDownCounter() { ++downctr; }
00090 bool IsAccelEnabled() { return downctr > 0; }
00091
00092 static TetrisPieceId GetNextId()
00093 {
00094 return (TetrisPieceId)(int)(genrand() * TETRISPIECE_ID_RAND_MAX);
00095 }
00096
00097 private:
00098 const TetrisPieceDesc *desc;
00099 PowerupId powerupId;
00100 TetrisPieceId pieceId;
00101 u8 rotation;
00102 u8 downctr;
00103
00104
00105
00106
00107
00108 s8 x;
00109 s8 y;
00110
00111 void _ResetDesc() { desc = &g_pieceDesc[pieceId][rotation]; }
00112 };
00113
00114
00115
00116
00117
00118
00119
00120 struct TetrisPieceConnectivityInfo
00121 {
00122 TetrisPieceConnectivityInfo(PowerupId pupId = POWERUP_ID_NONE,
00123 u8 maxCount = DEFAULT_BLOCKS_PER_PIECE) :
00124 powerupId(pupId),
00125 counter(maxCount) {}
00126
00127 PowerupId powerupId;
00128 u8 counter;
00129 };
00130
00131
00132
00133
00134
00135
00136 class TetrisPieceBlock
00137 {
00138 public:
00139 TetrisPieceBlock(TetrisPieceId id = TETRISPIECE_ID_NONE,
00140 TetrisPieceConnectivityInfo *info = NULL) :
00141 pieceId(id),
00142 connectivityInfo(info) {}
00143
00144 TetrisPieceId pieceId;
00145 TetrisPieceConnectivityInfo *connectivityInfo;
00146
00147 void SetConnectivityInfo(TetrisPieceConnectivityInfo *info)
00148 {
00149 connectivityInfo = info;
00150 }
00151
00152 void Free()
00153 {
00154 delete connectivityInfo;
00155 connectivityInfo = NULL;
00156 }
00157 };
00158
00159 #endif // __TETRISPIECE_H__