bloboland

annotate 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
rev   line source
nuclear@0 1 #include "game.h"
nuclear@0 2 #include "opengl.h"
nuclear@1 3 #include "level.h"
nuclear@1 4 #include "renderer.h"
nuclear@1 5 #include "camera.h"
nuclear@1 6
nuclear@1 7 bool keystate[256];
nuclear@1 8 bool bnstate[16];
nuclear@1 9
nuclear@1 10 static Level *level;
nuclear@1 11 static Renderer *rend;
nuclear@1 12 static FpsCamera cam;
nuclear@0 13
nuclear@0 14 bool game_init()
nuclear@0 15 {
nuclear@1 16 printf("initializing OpenGL state\n");
nuclear@1 17 glEnable(GL_CULL_FACE);
nuclear@1 18 glEnable(GL_DEPTH_TEST);
nuclear@1 19 glEnable(GL_LIGHTING);
nuclear@1 20 glEnable(GL_LIGHT0);
nuclear@1 21
nuclear@1 22 printf("initializing renderer\n");
nuclear@1 23 rend = new Renderer;
nuclear@1 24 rend->init();
nuclear@1 25
nuclear@1 26 printf("generating level\n");
nuclear@1 27 level = new Level;
nuclear@1 28 level->generate();
nuclear@1 29
nuclear@1 30 cam.input_move(0, 2, 2);
nuclear@1 31 cam.input_rotate(0, M_PI / 5, 0);
nuclear@1 32
nuclear@0 33 return true;
nuclear@0 34 }
nuclear@0 35
nuclear@0 36 void game_shutdown()
nuclear@0 37 {
nuclear@1 38 delete rend;
nuclear@1 39 delete level;
nuclear@0 40 }
nuclear@0 41
nuclear@0 42 void game_iter(double dt)
nuclear@0 43 {
nuclear@1 44 float offs = 0.05 * dt;
nuclear@1 45 float dx = 0, dy = 0;
nuclear@1 46
nuclear@1 47 // handle key input
nuclear@1 48 if(keystate['w'] || keystate['W']) {
nuclear@1 49 dy -= offs;
nuclear@1 50 }
nuclear@1 51 if(keystate['s'] || keystate['S']) {
nuclear@1 52 dy += offs;
nuclear@1 53 }
nuclear@1 54 if(keystate['d'] || keystate['D']) {
nuclear@1 55 dx += offs;
nuclear@1 56 }
nuclear@1 57 if(keystate['a'] || keystate['A']) {
nuclear@1 58 dx -= offs;
nuclear@1 59 }
nuclear@1 60
nuclear@1 61 cam.input_move(dx, 0, dy);
nuclear@0 62 }
nuclear@0 63
nuclear@0 64 void game_render()
nuclear@0 65 {
nuclear@1 66 glMatrixMode(GL_MODELVIEW);
nuclear@1 67 glLoadIdentity();
nuclear@1 68
nuclear@1 69 float lpos[] = {-1, 1, 2, 0};
nuclear@1 70 glLightfv(GL_LIGHT0, GL_POSITION, lpos);
nuclear@1 71
nuclear@1 72 cam.use_inverse();
nuclear@1 73
nuclear@1 74 rend->render(level);
nuclear@0 75 }
nuclear@1 76
nuclear@1 77 void game_input_shoot(int bn)
nuclear@1 78 {
nuclear@1 79 }
nuclear@1 80
nuclear@1 81 void game_input_move(float x, float y, float z)
nuclear@1 82 {
nuclear@1 83 cam.input_move(x, y, z);
nuclear@1 84 }
nuclear@1 85
nuclear@1 86 void game_input_rot(float x, float y)
nuclear@1 87 {
nuclear@1 88 cam.input_rotate(x * 6.0, y * 6.0, 0);
nuclear@1 89 }