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 __PLAYER_H__
00028 #define __PLAYER_H__
00029
00030 #include <cstring>
00031
00032 #include "TetrisPiece.h"
00033 #include "PowerupUtils.h"
00034 #include "Color.h"
00035 #include "Powerup.h"
00036 #include "Profile.h"
00037 #include "defines.h"
00038 #include "defines_Player.h"
00039
00040 extern ColorGradient g_cubeGradients[COLOR_ID_MAX];
00041
00042 enum
00043 {
00044 ROTATE_NORMAL,
00045 ROTATE_REVERSE,
00046 ROTATE_PIECE,
00047 ROTATE_SIZE
00048 };
00049
00050 enum
00051 {
00052 GUIDE_OFF,
00053 GUIDE_SHADOW,
00054 GUIDE_LINE,
00055 GUIDE_SIZE
00056 };
00057
00058
00059 class Player
00060 {
00061
00062
00063 struct PlayerPowerupData
00064 {
00065 PlayerPowerupData() : playfieldScale(0),
00066 isBigHand(false),
00067 isReverse(false),
00068 mirrorCtr(0) { }
00069
00070 float playfieldScale;
00071 bool isBigHand;
00072 bool isReverse;
00073 u8 mirrorCtr;
00074 };
00075
00076
00077 struct PlayerGameData
00078 {
00079 PlayerGameData() : grabbedPowerup(NULL),
00080 score(0),
00081 lines(0),
00082 pieces(-1),
00083 frame(0),
00084 level(0),
00085 speed(START_SPEED),
00086 cycleIdx(0),
00087 leftRightCtr(0),
00088 downCtr(0),
00089 isDead(false),
00090 isGrabHeld(false),
00091 isLeftRightHeld(false),
00092 isDownHeld(false)
00093 {
00094 memset(powerupQueue, 0, sizeof(powerupQueue));
00095 memset(powerupEffects, 0, sizeof(powerupEffects));
00096 }
00097
00098 TetrisPieceBlock playfield[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
00099 Powerup *powerupQueue[MAX_ACQUIRED_POWERUPS];
00100 Powerup *powerupEffects[MAX_POWERUP_EFFECTS];
00101 PlayerPowerupData powerupData;
00102 Powerup *grabbedPowerup;
00103 u16 score;
00104 u16 lines;
00105 u16 pieces;
00106 u8 frame;
00107 u8 level;
00108 u8 speed;
00109 u8 cycleIdx;
00110 u8 leftRightCtr;
00111 u8 downCtr;
00112 bool isDead;
00113 bool isGrabHeld;
00114 bool isLeftRightHeld;
00115 bool isDownHeld;
00116 };
00117
00118 public:
00119 Player() : powerups(g_totalPowerups),
00120 cubeAngle(DEFAULT_CUBE_ANGLE),
00121 playfieldDX(DEFAULT_PLAYFIELD_DX),
00122 playfieldDY(DEFAULT_PLAYFIELD_DY),
00123 powerupsSize(g_totalPowerups),
00124 playfieldWidth(DEFAULT_PLAYFIELD_WIDTH),
00125 playfieldHeight(DEFAULT_PLAYFIELD_HEIGHT),
00126 playfieldScale(DEFAULT_PLAYFIELD_SCALE),
00127 rotation(ROTATE_NORMAL),
00128 guide(GUIDE_SHADOW),
00129 isShakeEnabled(false),
00130 isPreviewEnabled(true),
00131 isHandicapEnabled(false)
00132 {
00133 for (int i = 0; i < g_totalPowerups; ++i)
00134 powerups[i] = (PowerupId)i;
00135 }
00136
00137 PlayerGameData gameData;
00138 Profile profile;
00139 vector<PowerupId> powerups;
00140 TetrisPiece currPiece;
00141 TetrisPiece nextPiece;
00142 float cubeAngle;
00143 s16 playfieldDX;
00144 s16 playfieldDY;
00145 u8 powerupsSize;
00146 u8 playfieldWidth;
00147 u8 playfieldHeight;
00148 u8 playfieldScale;
00149 u8 id;
00150 u8 rotation;
00151 u8 guide;
00152 bool isShakeEnabled;
00153 bool isPreviewEnabled;
00154 bool isHandicapEnabled;
00155
00156
00157 void IncrementCycle()
00158 {
00159 gameData.cycleIdx = ++gameData.cycleIdx % playfieldWidth;
00160 }
00161
00162
00163 void DecrementCycle()
00164 {
00165 gameData.cycleIdx = (gameData.cycleIdx > 0) ? gameData.cycleIdx - 1 : playfieldWidth - 1;
00166 }
00167
00168
00169 void Reset();
00170
00171
00172
00173 int GetPowerupQueueSlot()
00174 {
00175 for (int i = 0; i < MAX_ACQUIRED_POWERUPS; ++i)
00176 {
00177 if (!gameData.powerupQueue[i])
00178 {
00179 return i;
00180 }
00181 }
00182
00183 return -1;
00184 }
00185
00186
00187 void QueuePowerup(Powerup *powerup, int slot)
00188 {
00189 gameData.powerupQueue[slot] = powerup;
00190 }
00191
00192
00193 void RemovePowerup(int slot)
00194 {
00195 gameData.powerupQueue[slot] = NULL;
00196 }
00197
00198
00199
00200 int GetEffectQueueSlot()
00201 {
00202 for (int i = 0; i < MAX_POWERUP_EFFECTS; ++i)
00203 {
00204 if (!gameData.powerupEffects[i])
00205 {
00206 return i;
00207 }
00208 }
00209
00210 return -1;
00211 }
00212
00213
00214
00215 bool QueueEffect(Powerup *powerup)
00216 {
00217 for (int i = 0; i < MAX_POWERUP_EFFECTS; ++i)
00218 {
00219 if (!gameData.powerupEffects[i])
00220 {
00221 gameData.powerupEffects[i] = powerup;
00222 return true;
00223 }
00224 }
00225
00226 return false;
00227 }
00228
00229
00230 void QueueEffect(Powerup *powerup, int slot)
00231 {
00232 gameData.powerupEffects[slot] = powerup;
00233 }
00234
00235
00236
00237 bool RemoveEffect(Powerup *powerup)
00238 {
00239 for (int i = 0; i < MAX_POWERUP_EFFECTS; ++i)
00240 {
00241 if (gameData.powerupEffects[i] == powerup)
00242 {
00243 gameData.powerupEffects[i] = NULL;
00244 return true;
00245 }
00246 }
00247
00248 return false;
00249 }
00250
00251
00252 void Update()
00253 {
00254 Powerup *powerup;
00255 for (int i = 0; i < MAX_POWERUP_EFFECTS; ++i)
00256 {
00257 powerup = gameData.powerupEffects[i];
00258 if (powerup)
00259 powerup->Update();
00260 }
00261 }
00262
00263
00264 void DrawPlayfield();
00265
00266
00267 void DrawPiece(TetrisPiece* cp = NULL, u8 alpha = 255);
00268
00269
00270 void DrawPieceShadow();
00271
00272
00273 void DrawNextPiece()
00274 {
00275 if (isPreviewEnabled)
00276 DrawPiece(&nextPiece, 145);
00277 }
00278
00279
00280 void DrawBase();
00281
00282
00283 void RotateCurrentPiece(int rot)
00284 {
00285 int oldRot = currPiece.GetRotation();
00286 currPiece.SetRotation(rot);
00287
00288
00289 if (!_CanPlacePiece())
00290 currPiece.SetRotation(oldRot);
00291 }
00292
00293
00294 bool MovePlayfield(int type);
00295
00296
00297 bool MovePiece(int type, TetrisPiece *cp = NULL);
00298
00299
00300 void DoMovement();
00301
00302
00303 void DrawBlockAsCube(float x, float y, ColorId colorIdx, u8 alpha = 255, GuiImageData *imgData = NULL, bool isGuideDot = false);
00304
00305 private:
00306 float _GetScale() { return !gameData.powerupData.playfieldScale ? (float)playfieldScale : gameData.powerupData.playfieldScale; }
00307 void _SetBaseColor(GXColor &c) { g_cubeGradients[COLOR_ID_BASE].SetColor(c); }
00308 void _GetWinner();
00309 void _DisplayWinner(int winner);
00310 void _IncreaseLevelAllBut(int plyrIdx);
00311
00312
00313
00314 void _IncreaseLevel()
00315 {
00316 if (gameData.level < MAX_LEVEL)
00317 {
00318 gameData.level++;
00319 gameData.speed = START_SPEED - 3 * gameData.level;
00320 }
00321 }
00322
00323
00324 void _SpawnNextPiece()
00325 {
00326 currPiece.InitPiece(nextPiece.GetPieceId(), playfieldWidth);
00327 currPiece.SetPowerupId(nextPiece.GetPowerupId());
00328
00329 nextPiece.InitPiece(TetrisPiece::GetNextId(), playfieldWidth);
00330 nextPiece.SetPowerupId(PowerupUtils::GetNextId(*this));
00331 }
00332
00333
00334 bool _CanPlacePiece(TetrisPiece *cp = NULL);
00335
00336
00337 bool _RemoveLines();
00338
00339
00340 void _RemoveLine(int line);
00341 };
00342
00343 #endif // __PLAYER_H__