Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: now its a beauty too, and it till moves… and its a beauty, did I already mentioned that…

File size: 3.9 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
44/* this is a singleton class to prevent dublicates */
45Orxonox* Orxonox::singleton_ref = 0;
46World* Orxonox::world = 0;
47InputOutput* Orxonox::io = 0;
48bool Orxonox::pause = false;
49
50
51Orxonox* Orxonox::getInstance (void)
52{
53  if (singleton_ref == NULL)
54    singleton_ref = new Orxonox();
55  return singleton_ref;
56}
57
58
59int Orxonox::globalInit (int argc, char** argv) 
60{
61  glutInit(&argc, argv);
62  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
63  glutInitWindowSize(500, 500);
64  glutInitWindowPosition(100, 100);
65  glutCreateWindow("orxOnox");
66  glShadeModel(GL_FLAT);
67  /* window event dispatchers */
68  glutDisplayFunc(display);
69  glutReshapeFunc(reshape);
70  glutKeyboardFunc(keyboard);
71}
72
73
74int Orxonox::menuInit (void)
75{
76  glClearColor(0.0, 0.0, 0.0, 0.0);
77}
78
79
80int Orxonox::gameInit (void) 
81{
82  glClearColor(0.0, 0.0, 0.0, 0.0);
83  world = new World;
84  Player* localPlayer = new Player;
85  io = new InputOutput(world, localPlayer);
86  (*world).addPlayer(localPlayer);
87  //  (*localPlayer).addIO(io);
88
89  glutSpecialFunc(specFunc); 
90
91  //for testing purps only
92  //testTheShit();
93  glutIdleFunc(continousRedraw);
94}
95
96
97void Orxonox::keyboard(unsigned char key, int x, int y)
98{
99  switch(key) {
100
101  case 'p':
102    if (pause) 
103      {
104        cout << "unset pause" << endl;
105        glutIdleFunc(continousRedraw);
106        pause = false;
107      }
108    else 
109      {
110        cout << "set pause" << endl;
111        glutIdleFunc(NULL);
112        pause = true;
113      }
114    break;
115  case 27:
116    exit(0);
117    break;
118  }
119}
120
121
122/**
123   \brief special keys function. called by glut
124   
125   Here are all special key function defined.
126*/
127void Orxonox::specFunc(int key, int x, int y)
128{
129  switch(key) {
130  case GLUT_KEY_UP:
131    cout << "key_up" << endl;
132    (*io).goUp();
133    break;
134  case GLUT_KEY_DOWN:
135    cout << "key_down" << endl;
136    (*io).goDown();
137    break;
138  case GLUT_KEY_RIGHT:
139    cout << "key_right" << endl;
140    (*io).goRight();
141    break;
142  case GLUT_KEY_LEFT:
143    cout << "key_left" << endl;
144    (*io).goLeft();
145    break;
146  }
147}
148
149
150void Orxonox::display() 
151{
152  glClear(GL_COLOR_BUFFER_BIT);
153  (*world).drawWorld();
154  glutSwapBuffers();
155} 
156
157
158void Orxonox::continousRedraw()
159{
160  glutPostRedisplay();
161}
162
163
164void Orxonox::reshape (int w, int h)
165{
166  glViewport(0, 0, (GLsizei) w, (GLsizei) h);
167  glMatrixMode(GL_PROJECTION);
168  glLoadIdentity();
169  glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
170  glMatrixMode(GL_MODELVIEW);
171  glLoadIdentity(); //pb why a second time?
172}
173
174
175void Orxonox::testTheShit() 
176{
177  Player* pl = new Player;
178  (*pl).setPosition(1, 1, 1);
179  (*world).addPlayer(pl);
180 
181  //NPC* nl = new NPC;
182  //(*world).addNPC(nl);
183  //(*world).addNPC(nl);
184  //(*world).addNPC(nl);
185  //(*world).addNPC(nl);
186  //(*world).addNPC(nl);
187  //(*world).addNPC(nl);
188  //(*world).testThaTest();
189}
190
191
192int main (int argc, char** argv) 
193{ 
194  Orxonox *orx = Orxonox::getInstance();
195  (*orx).globalInit(argc, argv);
196  //(*orx).menuInit(); pb: directly jump to the game, no menu
197  (*orx).gameInit();
198
199  glutMainLoop(); 
200  return 0;
201}
Note: See TracBrowser for help on using the repository browser.