nuclear@0: #include "game.h" nuclear@0: #include "opengl.h" nuclear@1: #include "level.h" nuclear@1: #include "renderer.h" nuclear@1: #include "camera.h" nuclear@1: nuclear@1: bool keystate[256]; nuclear@1: bool bnstate[16]; nuclear@1: nuclear@1: static Level *level; nuclear@1: static Renderer *rend; nuclear@1: static FpsCamera cam; nuclear@0: nuclear@0: bool game_init() nuclear@0: { nuclear@1: printf("initializing OpenGL state\n"); nuclear@1: glEnable(GL_CULL_FACE); nuclear@1: glEnable(GL_DEPTH_TEST); nuclear@1: glEnable(GL_LIGHTING); nuclear@1: glEnable(GL_LIGHT0); nuclear@1: nuclear@1: printf("initializing renderer\n"); nuclear@1: rend = new Renderer; nuclear@1: rend->init(); nuclear@1: nuclear@1: printf("generating level\n"); nuclear@1: level = new Level; nuclear@1: level->generate(); nuclear@1: nuclear@1: cam.input_move(0, 2, 2); nuclear@1: cam.input_rotate(0, M_PI / 5, 0); nuclear@1: nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: void game_shutdown() nuclear@0: { nuclear@1: delete rend; nuclear@1: delete level; nuclear@0: } nuclear@0: nuclear@0: void game_iter(double dt) nuclear@0: { nuclear@1: float offs = 0.05 * dt; nuclear@1: float dx = 0, dy = 0; nuclear@1: nuclear@1: // handle key input nuclear@1: if(keystate['w'] || keystate['W']) { nuclear@1: dy -= offs; nuclear@1: } nuclear@1: if(keystate['s'] || keystate['S']) { nuclear@1: dy += offs; nuclear@1: } nuclear@1: if(keystate['d'] || keystate['D']) { nuclear@1: dx += offs; nuclear@1: } nuclear@1: if(keystate['a'] || keystate['A']) { nuclear@1: dx -= offs; nuclear@1: } nuclear@1: nuclear@1: cam.input_move(dx, 0, dy); nuclear@0: } nuclear@0: nuclear@0: void game_render() nuclear@0: { nuclear@1: glMatrixMode(GL_MODELVIEW); nuclear@1: glLoadIdentity(); nuclear@1: nuclear@1: float lpos[] = {-1, 1, 2, 0}; nuclear@1: glLightfv(GL_LIGHT0, GL_POSITION, lpos); nuclear@1: nuclear@1: cam.use_inverse(); nuclear@1: nuclear@1: rend->render(level); nuclear@0: } nuclear@1: nuclear@1: void game_input_shoot(int bn) nuclear@1: { nuclear@1: } nuclear@1: nuclear@1: void game_input_move(float x, float y, float z) nuclear@1: { nuclear@1: cam.input_move(x, y, z); nuclear@1: } nuclear@1: nuclear@1: void game_input_rot(float x, float y) nuclear@1: { nuclear@1: cam.input_rotate(x * 6.0, y * 6.0, 0); nuclear@1: }