00001 #include "Controls.h"
00002
00003 void centerMouse()
00004 {
00005 glutWarpPointer((GLint)(glutGet(GLUT_WINDOW_WIDTH)/2), (GLint)(glutGet(GLUT_WINDOW_HEIGHT)/2));
00006 }
00007
00008 void kbSpecialFunc(int key, int x, int y)
00009 {
00010 if(gameIsPaused)
00011 {
00012 switch(key)
00013 {
00014 case GLUT_KEY_DOWN:
00015 incrementSelectedMenu();
00016 break;
00017
00018 case GLUT_KEY_UP:
00019 decreaseSelectedMenu();
00020 break;
00021 }
00022 }
00023 }
00024
00025 void kbUp(unsigned char key, int x, int y)
00026 {
00027 keys[(int)tolower(key)] = 0;
00028 }
00029
00030 void kbDown(unsigned char key, int x, int y)
00031 {
00032 keys[(int)tolower(key)] = 1;
00033 printf("%c ", key);
00034 }
00035
00036 void mouseFunc(int button, int state, int x, int y)
00037 {
00038
00039 if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN && exitMenu == 1)
00040 {
00041 if(x >= 250 && y >= 130 && x <= 450 && y <= 380)
00042 exit(0);
00043 }
00044 }
00045
00046 void checkKeyPressed()
00047 {
00048
00049 if(gameIsPaused)
00050 {
00051 if(keys[13])
00052 {
00053 pressEnter();
00054 keys[13] = 0;
00055 }
00056
00057 }
00058 else
00059 {
00060
00061 if(keys[(int)'w'])
00062 {
00063 racket.velocity[2]--;
00064
00065 racket.velocity[2] =-20.5;
00066
00067 }
00068
00069 if(keys[(int)'s'])
00070 {
00071 racket.velocity[2]++;
00072
00073 racket.velocity[2] =20.5;
00074
00075 }
00076
00077 if(keys[(int)'d'])
00078 {
00079 racket.velocity[0]++;
00080
00081
00082
00083 }
00084
00085 if(keys[(int)'a'])
00086 {
00087
00088 racket.velocity[0]--;
00089 racket.velocity[0] =-20.5;
00090
00091 }
00092
00093 if(keys[(int)' '])
00094 {
00095 racket.velocity[1]+=3;
00096 }
00097
00098 if(keys[(int)'r'] && !keys[(int)'g'])
00099 {
00100 resetBall();
00101 }
00102
00103 if(keys[(int)'b'])
00104 {
00105 ballBounce();
00106 }
00107
00108
00109
00110
00111
00112
00113 if(keys[(int)'g'] && keys[(int)'-'])
00114 {
00115
00116 gravity-= 0.5;
00117 printf("Gravity Decrease! Now: %f \n", gravity);
00119 keys[(int)'-'] = 0;
00120 }
00121
00122 if(keys[(int)'g'] && keys[(int)'='])
00123 {
00124 gravity+= 0.5;
00125 printf("Gravity Increase! Now: %f \n", gravity);
00126
00127 keys[(int)'='] = 0;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 if(keys[(int)'g'] && keys[(int)'r'] && !keys[(int)'='] && !keys[(int)'-'])
00139 {
00140 gravity = 1.0;
00141 printf("Gravity Reset! Now: %f \n", gravity);
00142 }
00143
00144 if(keys[(int)'f'] && keys[(int)'-'])
00145 {
00146
00147 friction-= 0.1;
00148 printf("Friction Decrease! Now: %f \n", friction);
00150 keys[(int)'-'] = 0;
00151 }
00152
00153 if(keys[(int)'f'] && keys[(int)'='])
00154 {
00155 friction+= 0.1;
00156 printf("Friction Increase! Now: %f \n", friction);
00157
00158 keys[(int)'='] = 0;
00159 }
00160
00161 if(keys[(int)'f'] && keys[(int)'d'])
00162 {
00163 if(friction != 0.0)
00164 friction = 0.0;
00165 else
00166 friction = 0.09;
00167
00168
00169 keys[(int)'d'] = 0;
00170 }
00171
00172 if(keys[27])
00173 {
00174 pauseGame();
00175 mainMenu();
00176 keys[27] = 0;
00177 }
00178 }
00179
00180 }
00181
00182
00183
00184
00185
00186 void passiveMouse(int x, int y)
00187 {
00188 static float lastTime = 0.0f, presentTime = 0.0f;
00189 float dt;
00190 GLint centerIt = 0;
00191 int winX = glutGet(GLUT_WINDOW_WIDTH);
00192 int winY = glutGet(GLUT_WINDOW_HEIGHT);
00193
00194
00195 float tmpX, tmpY;
00196
00197 presentTime = glutGet(GLUT_ELAPSED_TIME);
00198
00199 if(gameIsPaused)
00200 {
00201 lastTime = presentTime;
00202 return;
00203 }
00204
00205 dt = 0.001*((float)(presentTime - lastTime));
00206
00207
00208
00209
00210
00211 tmpX = 30.0/(float)winX*x;
00212 tmpY = 20.0/(float)(winY-200)*y;
00213
00214 racket.location[0] = tmpX;
00215 racket.location[2] = tmpY;
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 lastTime = presentTime;
00232 return;
00233
00234
00235 if((GLint)(glutGet(GLUT_WINDOW_WIDTH)/2) > x)
00236 {
00237 racket.velocity[0]-=5;
00238 centerIt = 1;
00239 }
00240
00241 if((GLint)(glutGet(GLUT_WINDOW_WIDTH)/2) < x)
00242 {
00243 racket.velocity[0]+=5;
00244 centerIt = 1;
00245 }
00246
00247 if((GLint)(glutGet(GLUT_WINDOW_HEIGHT)/2) > y)
00248 {
00249 racket.velocity[2]-=4;
00250 centerIt = 1;
00251 }
00252
00253 if((GLint)(glutGet(GLUT_WINDOW_HEIGHT)/2) < y)
00254 {
00255 racket.velocity[2]+=4;
00256 centerIt = 1;
00257 }
00258
00259
00260
00261 }
00262
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303