bloboland

diff src/game.cc @ 1:cfe68befb7cc

some progress
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 15 Dec 2012 23:43:03 +0200
parents e4818a3300b9
children 1757973feaed
line diff
     1.1 --- a/src/game.cc	Sat Dec 15 07:52:13 2012 +0200
     1.2 +++ b/src/game.cc	Sat Dec 15 23:43:03 2012 +0200
     1.3 @@ -1,19 +1,89 @@
     1.4  #include "game.h"
     1.5  #include "opengl.h"
     1.6 +#include "level.h"
     1.7 +#include "renderer.h"
     1.8 +#include "camera.h"
     1.9 +
    1.10 +bool keystate[256];
    1.11 +bool bnstate[16];
    1.12 +
    1.13 +static Level *level;
    1.14 +static Renderer *rend;
    1.15 +static FpsCamera cam;
    1.16  
    1.17  bool game_init()
    1.18  {
    1.19 +	printf("initializing OpenGL state\n");
    1.20 +	glEnable(GL_CULL_FACE);
    1.21 +	glEnable(GL_DEPTH_TEST);
    1.22 +	glEnable(GL_LIGHTING);
    1.23 +	glEnable(GL_LIGHT0);
    1.24 +
    1.25 +	printf("initializing renderer\n");
    1.26 +	rend = new Renderer;
    1.27 +	rend->init();
    1.28 +
    1.29 +	printf("generating level\n");
    1.30 +	level = new Level;
    1.31 +	level->generate();
    1.32 +
    1.33 +	cam.input_move(0, 2, 2);
    1.34 +	cam.input_rotate(0, M_PI / 5, 0);
    1.35 +
    1.36  	return true;
    1.37  }
    1.38  
    1.39  void game_shutdown()
    1.40  {
    1.41 +	delete rend;
    1.42 +	delete level;
    1.43  }
    1.44  
    1.45  void game_iter(double dt)
    1.46  {
    1.47 +	float offs = 0.05 * dt;
    1.48 +	float dx = 0, dy = 0;
    1.49 +
    1.50 +	// handle key input
    1.51 +	if(keystate['w'] || keystate['W']) {
    1.52 +		dy -= offs;
    1.53 +	}
    1.54 +	if(keystate['s'] || keystate['S']) {
    1.55 +		dy += offs;
    1.56 +	}
    1.57 +	if(keystate['d'] || keystate['D']) {
    1.58 +		dx += offs;
    1.59 +	}
    1.60 +	if(keystate['a'] || keystate['A']) {
    1.61 +		dx -= offs;
    1.62 +	}
    1.63 +
    1.64 +	cam.input_move(dx, 0, dy);
    1.65  }
    1.66  
    1.67  void game_render()
    1.68  {
    1.69 +	glMatrixMode(GL_MODELVIEW);
    1.70 +	glLoadIdentity();
    1.71 +
    1.72 +	float lpos[] = {-1, 1, 2, 0};
    1.73 +	glLightfv(GL_LIGHT0, GL_POSITION, lpos);
    1.74 +
    1.75 +	cam.use_inverse();
    1.76 +
    1.77 +	rend->render(level);
    1.78  }
    1.79 +
    1.80 +void game_input_shoot(int bn)
    1.81 +{
    1.82 +}
    1.83 +
    1.84 +void game_input_move(float x, float y, float z)
    1.85 +{
    1.86 +	cam.input_move(x, y, z);
    1.87 +}
    1.88 +
    1.89 +void game_input_rot(float x, float y)
    1.90 +{
    1.91 +	cam.input_rotate(x * 6.0, y * 6.0, 0);
    1.92 +}