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