Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

/home/rdbrown/doxygen/cse125g1/src/game/client/PlayerInput.h

00001 #ifndef _MM_PLAYER_INPUT_H_
00002 #define _MM_PLAYER_INPUT_H_
00003 
00004 #include <iostream>
00005 
00006 #include "input/Input.h"
00007 #include "net/MMNet.h"
00008 
00009 #ifdef __APPLE__
00010 namespace Carbon {
00011 #include <ApplicationServices/ApplicationServices.h>
00012 }
00013 #endif
00014 
00015 using namespace std;
00016 
00017 class PlayerInput;
00018 
00019 static PlayerInput *thisPlayerInput;
00020 static void mouseMovedCallback(int x, int y);
00021 static bool tabKeyPress;
00022 
00023 static void setTabKeyPress()
00024 {
00025         tabKeyPress = true;
00026 }
00027 
00028 static bool getTabKeyPress()
00029 {
00030         bool result = tabKeyPress;
00031         tabKeyPress = false;
00032         return result;
00033 }
00034 
00035 static void reqMultiShot();
00036 static void reqRapidFire();
00037 static void reqDoubleDamage();
00038 static void reqFastShot();
00039 
00040 class PlayerInput {
00041  
00042     private:
00043         MMNet::Player *player;       
00044         bool last[4];
00045                 Vector3 lastRotation;
00046         
00047     public:
00048         PlayerInput(MMNet::Player *player) { 
00049                         thisPlayerInput = this;
00050             this->player = player;
00051                         InputSetMouseMotion(mouseMovedCallback);
00052                         InputSetKeyDown('\t',setTabKeyPress);
00053                         InputSetKeyDown('m',reqMultiShot);
00054                         InputSetKeyDown('M',reqMultiShot);
00055                         InputSetKeyDown('j',reqRapidFire);
00056                         InputSetKeyDown('J',reqRapidFire);
00057                         InputSetKeyDown('k',reqDoubleDamage);
00058                         InputSetKeyDown('K',reqDoubleDamage);
00059 
00060                         lastRotation = player->world.c;
00061         }
00062     
00063                 void getMultiShot()
00064                 {
00065                         player->clientMultiShot();
00066                 }
00067                 void getRapidFire()
00068                 {
00069                         player->clientRapidFire();
00070                 }
00071                 void getDoubleDamage()
00072                 {
00073                         player->clientDoubleDamage();
00074                 }
00075         void update() {
00076             bool current[4];
00077             int i;            
00078             
00079             current[0] = InputKeyIsDown('w');
00080             current[1] = InputKeyIsDown('s');
00081             current[2] = InputKeyIsDown('a');
00082             current[3] = InputKeyIsDown('d');
00083             
00084 
00085             for(i = 0; i < 4; i++) {
00086                 if(current[i] != last[i]) {
00087                     //cerr << "Movement changed: " << current[0] << ", " <<  current[1]  << ", " << current[2] << ", " << current[3] << endl;                    
00088                                         player->clientUpdateMovement(TNL::RangedU32<0,1>(current[0]), TNL::RangedU32<0,1>(current[1]), TNL::RangedU32<0,1>(current[2]), TNL::RangedU32<0,1>(current[3]));                   
00089                     break;
00090                 }
00091             }
00092             
00093             for(i = 0; i < 4; i++) {
00094                 last[i] = current[i];
00095             }
00096                         
00097                         //handle weapon switch
00098                         if(getTabKeyPress()) player->clientChangeWeapon();
00099                         
00100                         if(lastRotation.Equals(player->world.c) == false) {            
00101                                 Vector3 &v = player->world.c;
00102                                 player->clientUpdateRotation(v.x, v.y, v.z);
00103                                 lastRotation = v;
00104                         }
00105 
00106                         //Handle Arrow Firing
00107                         //if (InputMouseIsDown(0))
00108                         //{
00109                         //}
00110         }
00111 
00112                 void mouseMoved(int x, int y) {          
00113                         Matrix34 yRot, xRot;
00114                         int dx, dy;             /* change in mouse coordinates          */
00115 
00116 #ifdef __APPLE__
00117                         Carbon::CGGetLastMouseDelta(&dx, &dy);
00118 #else
00119                         dx = x - 200;           /* change in mouse coords       */
00120                         dy = y - 300;
00121 
00122                         if (dx != 0 || dy != 0)
00123                                 glutWarpPointer(200,300);
00124 #endif
00125                         player->localUpdateRotation(dy*-0.004, dx*0.004);
00126                         glutPostRedisplay();
00127                 }
00128 
00129                 void pinMouse(bool b) {
00130 #ifdef __APPLE__
00131                   Carbon::CGAssociateMouseAndMouseCursorPosition(b);
00132                   glutWarpPointer(200,300);
00133 #endif            
00134                 }
00135 };
00136 
00137 static void mouseMovedCallback(int x, int y) {          
00138         thisPlayerInput->mouseMoved(x,y);            
00139 }
00140 
00141 static void reqMultiShot()
00142 {
00143         thisPlayerInput->getMultiShot();
00144 }
00145 static void reqRapidFire()
00146 {
00147         thisPlayerInput->getRapidFire();
00148 }
00149 static void reqDoubleDamage()
00150 {
00151         thisPlayerInput->getDoubleDamage();
00152 }
00153 
00154 /*
00155 
00156 register as callbacks with input library
00157 
00158 tick based
00159 
00160 
00161 mouse
00162 
00163 register mouse motion with input library
00164 (call automatically)
00165 do some math to calculate new orientation of player, and then
00166 call rpc.
00167 
00168 */
00169 
00170 #endif

Generated on Thu Aug 18 16:03:08 2005 for Robin Hood: Thieves & Knights by doxygen1.2.18