00001 #include <stdlib.h>
00002
00003 #include <gccore.h>
00004 #include <gcmodplay.h>
00005 #include <wiiuse/wpad.h>
00006
00007 #include "globals.h"
00008 #include "prototypes.h"
00009 #include "tetris_input.h"
00010 #include "tetris_menu.h"
00011 #include "PowerupUtils.h"
00012
00013 void TCYC_ProcessInput()
00014 {
00015
00016 if (PausePressedAnyPlayer())
00017 {
00018 Pause("Pause");
00019 if (g_tcycMenu != TCYC_MENU_NONE)
00020 return;
00021
00022
00023 PowerupUtils::ResetPowerupStartTimes();
00024 }
00025
00026 for (int i = 0; i < g_options.players; ++i)
00027 {
00028 if (g_players[i].gameData.isDead)
00029 continue;
00030
00031
00032 int targetSlot = -1;
00033 if (userInput[i].wpad->ir.valid)
00034 targetSlot = TCYC_GetTargetPowerupSlot(i, userInput[i].wpad->ir.x, userInput[i].wpad->ir.y);
00035
00036 if (GRAB_HELD(i))
00037 {
00038 if (!g_players[i].gameData.isGrabHeld)
00039 {
00040 g_players[i].gameData.isGrabHeld = true;
00041 if (targetSlot >= 0)
00042 {
00043 g_players[i].gameData.grabbedPowerup = g_players[i].gameData.powerupQueue[targetSlot];
00044 g_players[i].gameData.powerupQueue[targetSlot] = NULL;
00045
00046
00047
00048 WPAD_Data(i)->btns_d = 0;
00049 }
00050 }
00051 }
00052 else
00053 {
00054 g_players[i].gameData.isGrabHeld = false;
00055 if (g_players[i].gameData.grabbedPowerup)
00056 {
00057
00058 if (targetSlot >= 0)
00059 {
00060 int emptySlot = g_players[i].GetPowerupQueueSlot();
00061 if (emptySlot >= 0)
00062 {
00063 g_players[i].QueuePowerup(g_players[i].gameData.grabbedPowerup, emptySlot);
00064 }
00065 else
00066 {
00067
00068 PowerupUtils::GetInvalidTargetSound()->Play();
00069 }
00070 }
00071
00072 else
00073 {
00074 int targetPlayer = -1;
00075 if (userInput[i].wpad->ir.valid)
00076 targetPlayer = TCYC_GetTargetPlayer(userInput[i].wpad->ir.x);
00077
00078 bool success = false;
00079 if (targetPlayer >= 0)
00080 success = g_players[i].gameData.grabbedPowerup->Initiate(targetPlayer);
00081
00082 if (success)
00083 {
00084 g_players[i].gameData.grabbedPowerup->GetSound()->Play();
00085 }
00086 else
00087 {
00088
00089 int emptySlot = g_players[i].GetPowerupQueueSlot();
00090 if (emptySlot >= 0)
00091 g_players[i].QueuePowerup(g_players[i].gameData.grabbedPowerup, emptySlot);
00092
00093
00094 PowerupUtils::GetInvalidTargetSound()->Play();
00095 }
00096 }
00097
00098 g_players[i].gameData.grabbedPowerup = NULL;
00099 }
00100 }
00101
00102 if (ROTATE_PRESSED(i))
00103 rotate(g_currPiece[i].rot + 1, i);
00104 else if (ROTATE2_PRESSED(i))
00105 rotate(g_currPiece[i].rot - 1, i);
00106
00107 static const int move_timeout = 5;
00108
00109 bool left_pressed = LEFT_PRESSED(i);
00110 bool right_pressed = RIGHT_PRESSED(i);
00111
00112 if (g_players[i].gameData.powerupData.isReverse)
00113 SWAP(left_pressed, right_pressed);
00114
00115 if (!left_pressed && !right_pressed)
00116 {
00117 g_currPiece[i].haspressed = 0;
00118 g_currPiece[i].waitnum = 0;
00119 }
00120 else if (!g_currPiece[i].haspressed || g_currPiece[i].waitnum > move_timeout)
00121 {
00122 if (g_currPiece[i].waitnum > move_timeout)
00123 g_currPiece[i].waitnum = 0;
00124
00125 if (left_pressed)
00126 {
00127 g_currPiece[i].haspressed = 1;
00128
00129 if (MovePlayfield(LEFT, i))
00130 g_players[i].IncrementCycle();
00131 }
00132
00133 if (right_pressed)
00134 {
00135 g_currPiece[i].haspressed = 1;
00136
00137 if (MovePlayfield(RIGHT, i))
00138 g_players[i].DecrementCycle();
00139 }
00140 }
00141 else
00142 {
00143 g_currPiece[i].waitnum++;
00144 }
00145
00146
00147 static const int down_timeout = 2;
00148 static int down[2] = {0, 0};
00149
00150 TetrisPiece& p = g_currPiece[i];
00151 bool down_pressed = DOWN_PRESSED(i);
00152
00153 if (down_pressed)
00154 {
00155 if (p.down_enabled)
00156 {
00157 g_players[i].gameData.frame = 1;
00158 down[i] %= down_timeout;
00159 if (!down[i]++)
00160 DoMovement(i);
00161 }
00162 }
00163 else
00164 {
00165 p.down_enabled = true;
00166
00167 if (down[i])
00168 g_players[i].gameData.frame = down[i];
00169
00170 down[i] = 0;
00171 }
00172
00173
00174 if (g_players[i].gameData.frame % p.speed == 0)
00175 {
00176 DoMovement(i);
00177 p.downctr++;
00178 }
00179
00180
00181 bool accel_down = ACCEL_Z_PRESSED(i) && p.downctr;
00182 if (!accel_down)
00183 {
00184 p.accel_enabled = true;
00185 }
00186 else
00187 {
00188 if (!p.accel_enabled)
00189 accel_down = false;
00190
00191 p.accel_enabled = false;
00192 }
00193
00194 if (DROP_PRESSED(i) || (g_players[i].isShakeEnabled ? accel_down : false))
00195 {
00196 while (MoveBlock(DOWN, i));
00197
00198 g_players[i].gameData.frame = 0;
00199 DoMovement(i);
00200 }
00201 }
00202 }
00203
00204 void Pause(const char *pauseTxt, GXColor *txtColor)
00205 {
00206 g_options.isPaused = 1;
00207 MODPlay_Pause(&g_modPlay, 1);
00208
00209 GuiText txt(pauseTxt, 38, txtColor ? *txtColor : (GXColor){255, 255, 255, 255});
00210 txt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
00211 txt.SetPosition(0, 0);
00212
00213 GuiWindow pauseWindow(screenwidth, screenheight);
00214 if (pauseTxt)
00215 pauseWindow.Append(&txt);
00216
00217
00218 GuiButton quitBtn(btnOutline->GetWidth(), btnOutline->GetHeight());
00219 GuiText quitBtnTxt("Quit", 28, (GXColor){0, 0, 0, 255});
00220 GuiImage quitBtnImg(btnOutline);
00221 GuiImage quitBtnImgOver(btnOutlineOver);
00222
00223 quitBtn.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
00224 quitBtn.SetPosition(-50 - btnOutline->GetWidth(), -50);
00225 quitBtn.SetLabel(&quitBtnTxt);
00226 quitBtn.SetImage(&quitBtnImg);
00227 quitBtn.SetImageOver(&quitBtnImgOver);
00228 quitBtn.SetSoundOver(btnSoundOver);
00229 quitBtn.SetTrigger(trigA);
00230 quitBtn.SetEffectGrow();
00231 pauseWindow.Append(&quitBtn);
00232
00233
00234 GuiButton restartBtn(btnOutline->GetWidth(), btnOutline->GetHeight());
00235 GuiText restartBtnTxt("Restart", 28, (GXColor){0, 0, 0, 255});
00236 GuiImage restartBtnImg(btnOutline);
00237 GuiImage restartBtnImgOver(btnOutlineOver);
00238
00239 restartBtn.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
00240 restartBtn.SetPosition(-50, -50);
00241 restartBtn.SetLabel(&restartBtnTxt);
00242 restartBtn.SetImage(&restartBtnImg);
00243 restartBtn.SetImageOver(&restartBtnImgOver);
00244 restartBtn.SetSoundOver(btnSoundOver);
00245 restartBtn.SetTrigger(trigA);
00246 restartBtn.SetEffectGrow();
00247 pauseWindow.Append(&restartBtn);
00248
00249 mainWindow->Append(&pauseWindow);
00250
00251 TCYC_SetUp2D();
00252
00253 while (g_options.isPaused)
00254 {
00255
00256 UpdatePads();
00257 TCYC_DrawText();
00258 mainWindow->Draw();
00259
00260
00261
00262 #ifdef HW_RVL
00263 for(int i=3; i >= 0; i--)
00264 {
00265 if(userInput[i].wpad->ir.valid)
00266 Menu_DrawImg(userInput[i].wpad->ir.x-48, userInput[i].wpad->ir.y-48,
00267 96, 96, pointer[i]->GetImage(), userInput[i].wpad->ir.angle, 1, 1, 255);
00268 DoRumble(i);
00269 }
00270 #endif
00271
00272 Menu_Render();
00273 for (int i = 0; i < MAX_PLAYERS; ++i)
00274 mainWindow->Update(&userInput[i]);
00275
00276 if (PausePressedAnyPlayer())
00277 {
00278 g_options.isPaused = 0;
00279 MODPlay_Pause(&g_modPlay, 0);
00280 }
00281 else if (quitBtn.GetState() == STATE_CLICKED)
00282 {
00283 g_options.isPaused = 0;
00284 g_tcycMenu = TCYC_MENU_MAIN;
00285 }
00286 else if (restartBtn.GetState() == STATE_CLICKED)
00287 {
00288 g_options.isPaused = 0;
00289 g_tcycMenu = TCYC_MENU_GAME;
00290 }
00291 }
00292
00293
00294 UpdatePads();
00295
00296 mainWindow->Remove(&pauseWindow);
00297 }
00298
00299 void TCYC_ProcessEditModeInput()
00300 {
00301 for (int i = 0; i < g_options.players; ++i)
00302 {
00303 static const int move_timeout = 5;
00304
00305 bool left_pressed = LEFT_PRESSED(i);
00306 bool right_pressed = RIGHT_PRESSED(i);
00307
00308 if (!left_pressed && !right_pressed)
00309 {
00310 g_currPiece[i].haspressed = 0;
00311 g_currPiece[i].waitnum = 0;
00312 }
00313 else if (!g_currPiece[i].haspressed || g_currPiece[i].waitnum > move_timeout)
00314 {
00315 if (g_currPiece[i].waitnum > move_timeout)
00316 g_currPiece[i].waitnum = 0;
00317
00318 if (left_pressed)
00319 {
00320 g_currPiece[i].haspressed = 1;
00321
00322 if (MovePlayfield(LEFT, i))
00323 g_players[i].IncrementCycle();
00324 }
00325
00326 if (right_pressed)
00327 {
00328 g_currPiece[i].haspressed = 1;
00329
00330 if (MovePlayfield(RIGHT, i))
00331 g_players[i].DecrementCycle();
00332 }
00333 }
00334 else
00335 {
00336 g_currPiece[i].waitnum++;
00337 }
00338 }
00339 }