Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: added ability to shoot. so check out the new release and shoot the fuck up

File size: 5.6 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::alpha = 0;
59int Orxonox::beta = 0;
60//int Orxonox::offsetX = 0;
61//int Orxonox::offsetY = 0;
62
63Orxonox* Orxonox::getInstance (void)
64{
65  if (singleton_ref == NULL)
66    singleton_ref = new Orxonox();
67  return singleton_ref;
68}
69
70
71int Orxonox::globalInit (int argc, char** argv) 
72{
73  glutInit(&argc, argv);
74  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
75  glEnable(GL_DEPTH_TEST);
76  glutInitWindowSize(500, 500);
77  //glutFullScreen();
78  glutInitWindowPosition(100, 100);
79  glutCreateWindow("orxOnox");
80  glShadeModel(GL_FLAT);
81  /* window event dispatchers */
82  glutDisplayFunc(display);
83  glutReshapeFunc(reshape);
84  glutKeyboardFunc(keyboard);
85  glutKeyboardUpFunc(upKeyboard);
86}
87
88
89int Orxonox::menuInit (void)
90{
91  glClearColor(0.0, 0.0, 0.0, 0.0);
92}
93
94
95int Orxonox::gameInit (void) 
96{
97  glClearColor(0.0, 0.0, 0.0, 0.0);
98  world = new World;
99  (*world).initEnvironement();
100  localPlayer = new Player;
101  io = new InputOutput(world, localPlayer);
102  (*world).addPlayer(localPlayer);
103  Environment *env = new Environment;
104  (*world).addEnv(env);
105
106  glutSpecialFunc(specFunc); 
107  glutSpecialUpFunc(releaseKey);
108
109  glutIdleFunc(continousRedraw);
110  //cout << "Orxonox::gameInit" << endl;
111}
112
113
114void Orxonox::keyboard(unsigned char key, int x, int y)
115{
116  switch(key) {
117
118    /* perspectiv control */
119  case 'w':
120    beta -= 1;
121    break;
122  case 's':
123    beta += 1;
124    break;
125  case 'a':
126    alpha -= 1;
127    break;
128  case 'd':
129    alpha += 1;
130    break;
131
132    /* game controls */
133  case 'p':
134    if (pause) 
135      {
136        cout << "unset pause" << endl;
137        glutIdleFunc(continousRedraw);
138        pause = false;
139      }
140    else 
141      {
142        cout << "set pause" << endl;
143        glutIdleFunc(NULL);
144        pause = true;
145      }
146    break;
147  case 32:
148    shoot1 = true;
149    break;
150  case 27:
151  case 'q':
152    quitGame();
153    break;
154  }
155}
156
157
158void Orxonox::upKeyboard(unsigned char key, int x, int y) 
159{
160  switch(key) {
161  case 32:
162    shoot1 = false;
163    break;
164  }
165}
166
167
168void Orxonox::quitGame() 
169{
170  //cout << "finished garbage colletion, quitting..." << endl;
171  exit(0);
172}
173
174
175void Orxonox::releaseKey(int key, int x, int y) 
176{ 
177  switch(key) {
178  case GLUT_KEY_UP:
179    upWeGo = false;
180    break;
181  case GLUT_KEY_DOWN:
182    downWeGo = false;
183    break;
184  case GLUT_KEY_RIGHT:
185    rightWeGo = false;
186    break;
187  case GLUT_KEY_LEFT:
188    leftWeGo = false;
189    break;
190  }
191}
192
193
194/**
195   \brief special keys function. called by glut
196   
197   Here are all special key function defined.
198*/
199void Orxonox::specFunc(int key, int x, int y)
200{
201  switch(key) {
202    /* spacecraft controls */
203  case GLUT_KEY_UP:
204    upWeGo = true;
205    break;
206  case GLUT_KEY_DOWN:
207    downWeGo = true;
208    break;
209  case GLUT_KEY_RIGHT:
210    rightWeGo = true;
211    break;
212  case GLUT_KEY_LEFT:
213    leftWeGo = true;
214    break;
215  }
216}
217
218
219void Orxonox::display() 
220{
221  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
222
223  glColor3f(0.0, 0.5, 0.6);
224  glLoadIdentity();
225  gluLookAt(0.0, -14.0, 15.0, 0.0 + alpha, 0.0 + beta, 0.0, 0.0, 1.0, 0.0);
226  (*world).drawWorld();
227
228  glutSwapBuffers();
229} 
230
231
232void Orxonox::continousRedraw()
233{
234  /* check for input to pass it over */
235  if ( !pause && (rightWeGo || leftWeGo || upWeGo || downWeGo || shoot1)) {
236    if (upWeGo)
237      (*io).goUp();
238    if (downWeGo)
239      (*io).goDown();
240    if (rightWeGo)
241      (*io).goRight();
242    if (leftWeGo)
243      (*io).goLeft();
244    if (shoot1) 
245      (*io).shoot();
246  }
247  /* request repaint */
248  glutPostRedisplay();
249  //cout << "Orxonox::continousRedraw" << endl;
250}
251
252
253void Orxonox::reshape (int w, int h)
254{
255  glViewport(0, 0, (GLsizei) w, (GLsizei) h);
256  glMatrixMode(GL_PROJECTION);
257  glLoadIdentity();
258  glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 200.0);
259  glMatrixMode(GL_MODELVIEW);
260  glLoadIdentity(); //pb why a second time?
261}
262
263
264void Orxonox::testTheShit() 
265{
266  //Player* pl = new Player;
267  //(*pl).setPosition(1, 1, 1);
268  //(*world).addPlayer(pl);
269 
270  //NPC* nl = new NPC;
271  //(*world).addNPC(nl);
272  //(*world).addNPC(nl);
273  //(*world).addNPC(nl);
274  //(*world).addNPC(nl);
275  //(*world).addNPC(nl);
276  //(*world).addNPC(nl);
277  //(*world).testThaTest();
278}
279
280
281int main (int argc, char** argv) 
282{ 
283  Orxonox *orx = Orxonox::getInstance();
284  (*orx).globalInit(argc, argv);
285  //(*orx).menuInit(); pb: directly jump to the game, no menu
286  (*orx).gameInit();
287
288  glutMainLoop(); 
289  return 0;
290}
Note: See TracBrowser for help on using the repository browser.