Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/core/orxonox.cc @ 1899

Last change on this file since 1899 was 1899, checked in by patrick, 20 years ago

trunk/orxonox: collision detection implemented: simple spheres. all debug informations still print out to console. one enemy added, no AI, no move, waits to be killed. No kill signal implemented yet: look debug infos on console.

File size: 6.1 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software Foundation,
18   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
19
20
21   ### File Specific:
22   main-programmer: Patrick Boenzli
23   co-programmer:
24*/
25
26/* class definition header */
27#include "orxonox.h"
28
29
30using namespace std;
31
32
33
34Orxonox::Orxonox () 
35{
36  pause = false;
37}
38
39
40
41Orxonox::~Orxonox () 
42{
43  glutSetKeyRepeat(GLUT_KEY_REPEAT_ON);
44}
45
46
47/* this is a singleton class to prevent dublicates */
48Orxonox* Orxonox::singleton_ref = 0;
49World* Orxonox::world = 0;
50InputOutput* Orxonox::io = 0;
51Player* Orxonox::localPlayer = 0;
52bool Orxonox::pause = false;
53bool Orxonox::upWeGo = false;
54bool Orxonox::downWeGo = false;
55bool Orxonox::rightWeGo = false;
56bool Orxonox::leftWeGo = false;
57bool Orxonox::shoot1 = false;
58int Orxonox::fps = 0;
59int Orxonox::alpha = 0;
60int Orxonox::beta = 0;
61//int Orxonox::offsetX = 0;
62//int Orxonox::offsetY = 0;
63
64Orxonox* Orxonox::getInstance (void)
65{
66  if (singleton_ref == NULL)
67    singleton_ref = new Orxonox();
68  return singleton_ref;
69}
70
71
72int Orxonox::globalInit (int argc, char** argv) 
73{
74  glutInit(&argc, argv);
75  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
76  glEnable(GL_DEPTH_TEST);
77  glutInitWindowSize(500, 500);
78  //glutFullScreen();
79  glutInitWindowPosition(100, 100);
80  glutCreateWindow("orxOnox");
81  glShadeModel(GL_FLAT);
82  /* window event dispatchers */
83  glutDisplayFunc(display);
84  glutReshapeFunc(reshape);
85  glutKeyboardFunc(keyboard);
86  glutKeyboardUpFunc(upKeyboard);
87
88  glutTimerFunc(1000, timeSlice, 0);
89}
90
91
92int Orxonox::menuInit (void)
93{
94  glClearColor(0.0, 0.0, 0.0, 0.0);
95}
96
97
98int Orxonox::gameInit (void) 
99{
100  glClearColor(0.0, 0.0, 0.0, 0.0);
101 
102  /* world init, shouldnt be done here later */
103  world = new World;
104  (*world).initEnvironement();
105  localPlayer = new Player;
106  localPlayer->setPosition(0.0, -10.0, 3.0);
107  io = new InputOutput(world, localPlayer);
108  (*world).addPlayer(localPlayer);
109  Environment *env = new Environment;
110  (*world).addEnv(env);
111  NPC* npc = new NPC;
112  npc->setPosition(3.0, 0.0, 3.0);
113  npc->setCollisionRadius(1.0);
114  world->addNPC(npc);
115
116  glutSpecialFunc(specFunc); 
117  glutSpecialUpFunc(releaseKey);
118
119  glutIdleFunc(continousRedraw);
120  //cout << "Orxonox::gameInit" << endl;
121}
122
123
124/* this is the time triggered function. heart beat*/
125
126void Orxonox::timeSlice(int value)
127{
128  cout << "fps: " << fps << endl;
129  fps = 0;
130  glutTimerFunc(1000, timeSlice, 0);
131}
132
133
134
135void Orxonox::keyboard(unsigned char key, int x, int y)
136{
137  switch(key) {
138
139    /* perspectiv control */
140  case 'w':
141    beta -= 1;
142    break;
143  case 's':
144    beta += 1;
145    break;
146  case 'a':
147    alpha -= 1;
148    break;
149  case 'd':
150    alpha += 1;
151    break;
152
153    /* game controls */
154  case 'p':
155    if (pause) 
156      {
157        cout << "unset pause" << endl;
158        glutIdleFunc(continousRedraw);
159        pause = false;
160      }
161    else 
162      {
163        cout << "set pause" << endl;
164        glutIdleFunc(NULL);
165        pause = true;
166      }
167    break;
168  case 32:
169    shoot1 = true;
170    break;
171  case 27:
172  case 'q':
173    quitGame();
174    break;
175  }
176}
177
178
179void Orxonox::upKeyboard(unsigned char key, int x, int y) 
180{
181  switch(key) {
182  case 32:
183    shoot1 = false;
184    break;
185  }
186}
187
188
189void Orxonox::quitGame() 
190{
191  //cout << "finished garbage colletion, quitting..." << endl;
192  exit(0);
193}
194
195
196void Orxonox::releaseKey(int key, int x, int y) 
197{ 
198  switch(key) {
199  case GLUT_KEY_UP:
200    upWeGo = false;
201    break;
202  case GLUT_KEY_DOWN:
203    downWeGo = false;
204    break;
205  case GLUT_KEY_RIGHT:
206    rightWeGo = false;
207    break;
208  case GLUT_KEY_LEFT:
209    leftWeGo = false;
210    break;
211  }
212}
213
214
215/**
216   \brief special keys function. called by glut
217   
218   Here are all special key function defined.
219*/
220void Orxonox::specFunc(int key, int x, int y)
221{
222  switch(key) {
223    /* spacecraft controls */
224  case GLUT_KEY_UP:
225    upWeGo = true;
226    break;
227  case GLUT_KEY_DOWN:
228    downWeGo = true;
229    break;
230  case GLUT_KEY_RIGHT:
231    rightWeGo = true;
232    break;
233  case GLUT_KEY_LEFT:
234    leftWeGo = true;
235    break;
236  }
237}
238
239
240void Orxonox::display() 
241{
242  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
243
244  glColor3f(0.0, 0.5, 0.6);
245  glLoadIdentity();
246  gluLookAt(0.0, -14.0, 15.0, 0.0 + alpha, 0.0 + beta, 0.0, 0.0, 1.0, 0.0);
247  (*world).drawWorld();
248
249  glutSwapBuffers();
250} 
251
252
253void Orxonox::continousRedraw()
254{
255  /* increment the frames-per-second counter*/
256  fps++;
257  /* check for collisions */
258  world->detectCollision();
259
260  /* check for input to pass it over */
261  if ( !pause && (rightWeGo || leftWeGo || upWeGo || downWeGo || shoot1)) {
262    if (upWeGo)
263      (*io).goUp();
264    if (downWeGo)
265      (*io).goDown();
266    if (rightWeGo)
267      (*io).goRight();
268    if (leftWeGo)
269      (*io).goLeft();
270    if (shoot1) 
271      (*io).shoot();
272  }
273  /* request repaint */
274  glutPostRedisplay();
275  //cout << "Orxonox::continousRedraw" << endl;
276}
277
278
279void Orxonox::reshape (int w, int h)
280{
281  glViewport(0, 0, (GLsizei) w, (GLsizei) h);
282  glMatrixMode(GL_PROJECTION);
283  glLoadIdentity();
284  glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 200.0);
285  glMatrixMode(GL_MODELVIEW);
286  glLoadIdentity(); //pb why a second time?
287}
288
289
290void Orxonox::testTheShit() 
291{
292  //Player* pl = new Player;
293  //(*pl).setPosition(1, 1, 1);
294  //(*world).addPlayer(pl);
295 
296  //NPC* nl = new NPC;
297  //(*world).addNPC(nl);
298  //(*world).addNPC(nl);
299  //(*world).addNPC(nl);
300  //(*world).addNPC(nl);
301  //(*world).addNPC(nl);
302  //(*world).addNPC(nl);
303  //(*world).testThaTest();
304}
305
306
307int main (int argc, char** argv) 
308{ 
309  Orxonox *orx = Orxonox::getInstance();
310  (*orx).globalInit(argc, argv);
311  //(*orx).menuInit(); pb: directly jump to the game, no menu
312  (*orx).gameInit();
313
314  glutMainLoop(); 
315  return 0;
316}
Note: See TracBrowser for help on using the repository browser.