• Main Page
  • Classes
  • Files
  • File List
  • File Members

code/include/tcyc_input.h

Go to the documentation of this file.
00001 /*
00002  * TetriCycle
00003  * Copyright (C) 2009, 2010 Cale Scholl
00004  *
00005  * This file is part of TetriCycle.
00006  *
00007  * TetriCycle is free software: you can redistribute it and/or modify
00008  * it under the terms of the GNU Lesser General Public License as published
00009  * by the Free Software Foundation, either version 3 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * TetriCycle is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with TetriCycle.  If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 /** @file tcyc_input.h
00022  * @brief Magical macros for handling user input.
00023  * @author Cale Scholl / calvinss4
00024  */
00025 
00026 #pragma once
00027 #ifndef __TCYC_INPUT_H__
00028 #define __TCYC_INPUT_H__
00029 
00030 #include <wiiuse/wpad.h>
00031 #include "defines.h" // for MAX_PLAYERS
00032 
00033 extern vec3w_t g_wiiacc[MAX_PLAYERS];     ///< wiimote acceleration data
00034 extern expansion_t g_wiiexp[MAX_PLAYERS]; ///< wiimote expansion-controller data
00035 
00036 // function prototypes
00037 void TCYC_ProcessInput();         ///< Process player input during game mode.
00038 void TCYC_ProcessEditModeInput(); ///< Process player input during edit mode.
00039 bool PausePressedAnyPlayer();     ///< Returns true if any player pressed pause.
00040  
00041 /// Scans gamecube and wiimote, then updates ACCEL and EXP data.
00042 #define ALL_ScanPads() \
00043 { \
00044   PAD_ScanPads(); \
00045   WPAD_ScanPads(); \
00046   for (int i = 0; i < MAX_PLAYERS; ++i) \
00047   { \
00048     WPAD_Accel(i, g_wiiacc + i); \
00049     WPAD_Expansion(i, g_wiiexp + i); \
00050   } \
00051   for (int i = 3; i >= 0; --i) \
00052   { \
00053           userInput[i].pad.btns_d = PAD_ButtonsDown(i); \
00054           userInput[i].pad.btns_u = PAD_ButtonsUp(i); \
00055           userInput[i].pad.btns_h = PAD_ButtonsHeld(i); \
00056           userInput[i].pad.stickX = PAD_StickX(i); \
00057           userInput[i].pad.stickY = PAD_StickY(i); \
00058           userInput[i].pad.substickX = PAD_SubStickX(i); \
00059           userInput[i].pad.substickY = PAD_SubStickY(i); \
00060           userInput[i].pad.triggerL = PAD_TriggerL(i); \
00061           userInput[i].pad.triggerR = PAD_TriggerR(i); \
00062   } \
00063 }
00064 
00065 // detect nunchuk:
00066 // exp.type == WPAD_EXP_NUNCHUK
00067 #define NUNCHUK_CONNECTED(i) (g_wiiexp[i].type == WPAD_EXP_NUNCHUK)
00068 
00069 #define NUNCHUK_StickPosX(i) g_wiiexp[i].nunchuk.js.pos.x
00070 #define NUNCHUK_StickPosY(i) g_wiiexp[i].nunchuk.js.pos.y
00071 
00072 #define NUNCHUK_StickCenterX(i) g_wiiexp[i].nunchuk.js.center.x
00073 #define NUNCHUK_StickCenterY(i) g_wiiexp[i].nunchuk.js.center.y
00074 
00075 #define NUNCHUK_StickDX(i) (NUNCHUK_StickPosX(i) - NUNCHUK_StickCenterX(i))
00076 #define NUNCHUK_StickDY(i) (NUNCHUK_StickPosY(i) - NUNCHUK_StickCenterY(i))
00077 
00078 #define NUNCHUK_THRESHOLD 65
00079 
00080 #define NUNCHUK_LEFT_PRESSED(i)  (NUNCHUK_StickDX(i) < -NUNCHUK_THRESHOLD)
00081 #define NUNCHUK_RIGHT_PRESSED(i) (NUNCHUK_StickDX(i) > NUNCHUK_THRESHOLD)
00082 #define NUNCHUK_UP_PRESSED(i)    (NUNCHUK_StickDY(i) > NUNCHUK_THRESHOLD)
00083 #define NUNCHUK_DOWN_PRESSED(i)  (NUNCHUK_StickDY(i) < -NUNCHUK_THRESHOLD)
00084 
00085 #define NUNCHUK_ButtonsDown(i) g_wiiexp[i].nunchuk.btns
00086 #define NUNCHUK_ButtonsReleased(i) g_wiiexp[i].nunchuk.btns_released
00087 
00088 #define NUNCHUK_C_PRESSED(i)  (NUNCHUK_ButtonsDown(i) & NUNCHUK_BUTTON_C)
00089 #define NUNCHUK_Z_PRESSED(i)  (NUNCHUK_ButtonsDown(i) & NUNCHUK_BUTTON_Z)
00090 #define NUNCHUK_Z_RELEASED(i) (NUNCHUK_ButtonsReleased(i) & NUNCHUK_BUTTON_Z)
00091 
00092 // ACTION_PRESSED - 
00093 // true if corresponding action button was pressed this frame.
00094 
00095 #define MENU_LEFT_PRESSED(i) \
00096 ( \
00097   PAD_ButtonsDown(i) & PAD_BUTTON_LEFT \
00098   || PAD_StickX(i) < -65 \
00099   || (NUNCHUK_CONNECTED(i) ? \
00100        WPAD_ButtonsDown(i) & WPAD_BUTTON_LEFT || NUNCHUK_LEFT_PRESSED(i) \
00101          : \
00102        WPAD_ButtonsDown(i) & WPAD_BUTTON_UP) \
00103 )
00104 
00105 #define MENU_RIGHT_PRESSED(i) \
00106 ( \
00107   PAD_ButtonsDown(i) & PAD_BUTTON_RIGHT \
00108   || PAD_StickX(i) > 65 \
00109   || (NUNCHUK_CONNECTED(i) ? \
00110        WPAD_ButtonsDown(i) & WPAD_BUTTON_RIGHT || NUNCHUK_RIGHT_PRESSED(i) \
00111          : \
00112        WPAD_ButtonsDown(i) & WPAD_BUTTON_DOWN) \
00113 )
00114 
00115 #define MENU_UP_PRESSED(i) \
00116 ( \
00117   PAD_ButtonsDown(i) & PAD_BUTTON_UP \
00118   || PAD_StickY(i) > 65 \
00119   || (NUNCHUK_CONNECTED(i) ? \
00120        WPAD_ButtonsDown(i) & WPAD_BUTTON_UP || NUNCHUK_UP_PRESSED(i) \
00121          : \
00122        WPAD_ButtonsDown(i) & WPAD_BUTTON_RIGHT) \
00123 )
00124 
00125 #define MENU_DOWN_PRESSED(i) \
00126 ( \
00127   PAD_ButtonsDown(i) & PAD_BUTTON_DOWN \
00128   || PAD_StickY(i) < -65 \
00129   || (NUNCHUK_CONNECTED(i) ? \
00130        WPAD_ButtonsDown(i) & WPAD_BUTTON_DOWN || NUNCHUK_DOWN_PRESSED(i) \
00131          : \
00132        WPAD_ButtonsDown(i) & WPAD_BUTTON_LEFT) \
00133 )
00134 
00135 #define MENU_SELECT_PRESSED(i) \
00136 ( \
00137   PAD_ButtonsDown(i) & PAD_BUTTON_A \
00138   || WPAD_ButtonsDown(i) & (NUNCHUK_CONNECTED(i) ? WPAD_BUTTON_A : WPAD_BUTTON_2) \
00139 )
00140 
00141 #define MENU_EXIT_PRESSED(i) \
00142 ( \
00143   PAD_ButtonsDown(i) & PAD_BUTTON_B \
00144   || WPAD_ButtonsDown(i) & (NUNCHUK_CONNECTED(i) ? WPAD_BUTTON_B : WPAD_BUTTON_1) \
00145 )
00146 
00147 #define A_PRESSED(i) \
00148 ( \
00149   WPAD_ButtonsDown(i) & WPAD_BUTTON_A \
00150   || PAD_ButtonsDown(i) & PAD_BUTTON_A \
00151 )
00152 
00153 #define B_PRESSED(i) \
00154 ( \
00155   WPAD_ButtonsDown(i) & WPAD_BUTTON_B \
00156   || PAD_ButtonsDown(i) & PAD_BUTTON_B \
00157 )
00158 
00159 #define LEFT_PRESSED(i) \
00160 ( \
00161   (g_players[i].rotation != ROTATE_REVERSE ? \
00162     _LEFT_PRESSED(i) \
00163       : \
00164     _RIGHT_PRESSED(i)) \
00165 )
00166 
00167 #define RIGHT_PRESSED(i) \
00168 ( \
00169   (g_players[i].rotation != ROTATE_REVERSE ? \
00170     _RIGHT_PRESSED(i) \
00171       : \
00172     _LEFT_PRESSED(i)) \
00173 )
00174 
00175 #define _LEFT_PRESSED(i) \
00176 ( \
00177   PAD_ButtonsDown(i) & PAD_BUTTON_LEFT \
00178   || PAD_StickX(i) < -65 \
00179   || (NUNCHUK_CONNECTED(i) ? \
00180        WPAD_ButtonsDown(i) & WPAD_BUTTON_LEFT || NUNCHUK_LEFT_PRESSED(i) \
00181          : \
00182        WPAD_ButtonsHeld(i) & WPAD_BUTTON_UP) \
00183 )
00184 
00185 #define _RIGHT_PRESSED(i) \
00186 ( \
00187   PAD_ButtonsDown(i) & PAD_BUTTON_RIGHT \
00188   || PAD_StickX(i) > 65 \
00189   || (NUNCHUK_CONNECTED(i) ? \
00190        WPAD_ButtonsDown(i) & WPAD_BUTTON_RIGHT || NUNCHUK_RIGHT_PRESSED(i) \
00191          : \
00192        WPAD_ButtonsHeld(i) & WPAD_BUTTON_DOWN) \
00193 )
00194 
00195 #define UP_PRESSED(i) \
00196 ( \
00197   PAD_ButtonsDown(i) & PAD_BUTTON_UP \
00198   || PAD_StickY(i) > 65 \
00199   || (NUNCHUK_CONNECTED(i) ? \
00200        WPAD_ButtonsDown(i) & WPAD_BUTTON_UP || NUNCHUK_UP_PRESSED(i) \
00201          : \
00202        WPAD_ButtonsDown(i) & WPAD_BUTTON_RIGHT) \
00203 )
00204 
00205 #define DOWN_PRESSED(i) \
00206 ( \
00207   PAD_ButtonsHeld(i) & PAD_BUTTON_X \
00208   || PAD_ButtonsHeld(i) & PAD_BUTTON_Y \
00209   || PAD_StickY(i) < -65 \
00210   || (NUNCHUK_CONNECTED(i) ? \
00211        WPAD_ButtonsDown(i) & WPAD_BUTTON_DOWN || NUNCHUK_DOWN_PRESSED(i) \
00212          : \
00213        WPAD_ButtonsHeld(i) & WPAD_BUTTON_LEFT) \
00214 )
00215 
00216 // rotate tetris piece
00217 #define ROTATE_PRESSED(i) \
00218 ( \
00219   PAD_ButtonsDown(i) & PAD_BUTTON_A \
00220   || WPAD_ButtonsDown(i) & (NUNCHUK_CONNECTED(i) ? WPAD_BUTTON_A : WPAD_BUTTON_2) \
00221 )
00222 
00223 // rotate tetris piece in opposite direction
00224 #define ROTATE2_PRESSED(i) \
00225 ( \
00226   PAD_ButtonsDown(i) & PAD_BUTTON_B \
00227   || WPAD_ButtonsDown(i) & (NUNCHUK_CONNECTED(i) ? WPAD_BUTTON_B : WPAD_BUTTON_1) \
00228 )
00229 
00230 // grab a powerup from the queue
00231 #define GRAB_HELD(i) \
00232 ( \
00233   WPAD_ButtonsHeld(i) & WPAD_BUTTON_A \
00234 )
00235 
00236 #define PAUSE_PRESSED(i) \
00237 ( \
00238   PAD_ButtonsDown(i) & PAD_BUTTON_START \
00239   || WPAD_ButtonsDown(i) & WPAD_BUTTON_PLUS \
00240 )
00241 
00242 #define MENU_PRESSED(i) \
00243 ( \
00244   PAD_ButtonsDown(i) & PAD_TRIGGER_Z \
00245   || WPAD_ButtonsDown(i) & WPAD_BUTTON_MINUS \
00246 )
00247 
00248 #define LOADER_PRESSED(i) \
00249 ( \
00250   PAD_ButtonsDown(i) & PAD_TRIGGER_R \
00251   || WPAD_ButtonsDown(i) & WPAD_BUTTON_HOME \
00252 )
00253 
00254 // When holding wiimote sideways, XYZ accel values at rest are: 500, 500, 600
00255 #define ACCEL_Z_THRESHOLD 750
00256 #define ACCEL_Z_PRESSED(i) (g_wiiacc[i].z > ACCEL_Z_THRESHOLD)
00257 
00258 #define DROP_PRESSED(i) \
00259 ( \
00260   PAD_ButtonsDown(i) & PAD_BUTTON_DOWN \
00261   || WPAD_ButtonsDown(i) & (NUNCHUK_CONNECTED(i) ? WPAD_BUTTON_DOWN : WPAD_BUTTON_A) \
00262 )
00263 
00264 // ACTION_HELD - 
00265 // true if corresponding action button was held this frame.
00266 
00267 #define PAUSE_HELD(i) \
00268 ( \
00269   PAD_ButtonsHeld(i) & PAD_BUTTON_START \
00270   || WPAD_ButtonsHeld(i) & WPAD_BUTTON_PLUS \
00271 )
00272 
00273 #endif // __TCYC_INPUT_H__

Generated on Wed Oct 20 2010 17:06:58 for TetriCycle by  doxygen 1.7.1