intravenous
diff src/game.cc @ 3:94d4c60af435
some progress
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 22 Apr 2012 03:35:18 +0300 |
parents | 472c28b8b875 |
children | c6a6a64df6de |
line diff
1.1 --- a/src/game.cc Sat Apr 21 23:03:36 2012 +0300 1.2 +++ b/src/game.cc Sun Apr 22 03:35:18 2012 +0300 1.3 @@ -4,6 +4,7 @@ 1.4 #include "vein.h" 1.5 #include "ship.h" 1.6 #include "camera.h" 1.7 +#include "cockpit.h" 1.8 1.9 static Vein *vein; 1.10 static Ship ship; 1.11 @@ -19,20 +20,28 @@ 1.12 { 1.13 glEnable(GL_DEPTH_TEST); 1.14 glEnable(GL_CULL_FACE); 1.15 - glEnable(GL_LIGHTING); 1.16 - glEnable(GL_LIGHT0); 1.17 1.18 float lpos[] = {-1, 1, 1, 0}; 1.19 glLightfv(GL_LIGHT0, GL_POSITION, lpos); 1.20 1.21 - // initialize the only level (vein) 1.22 + // initialize the cockpit 1.23 + if(!cockpit_init()) { 1.24 + return false; 1.25 + } 1.26 + 1.27 + // initialize the only level 1.28 vein = new Vein; 1.29 + if(!vein->init()) { 1.30 + return false; 1.31 + } 1.32 1.33 return true; 1.34 } 1.35 1.36 void game_shutdown() 1.37 { 1.38 + delete vein; 1.39 + cockpit_destroy(); 1.40 exit(0); 1.41 } 1.42 1.43 @@ -54,19 +63,18 @@ 1.44 if(keystate['s'] || keystate['S']) { 1.45 ship.accelerate(-1.0 * dt); 1.46 } 1.47 - // XXX change to mouselook 1.48 if(keystate['d'] || keystate['D']) { 1.49 - ship.turn(-1.0 * dt, 0.0); 1.50 + ship.accelerate_side(1.0 * dt); 1.51 } 1.52 if(keystate['a'] || keystate['A']) { 1.53 - ship.turn(1.0 * dt, 0.0); 1.54 + ship.accelerate_side(-1.0 * dt); 1.55 } 1.56 - if(keystate['e'] || keystate['E']) { 1.57 + /*if(keystate['e'] || keystate['E']) { 1.58 ship.turn(0.0, 1.0 * dt); 1.59 } 1.60 if(keystate['c'] || keystate['C']) { 1.61 ship.turn(0.0, -1.0 * dt); 1.62 - } 1.63 + }*/ 1.64 1.65 ship.update(dt); 1.66 1.67 @@ -76,14 +84,20 @@ 1.68 void game_draw() 1.69 { 1.70 glMatrixMode(GL_MODELVIEW); 1.71 - dbgcam.use(); 1.72 1.73 if(dbg_inside) { 1.74 load_gl_matrix(ship.get_matrix().inverse()); 1.75 + } else { 1.76 + dbgcam.use(); 1.77 } 1.78 1.79 vein->draw(ship.get_position()); 1.80 - ship.dbg_draw(); 1.81 + 1.82 + if(!dbg_inside) { 1.83 + ship.dbg_draw(); 1.84 + } else { 1.85 + cockpit_draw(); 1.86 + } 1.87 } 1.88 1.89 void game_input_keyb(int key, int state) 1.90 @@ -96,6 +110,13 @@ 1.91 1.92 case '\b': 1.93 dbg_inside = !dbg_inside; 1.94 + if(dbg_inside) { 1.95 + glutPassiveMotionFunc(game_input_mmotion); 1.96 + glutSetCursor(GLUT_CURSOR_NONE); 1.97 + } else { 1.98 + glutPassiveMotionFunc(0); 1.99 + glutSetCursor(GLUT_CURSOR_INHERIT); 1.100 + } 1.101 break; 1.102 1.103 default: 1.104 @@ -122,15 +143,28 @@ 1.105 1.106 void game_input_mmotion(int x, int y) 1.107 { 1.108 + static bool ignore_next; 1.109 int dx = x - prev_x; 1.110 int dy = y - prev_y; 1.111 prev_x = x; 1.112 prev_y = y; 1.113 1.114 - if(bnstate[0]) { 1.115 - dbgcam.input_rotate(10.0 * dx / win_xsz, 10.0 * dy / win_ysz, 0); 1.116 + if(ignore_next) { 1.117 + ignore_next = false; 1.118 + return; 1.119 } 1.120 - if(bnstate[2]) { 1.121 - dbgcam.input_zoom(10.0 * dy / win_ysz); 1.122 + 1.123 + if(dbg_inside) { 1.124 + ship.turn((float)-dx / win_xsz, (float)-dy / win_ysz); 1.125 + 1.126 + ignore_next = true; 1.127 + glutWarpPointer(win_xsz / 2, win_ysz / 2); 1.128 + } else { 1.129 + if(bnstate[0]) { 1.130 + dbgcam.input_rotate(10.0 * dx / win_xsz, 10.0 * dy / win_ysz, 0); 1.131 + } 1.132 + if(bnstate[2]) { 1.133 + dbgcam.input_zoom(10.0 * dy / win_ysz); 1.134 + } 1.135 } 1.136 }