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 | |
---|
30 | using namespace std; |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | Orxonox::Orxonox () |
---|
35 | { |
---|
36 | pause = false; |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | Orxonox::~Orxonox () {} |
---|
42 | |
---|
43 | |
---|
44 | /* this is a singleton class to prevent dublicates */ |
---|
45 | Orxonox* Orxonox::singleton_ref = 0; |
---|
46 | World* Orxonox::world = 0; |
---|
47 | InputOutput* Orxonox::io = 0; |
---|
48 | bool Orxonox::pause = false; |
---|
49 | |
---|
50 | |
---|
51 | Orxonox* Orxonox::getInstance (void) |
---|
52 | { |
---|
53 | if (singleton_ref == NULL) |
---|
54 | singleton_ref = new Orxonox(); |
---|
55 | return singleton_ref; |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | int Orxonox::globalInit (int argc, char** argv) |
---|
60 | { |
---|
61 | glutInit(&argc, argv); |
---|
62 | glutInitDisplayMode(GLUT_SINGLE | 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 | |
---|
74 | int Orxonox::menuInit (void) |
---|
75 | { |
---|
76 | glClearColor(0.0, 0.0, 0.0, 0.0); |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | int 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 | } |
---|
94 | |
---|
95 | |
---|
96 | void Orxonox::keyboard(unsigned char key, int x, int y) |
---|
97 | { |
---|
98 | switch(key) { |
---|
99 | |
---|
100 | case 'p': |
---|
101 | if (pause) |
---|
102 | { |
---|
103 | cout << "unset pause" << endl; |
---|
104 | glutIdleFunc(continousRedraw); |
---|
105 | pause = false; |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | cout << "set pause" << endl; |
---|
110 | glutIdleFunc(NULL); |
---|
111 | pause = true; |
---|
112 | } |
---|
113 | break; |
---|
114 | case 27: |
---|
115 | exit(0); |
---|
116 | break; |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | /** |
---|
122 | \brief special keys function. called by glut |
---|
123 | |
---|
124 | Here are all special key function defined. |
---|
125 | */ |
---|
126 | void Orxonox::specFunc(int key, int x, int y) |
---|
127 | { |
---|
128 | switch(key) { |
---|
129 | case GLUT_KEY_UP: |
---|
130 | cout << "key_up" << endl; |
---|
131 | (*io).goUp(); |
---|
132 | break; |
---|
133 | case GLUT_KEY_DOWN: |
---|
134 | cout << "key_down" << endl; |
---|
135 | (*io).goDown(); |
---|
136 | break; |
---|
137 | case GLUT_KEY_RIGHT: |
---|
138 | cout << "key_right" << endl; |
---|
139 | (*io).goRight(); |
---|
140 | break; |
---|
141 | case GLUT_KEY_LEFT: |
---|
142 | cout << "key_left" << endl; |
---|
143 | (*io).goLeft(); |
---|
144 | break; |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | void Orxonox::display() |
---|
150 | { |
---|
151 | glClear(GL_COLOR_BUFFER_BIT); |
---|
152 | (*world).drawWorld(); |
---|
153 | glutSwapBuffers(); |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | void Orxonox::continousRedraw() |
---|
158 | { |
---|
159 | glutPostRedisplay(); |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | void Orxonox::reshape (int w, int h) |
---|
164 | { |
---|
165 | glViewport(0, 0, (GLsizei) w, (GLsizei) h); |
---|
166 | glMatrixMode(GL_PROJECTION); |
---|
167 | glLoadIdentity(); |
---|
168 | glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0); |
---|
169 | glMatrixMode(GL_MODELVIEW); |
---|
170 | glLoadIdentity(); //pb why a second time? |
---|
171 | } |
---|
172 | |
---|
173 | |
---|
174 | void Orxonox::testTheShit() |
---|
175 | { |
---|
176 | Player* pl = new Player; |
---|
177 | (*pl).setPosition(1, 1, 1); |
---|
178 | (*world).addPlayer(pl); |
---|
179 | |
---|
180 | //NPC* nl = new NPC; |
---|
181 | //(*world).addNPC(nl); |
---|
182 | //(*world).addNPC(nl); |
---|
183 | //(*world).addNPC(nl); |
---|
184 | //(*world).addNPC(nl); |
---|
185 | //(*world).addNPC(nl); |
---|
186 | //(*world).addNPC(nl); |
---|
187 | //(*world).testThaTest(); |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | int main (int argc, char** argv) |
---|
192 | { |
---|
193 | Orxonox *orx = Orxonox::getInstance(); |
---|
194 | (*orx).globalInit(argc, argv); |
---|
195 | //(*orx).menuInit(); pb: directly jump to the game, no menu |
---|
196 | (*orx).gameInit(); |
---|
197 | |
---|
198 | glutMainLoop(); |
---|
199 | return 0; |
---|
200 | } |
---|