bloboland

diff src/game.cc @ 4:9021a906c5d3

lots of stuff
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 18 Dec 2012 06:13:09 +0200
parents a39c301cdcce
children 2f4406cc341e
line diff
     1.1 --- a/src/game.cc	Sun Dec 16 14:24:16 2012 +0200
     1.2 +++ b/src/game.cc	Tue Dec 18 06:13:09 2012 +0200
     1.3 @@ -20,6 +20,9 @@
     1.4  static Renderer *rend;
     1.5  static FpsCamera cam;
     1.6  
     1.7 +static const float fog_color[] = {0.76, 0.64, 0.91, 1.0};
     1.8 +static Vector3 gravity;
     1.9 +
    1.10  bool game_init()
    1.11  {
    1.12  	printf("initializing OpenGL state\n");
    1.13 @@ -33,6 +36,7 @@
    1.14  
    1.15  	printf("generating level\n");
    1.16  	level = new Level;
    1.17 +	level->world_size = Vector3(8, 8, 4);
    1.18  	level->generate();
    1.19  
    1.20  	printf("initializing renderer\n");
    1.21 @@ -44,6 +48,11 @@
    1.22  	cam.input_move(0, 2, 2);
    1.23  	cam.input_rotate(0, M_PI / 5, 0);
    1.24  
    1.25 +	glClearColor(fog_color[0], fog_color[1], fog_color[2], 1.0);
    1.26 +	glFogfv(GL_FOG_COLOR, fog_color);
    1.27 +
    1.28 +	gravity = Vector3(0, -0.01, 0);
    1.29 +
    1.30  	return true;
    1.31  }
    1.32  
    1.33 @@ -73,6 +82,18 @@
    1.34  	}
    1.35  
    1.36  	cam.input_move(dx, 0, dy);
    1.37 +
    1.38 +	for(size_t i=0; i<level->blobs.size(); i++) {
    1.39 +		Blob *b = &level->blobs[i];
    1.40 +
    1.41 +		b->velocity += gravity * dt;
    1.42 +		Vector3 npos = b->pos + b->velocity * dt;
    1.43 +
    1.44 +		Vector3 normal;
    1.45 +		if(level->collision(b->pos, npos, &npos, &normal)) {
    1.46 +			b->velocity = b->velocity.reflection(normal);
    1.47 +		}
    1.48 +	}
    1.49  }
    1.50  
    1.51  void game_render()
    1.52 @@ -81,6 +102,7 @@
    1.53  
    1.54  	if(opt.stereo) {
    1.55  		glDrawBuffer(GL_BACK_LEFT);
    1.56 +		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.57  
    1.58  		glMatrixMode(GL_PROJECTION);
    1.59  		glLoadIdentity();
    1.60 @@ -92,6 +114,7 @@
    1.61  		rend->render();
    1.62  
    1.63  		glDrawBuffer(GL_BACK_RIGHT);
    1.64 +		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.65  
    1.66  		glMatrixMode(GL_PROJECTION);
    1.67  		glLoadIdentity();
    1.68 @@ -102,6 +125,8 @@
    1.69  
    1.70  		rend->render();
    1.71  	} else {
    1.72 +		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.73 +
    1.74  		glMatrixMode(GL_PROJECTION);
    1.75  		glLoadIdentity();
    1.76  		proj_matrix(0);