intravenous

diff src/game.cc @ 6:2723dc026c4f

collision detection
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 23 Apr 2012 21:43:10 +0300
parents aab0d8ea21cd
children 90af225f469a
line diff
     1.1 --- a/src/game.cc	Sun Apr 22 06:26:08 2012 +0300
     1.2 +++ b/src/game.cc	Mon Apr 23 21:43:10 2012 +0300
     1.3 @@ -6,10 +6,10 @@
     1.4  #include "camera.h"
     1.5  #include "cockpit.h"
     1.6  
     1.7 -static const Vector3 fog_color{0.64, 0.1, 0.1};
     1.8 +static const Vector3 fog_color(0.64, 0.1, 0.1);
     1.9  
    1.10  static Vein *vein;
    1.11 -static Ship ship;
    1.12 +static Ship *ship;
    1.13  
    1.14  static int keystate[256];
    1.15  static int dbg_inside = false;
    1.16 @@ -39,6 +39,9 @@
    1.17  	}
    1.18  	vein->set_fog_color(fog_color);
    1.19  
    1.20 +	// create the player's ship
    1.21 +	ship = new Ship(vein);
    1.22 +
    1.23  	glClearColor(fog_color.x, fog_color.y, fog_color.z, 1);
    1.24  
    1.25  	return true;
    1.26 @@ -64,25 +67,19 @@
    1.27  
    1.28  	// handle key input
    1.29  	if(keystate['w'] || keystate['W']) {
    1.30 -		ship.accelerate(1.0 * dt);
    1.31 +		ship->accelerate(1.0 * dt);
    1.32  	}
    1.33  	if(keystate['s'] || keystate['S']) {
    1.34 -		ship.accelerate(-1.0 * dt);
    1.35 +		ship->accelerate(-1.0 * dt);
    1.36  	}
    1.37  	if(keystate['d'] || keystate['D']) {
    1.38 -		ship.accelerate_side(1.0 * dt);
    1.39 +		ship->accelerate_side(1.0 * dt);
    1.40  	}
    1.41  	if(keystate['a'] || keystate['A']) {
    1.42 -		ship.accelerate_side(-1.0 * dt);
    1.43 +		ship->accelerate_side(-1.0 * dt);
    1.44  	}
    1.45 -	/*if(keystate['e'] || keystate['E']) {
    1.46 -		ship.turn(0.0, 1.0 * dt);
    1.47 -	}
    1.48 -	if(keystate['c'] || keystate['C']) {
    1.49 -		ship.turn(0.0, -1.0 * dt);
    1.50 -	}*/
    1.51  
    1.52 -	ship.update(dt);
    1.53 +	ship->update(dt);
    1.54  
    1.55  	last_upd = msec;
    1.56  }
    1.57 @@ -92,15 +89,15 @@
    1.58  	glMatrixMode(GL_MODELVIEW);
    1.59  
    1.60  	if(dbg_inside) {
    1.61 -		load_gl_matrix(ship.get_matrix().inverse());
    1.62 +		load_gl_matrix(ship->get_matrix().inverse());
    1.63  	} else {
    1.64  		dbgcam.use();
    1.65  	}
    1.66  
    1.67 -	vein->draw(ship.get_position());
    1.68 +	vein->draw(ship->get_position());
    1.69  
    1.70  	if(!dbg_inside) {
    1.71 -		ship.dbg_draw();
    1.72 +		ship->dbg_draw();
    1.73  	} else {
    1.74  		cockpit_draw();
    1.75  	}
    1.76 @@ -115,6 +112,7 @@
    1.77  			break;
    1.78  
    1.79  		case '\b':
    1.80 +		case 127:
    1.81  			dbg_inside = !dbg_inside;
    1.82  			if(dbg_inside) {
    1.83  				glutPassiveMotionFunc(game_input_mmotion);
    1.84 @@ -163,7 +161,7 @@
    1.85  	}
    1.86  
    1.87  	if(dbg_inside) {
    1.88 -		ship.turn((float)-dx / win_xsz, (float)-dy / win_ysz);
    1.89 +		ship->turn((float)-dx / win_xsz, (float)-dy / win_ysz);
    1.90  
    1.91  		ignore_next_motion = true;
    1.92  		glutWarpPointer(win_xsz / 2, win_ysz / 2);