Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

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

File size: 5.8 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  lastShoot = null;
36}
37
38
39World::~World () {}
40
41
42/**
43   \brief Add Player
44   \param player A reference to the new player object
45   
46   Add a new Player to the game. Player has to be initialised previously
47*/
48bool World::addPlayer(Player* player) 
49{
50  playerList* listMember = new playerList;
51  listMember->player = player;
52  if ( lastPlayer != null ) 
53    {
54      listMember->number = lastPlayer->number + 1;
55      listMember->next = lastPlayer;
56    }
57  else 
58    {
59      listMember->number = 0;
60      listMember->next = null;
61    }
62  lastPlayer = listMember;
63}
64
65
66/**
67   \brief Remove Player
68   \param player A reference to the new npc object
69   
70   Remove a new Player to the game.
71*/
72bool World::removePlayer(Player* player) {
73  cout << "World::removeNPC not implemented yet" << endl;
74}
75
76Player* World::getLocalPlayer() 
77{
78  return localPlayer;
79}
80
81
82/**
83   \brief Add Non-Player-Character
84   \param player A reference to the new npc object
85   
86   Add a new Non-Player-Character to the game. Player has to be initialised previously
87*/
88bool World::addNPC(NPC* npc) 
89{
90  npcList* listMember = new npcList;
91  listMember->npc = npc;
92  if ( lastNPC != null ) 
93    {
94      listMember->number = lastNPC->number + 1;
95      listMember->next = lastNPC;
96    }
97  else 
98    {
99      listMember->number = 0;
100      listMember->next = null;
101    }
102  lastNPC = listMember;
103}
104
105
106/**
107   \brief Add environmental object
108   \param player A reference to the new env object
109   
110   Add a new Environment to the world. Env has to be initialised before.
111*/
112bool World::addEnv(Environment* env) 
113{
114  envList* listMember = new envList;
115  listMember->env = env;
116  if ( lastEnv != null ) 
117    {
118      listMember->number = lastEnv->number + 1;
119      listMember->next = lastEnv;
120    }
121  else 
122    {
123      listMember->number = 0;
124      listMember->next = null;
125    }
126  lastEnv = listMember;
127}
128
129
130/**
131   \brief Add environmental object
132   \param player A reference to the new env object
133   
134   Add a new Environment to the world. Env has to be initialised before.
135*/
136bool World::addShoot(ShootLaser* shoot) 
137{
138  shootList* listMember = new shootList;
139  listMember->shoot = shoot;
140  if ( lastShoot != null ) 
141    {
142      listMember->number = lastShoot->number + 1;
143      listMember->next = lastShoot;
144    }
145  else 
146    {
147      listMember->number = 0;
148      listMember->next = null;
149    }
150  lastShoot = listMember;
151}
152
153
154/**
155   \brief Remove Non-Player Character
156   \param player A reference to the new npc object
157   
158   Remove a new Non-Player-Character to the game.
159*/
160bool World::removeNPC(NPC* npc) {
161  cout << "World::removeNPC not implemented yet" << endl;
162}
163
164
165
166/**
167   \brief Draws the World and all Objects contained
168   
169   Calls the draw function of all: Objects, Players, Environement. This is the core of all graphics here.
170*/
171void World::drawWorld(void) 
172{
173  /* first draw all players */
174  playerList* tmpPlayer = lastPlayer;
175  Player* player = tmpPlayer->player;
176  while( tmpPlayer != null ) 
177    {
178      (*tmpPlayer->player).drawPlayer();
179      tmpPlayer = tmpPlayer->next;
180    }
181  /* second draw all npcs */
182  npcList* tmpNPC = lastNPC;
183  while( tmpNPC != null )
184    {
185      (*tmpNPC->npc).drawNPC();
186      tmpNPC = tmpNPC->next;
187    }
188  /* now draw the rest of the world: environement */
189  envList* tmpEnv = lastEnv;
190  while( tmpEnv != null )
191    {
192      (*tmpEnv->env).drawEnvironment();
193      tmpEnv = tmpEnv->next;
194    }
195  /* now draw all the shoots (many) */
196  shootList* tmpShoot = lastShoot;
197  while( tmpShoot != null )
198    {
199      (*tmpShoot->shoot).drawShoot();
200      tmpShoot = tmpShoot->next;
201    }
202 
203  glColor3f(0.0, 1.0, 0.0);
204 
205  glBegin(GL_LINES);
206  for (int x = 0; x < 60; x += 2)
207    {
208      for (int y = 0; y < 60; y += 2)
209        {
210          glVertex3f((float)(x - 30), (float)(y - 30), surface[x][y]);
211          glVertex3f((float)(x - 30), (float)(y - 28), surface[x][y+2]);
212        }
213    }
214  glEnd();
215 
216 
217  glBegin(GL_LINES);
218  for (int y = 0; y < 60; y += 2)
219    {
220      for (int x = 0; x < 60; x += 2)
221        {
222          glVertex3f((float)(x - 30), (float)(y - 30), surface[x][y]);
223          glVertex3f((float)(x - 28), (float)(y - 30), surface[x+2][y]);
224        }
225    }
226  glEnd();
227 
228}
229
230
231void World::initEnvironement()
232{
233
234 for (int x = 0; x < 60; x += 2)
235    {
236      for (int y = 0; y < 60; y += 2)
237        {
238          surface[x][y] = 0;
239        }
240    }
241}
242
243
244/**
245   \brief Updates the world and all its objects
246   
247   Calculates the new state of the world. User-input and AI of
248   the enemies are accounted for.
249*/
250void World::updateWorld(void) 
251{
252 
253
254}
255
256
257
258/**
259   \brief Routine for testing purposes.
260   
261   testing, testing, testing...
262*/
263void World::testThaTest(void) 
264{
265  cout << "World::testThaTest() called" << endl;
266  /* test addPlayer */
267  cout << "addPlayer test..." << endl;
268  playerList* pl = lastPlayer;
269  while ( pl != null )
270    {
271      cout << "player " << pl->number << " was found" << endl;
272      pl = pl->next;
273    }
274
275  /* test addNPC */
276  cout << "addNPC test..." << endl;
277  npcList* nl = lastNPC;
278  while ( nl != null )
279    {
280      cout << "npc " << nl->number << " was found" << endl;
281      nl = nl->next;
282    }
283
284
285  /* test addEnv */
286  cout << "addEnv test..." << endl;
287  envList* en = lastEnv;
288  while ( en != null )
289    {
290      cout << "env " << en->number << " was found" << endl;
291      en = en->next;
292    }
293
294  /* test drawWorld() */
295}
Note: See TracBrowser for help on using the repository browser.