Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: perspective view, key-repeat bug fixed

File size: 4.4 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}
35
36
37World::~World () {}
38
39
40/**
41   \brief Add Player
42   \param player A reference to the new player object
43   
44   Add a new Player to the game. Player has to be initialised previously
45*/
46bool World::addPlayer(Player* player) 
47{
48  playerList* listMember = new playerList;
49  listMember->player = player;
50  if ( lastPlayer != null ) 
51    {
52      listMember->number = lastPlayer->number + 1;
53      listMember->next = lastPlayer;
54    }
55  else 
56    {
57      listMember->number = 0;
58      listMember->next = null;
59    }
60  lastPlayer = listMember;
61}
62
63
64/**
65   \brief Remove Player
66   \param player A reference to the new npc object
67   
68   Remove a new Player to the game.
69*/
70bool World::removePlayer(Player* player) {
71  cout << "World::removeNPC not implemented yet" << endl;
72}
73
74Player* World::getLocalPlayer() 
75{
76  return localPlayer;
77}
78
79
80/**
81   \brief Add Non-Player-Character
82   \param player A reference to the new npc object
83   
84   Add a new Non-Player-Character to the game. Player has to be initialised previously
85*/
86bool World::addNPC(NPC* npc) 
87{
88  npcList* listMember = new npcList;
89  listMember->npc = npc;
90  if ( lastNPC != null ) 
91    {
92      listMember->number = lastNPC->number + 1;
93      listMember->next = lastNPC;
94    }
95  else 
96    {
97      listMember->number = 0;
98      listMember->next = null;
99    }
100  lastNPC = listMember;
101}
102
103
104/**
105   \brief Remove Non-Player-Character
106   \param player A reference to the new npc object
107   
108   Remove a new Non-Player-Character to the game.
109*/
110bool World::removeNPC(NPC* npc) {
111  cout << "World::removeNPC not implemented yet" << endl;
112}
113
114
115
116/**
117   \brief Draws the World and all Objects contained
118   
119   Calls the draw function of all: Objects, Players, Environement. This is the core of all graphics here.
120*/
121void World::drawWorld(void) 
122{
123  /* first draw all players */
124  playerList* tmpPlayer = lastPlayer;
125  Player* player = tmpPlayer->player;
126  while( tmpPlayer != null ) 
127    {
128      (*tmpPlayer->player).drawPlayer();
129      tmpPlayer = tmpPlayer->next;
130    }
131  /* second draw all npcs */
132  npcList* tmpNPC = lastNPC;
133  while( tmpNPC != null )
134    {
135      (*tmpNPC->npc).drawNPC();
136      tmpNPC = tmpNPC->next;
137    }
138  /* now draw the rest of the world: environement */
139  glColor3f(0.0, 1.0, 0.0);
140  glBegin(GL_LINES);
141  glVertex3f(0.0, -10.0, 0.0);
142  glVertex3f(0.0, 200.0, 0.0);
143
144  glVertex3f(5.0, -10.0, 0.0);
145  glVertex3f(5.0, 200.0, 0.0);
146
147  glVertex3f(-5.0, -10.0, 0.0);
148  glVertex3f(-5.0, 200.0, 0.0);
149
150  glVertex3f(10.0, -10.0, 0.0);
151  glVertex3f(10.0, 200.0, 0.0);
152
153  glVertex3f(-10.0, -10.0, 0.0);
154  glVertex3f(-10.0, 200.0, 0.0);
155
156  glVertex3f(15.0, -10.0, 0.0);
157  glVertex3f(15.0, 200.0, 0.0);
158
159  glVertex3f(-15.0, -10.0, 0.0);
160  glVertex3f(-15.0, 200.0, 0.0);
161
162  glVertex3f(20.0, -10.0, 0.0);
163  glVertex3f(20.0, 200.0, 0.0);
164
165  glVertex3f(-20.0, -10.0, 0.0);
166  glVertex3f(-20.0, 200.0, 0.0);
167
168  glVertex3f(25.0, -10.0, 0.0);
169  glVertex3f(25.0, 200.0, 0.0);
170
171  glVertex3f(-25.0, -10.0, 0.0);
172  glVertex3f(-25.0, 200.0, 0.0);
173  glEnd();
174
175
176}
177
178
179/**
180   \brief Updates the world and all its objects
181   
182   Calculates the new state of the world. User-input and AI of
183   the enemies are accounted for.
184*/
185void World::updateWorld(void) 
186{
187 
188
189}
190
191
192
193/**
194   \brief Routine for testing purposes.
195   
196   testing, testing, testing...
197*/
198void World::testThaTest(void) 
199{
200  cout << "World::testThaTest() called" << endl;
201  /* test addPlayer */
202  cout << "addPlayer test..." << endl;
203  playerList* pl = lastPlayer;
204  while ( pl != null )
205    {
206      cout << "player " << pl->number << " was found" << endl;
207      pl = pl->next;
208    }
209
210  /* test addNPC */
211  cout << "addNPC test..." << endl;
212  npcList* nl = lastNPC;
213  while ( nl != null )
214    {
215      cout << "npc " << nl->number << " was found" << endl;
216      nl = nl->next;
217    }
218
219  /* test drawWorld() */
220  cout << "drawWorld()..." << endl;
221  drawWorld();
222
223  cout << "World::testThaTest() finished" << endl;
224}
Note: See TracBrowser for help on using the repository browser.