Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/core/world.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
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer:
16*/
17
18
19#include "world.h"
20
21#include <iostream>
22
23using namespace std;
24
25
26/**
27   \brief Create a new World
28   
29   This creates a new empty world!
30*/
31World::World () {
32  lastPlayer = null;
33  lastNPC = null;
34  lastEnv = null;
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  /* now draw the rest of the world: environement */
167  envList* tmpEnv = lastEnv;
168  while( tmpEnv != null )
169    {
170      (*tmpEnv->env).drawEnvironment();
171      tmpEnv = tmpEnv->next;
172    }
173
174 
175  glColor3f(0.0, 1.0, 0.0);
176 
177  glBegin(GL_LINES);
178  for (int x = 0; x < 60; x += 2)
179    {
180      for (int y = 0; y < 60; y += 2)
181        {
182          glVertex3f((float)(x - 30), (float)(y - 30), surface[x][y]);
183          glVertex3f((float)(x - 30), (float)(y - 28), surface[x][y+2]);
184        }
185    }
186  glEnd();
187 
188 
189  glBegin(GL_LINES);
190  for (int y = 0; y < 60; y += 2)
191    {
192      for (int x = 0; x < 60; x += 2)
193        {
194          glVertex3f((float)(x - 30), (float)(y - 30), surface[x][y]);
195          glVertex3f((float)(x - 28), (float)(y - 30), surface[x+2][y]);
196        }
197    }
198  glEnd();
199 
200}
201
202
203void World::initEnvironement()
204{
205
206 for (int x = 0; x < 60; x += 2)
207    {
208      for (int y = 0; y < 60; y += 2)
209        {
210          surface[x][y] = 0;
211        }
212    }
213}
214
215
216/**
217   \brief Updates the world and all its objects
218   
219   Calculates the new state of the world. User-input and AI of
220   the enemies are accounted for.
221*/
222void World::updateWorld(void) 
223{
224 
225
226}
227
228
229/* collision detection */
230/* fix: bad efficency: stupid brute force */
231
232void World::detectCollision() 
233{
234  float xOff, yOff, zOff, radius;
235  npcList* tmpNPC;
236
237  //cout << "World::detectCollsions" << endl;
238  /* first: check if any player's shoots trigger a collision */
239  playerList* tmpPlayer = lastPlayer;
240  Player* player = tmpPlayer->player;
241  while( tmpPlayer != null ) 
242    {
243      tmpNPC = lastNPC;
244      while( tmpNPC != null )
245        {
246          radius = tmpNPC->npc->collisionRadius;
247          ShootLaser::shoot* shoota = tmpPlayer->player->shootLaser->lastShoot;
248          while( shoota != null )
249            {
250              xOff = shoota->xCor - tmpNPC->npc->xCor;
251              yOff = shoota->yCor - tmpNPC->npc->yCor;
252              zOff = shoota->zCor - tmpNPC->npc->zCor;
253              if ( sqrt(xOff*xOff + yOff*yOff + zOff*zOff) < radius )
254                cout << "COLLISION " << endl;
255              shoota = shoota->next;
256            }
257          tmpNPC = tmpNPC->next;
258        }
259     
260      tmpPlayer = tmpPlayer->next;
261    }
262
263  /* second: check if any player hits an enemy */
264
265  /* third: check if any enemy shoots a player */
266
267  //cout << "World::detectCollisions end" << endl;
268}
269
270
271
272/**
273   \brief Routine for testing purposes.
274   
275   testing, testing, testing...
276*/
277void World::testThaTest(void) 
278{
279  cout << "World::testThaTest() called" << endl;
280  /* test addPlayer */
281  cout << "addPlayer test..." << endl;
282  playerList* pl = lastPlayer;
283  while ( pl != null )
284    {
285      cout << "player " << pl->number << " was found" << endl;
286      pl = pl->next;
287    }
288
289  /* test addNPC */
290  cout << "addNPC test..." << endl;
291  npcList* nl = lastNPC;
292  while ( nl != null )
293    {
294      cout << "npc " << nl->number << " was found" << endl;
295      nl = nl->next;
296    }
297
298
299  /* test addEnv */
300  cout << "addEnv test..." << endl;
301  envList* en = lastEnv;
302  while ( en != null )
303    {
304      cout << "env " << en->number << " was found" << endl;
305      en = en->next;
306    }
307
308  /* test drawWorld() */
309}
Note: See TracBrowser for help on using the repository browser.