Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/core/world.cc @ 1917

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

orxonox/trunk: ground moves

File size: 6.9 KB
Line 
1
2/*
3   orxonox - the future of 3D-vertical-scrollers
4
5   Copyright (C) 2004 orx
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12   ### File Specific:
13   main-programmer: Patrick Boenzli
14   co-programmer:
15*/
16
17
18#include "world.h"
19
20#include <iostream>
21
22using namespace std;
23
24
25/**
26   \brief Create a new World
27   
28   This creates a new empty world!
29*/
30World::World () {
31  lastPlayer = null;
32  lastNPC = null;
33  lastEnv = null;
34  primitiveMove = 0;
35}
36
37
38World::~World () {}
39
40
41/**
42   \brief Add Player
43   \param player A reference to the new player object
44   
45   Add a new Player to the game. Player has to be initialised previously
46*/
47bool World::addPlayer(Player* player) 
48{
49  playerList* listMember = new playerList;
50  listMember->player = player;
51  if ( lastPlayer != null ) 
52    {
53      listMember->number = lastPlayer->number + 1;
54      listMember->next = lastPlayer;
55    }
56  else 
57    {
58      listMember->number = 0;
59      listMember->next = null;
60    }
61  lastPlayer = listMember;
62}
63
64
65/**
66   \brief Remove Player
67   \param player A reference to the new npc object
68   
69   Remove a new Player to the game.
70*/
71bool World::removePlayer(Player* player) {
72  cout << "World::removeNPC not implemented yet" << endl;
73}
74
75Player* World::getLocalPlayer() 
76{
77  return localPlayer;
78}
79
80
81/**
82   \brief Add Non-Player-Character
83   \param player A reference to the new npc object
84   
85   Add a new Non-Player-Character to the game. Player has to be initialised previously
86*/
87bool World::addNPC(NPC* npc) 
88{
89  npcList* listMember = new npcList;
90  listMember->npc = npc;
91  if ( lastNPC != null ) 
92    {
93      listMember->number = lastNPC->number + 1;
94      listMember->next = lastNPC;
95    }
96  else 
97    {
98      listMember->number = 0;
99      listMember->next = null;
100    }
101  lastNPC = listMember;
102}
103
104
105/**
106   \brief Add environmental object
107   \param player A reference to the new env object
108   
109   Add a new Environment to the world. Env has to be initialised before.
110*/
111bool World::addEnv(Environment* env) 
112{
113  envList* listMember = new envList;
114  listMember->env = env;
115  if ( lastEnv != null ) 
116    {
117      listMember->number = lastEnv->number + 1;
118      listMember->next = lastEnv;
119    }
120  else 
121    {
122      listMember->number = 0;
123      listMember->next = null;
124    }
125  lastEnv = listMember;
126}
127
128
129
130
131
132/**
133   \brief Remove Non-Player Character
134   \param player A reference to the new npc object
135   
136   Remove a new Non-Player-Character to the game.
137*/
138bool World::removeNPC(NPC* npc) {
139  cout << "World::removeNPC not implemented yet" << endl;
140}
141
142
143
144/**
145   \brief Draws the World and all Objects contained
146   
147   Calls the draw function of all: Objects, Players, Environement. This is the core of all graphics here.
148*/
149void World::drawWorld(void) 
150{
151  /* first draw all players */
152  playerList* tmpPlayer = lastPlayer;
153  Player* player = tmpPlayer->player;
154  while( tmpPlayer != null ) 
155    {
156      (*tmpPlayer->player).drawPlayer();
157      tmpPlayer = tmpPlayer->next;
158    }
159  /* second draw all npcs */
160  npcList* tmpNPC = lastNPC;
161  while( tmpNPC != null )
162    {
163      (*tmpNPC->npc).drawNPC();
164      tmpNPC = tmpNPC->next;
165    }
166
167  glPushMatrix();
168  glTranslatef(0.0, -primitiveMove, 0.0);
169
170  /* now draw the rest of the world: environement */
171  envList* tmpEnv = lastEnv;
172  while( tmpEnv != null )
173    {
174      (*tmpEnv->env).drawEnvironment();
175      tmpEnv = tmpEnv->next;
176    }
177 
178 
179  /* draw the ground grid  */
180  glColor3f(0.0, 1.0, 0.0); 
181  glBegin(GL_LINES);
182  /* for the moment, we've got only pseudo moving ground */
183 for (int y = 0; y < 60; y += 2)
184    {
185      for (int x = 0; x < 60; x += 2)
186        {
187          glVertex3f((float)(x - 30), (float)(y - 30), surface[x][y]);
188          glVertex3f((float)(x - 28), (float)(y - 30), surface[x+2][y]);
189        }
190    }
191 glEnd();
192  glPopMatrix();
193 
194  glBegin(GL_LINES);
195  for (int x = 0; x < 60; x += 2)
196    {
197      for (int y = 0; y < 60; y += 2)
198        {
199          glVertex3f((float)(x - 30), (float)(y - 30), surface[x][y]);
200          glVertex3f((float)(x - 30), (float)(y - 28), surface[x][y+2]);
201        }
202    }
203  glEnd();
204
205
206  primitiveMove+=0.1;
207}
208
209
210void World::initEnvironement()
211{
212
213 for (int x = 0; x < 60; x += 2)
214    {
215      for (int y = 0; y < 60; y += 2)
216        {
217          surface[x][y] = 0;
218        }
219    }
220}
221
222
223/**
224   \brief Updates the world and all its objects
225   
226   Calculates the new state of the world. User-input and AI of
227   the enemies are accounted for.
228*/
229void World::updateWorld(void) 
230{
231 
232
233}
234
235
236/* collision detection */
237/* fix: bad efficency: stupid brute force */
238
239void World::detectCollision() 
240{
241  //cout << "World::detectCollision" << endl;
242  float xOff, yOff, zOff, radius;
243  npcList* tmpNPC;
244
245  //cout << "World::detectCollsions" << endl;
246  /* first: check if any player's shoots trigger a collision */
247  playerList* tmpPlayer = lastPlayer;
248  Player* player = tmpPlayer->player;
249  while( tmpPlayer != null ) 
250    {
251      tmpNPC = lastNPC;
252      while( tmpNPC != null )
253        {
254          radius = tmpNPC->npc->collisionRadius;
255          ShootLaser::shoot* shoota = tmpPlayer->player->shootLaser->lastShoot;
256          while( shoota != null )
257            {
258              xOff = shoota->xCor - tmpNPC->npc->xCor;
259              yOff = shoota->yCor - tmpNPC->npc->yCor;
260              zOff = shoota->zCor - tmpNPC->npc->zCor;
261              if ( sqrt(xOff*xOff + yOff*yOff + zOff*zOff) < radius )
262                cout << "COLLISION " << endl;
263              shoota = shoota->next;
264            }
265          tmpNPC = tmpNPC->next;
266        }
267     
268      tmpPlayer = tmpPlayer->next;
269    }
270
271  /* second: check if any player hits an enemy */
272
273 
274  tmpPlayer = lastPlayer;
275  while( tmpPlayer != null ) 
276    {
277      tmpNPC = lastNPC;
278      while( tmpNPC != null )
279        {
280          radius = tmpNPC->npc->collisionRadius + tmpPlayer->player->collisionRadius;
281          xOff = tmpPlayer->player->xCor - tmpNPC->npc->xCor;
282          yOff = tmpPlayer->player->yCor - tmpNPC->npc->yCor;
283          zOff = tmpPlayer->player->zCor - tmpNPC->npc->zCor;
284          if ( sqrt(xOff*xOff + yOff*yOff + zOff*zOff) < radius )
285            cout << "COLLISION " << endl;
286         
287          tmpNPC = tmpNPC->next;
288        }
289     
290      tmpPlayer = tmpPlayer->next;
291    }
292 
293 
294
295  /* third: check if any enemy shoots a player */
296
297  //cout << "World::detectCollisions end" << endl;
298}
299
300
301
302/**
303   \brief Routine for testing purposes.
304   
305   testing, testing, testing...
306*/
307void World::testThaTest(void) 
308{
309  cout << "World::testThaTest() called" << endl;
310  /* test addPlayer */
311  cout << "addPlayer test..." << endl;
312  playerList* pl = lastPlayer;
313  while ( pl != null )
314    {
315      cout << "player " << pl->number << " was found" << endl;
316      pl = pl->next;
317    }
318
319  /* test addNPC */
320  cout << "addNPC test..." << endl;
321  npcList* nl = lastNPC;
322  while ( nl != null )
323    {
324      cout << "npc " << nl->number << " was found" << endl;
325      nl = nl->next;
326    }
327
328
329  /* test addEnv */
330  cout << "addEnv test..." << endl;
331  envList* en = lastEnv;
332  while ( en != null )
333    {
334      cout << "env " << en->number << " was found" << endl;
335      en = en->next;
336    }
337
338  /* test drawWorld() */
339}
Note: See TracBrowser for help on using the repository browser.