[1853] | 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. |
---|
[1855] | 12 | |
---|
| 13 | ### File Specific: |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
| 15 | co-programmer: |
---|
[1853] | 16 | */ |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | #include "world.h" |
---|
| 20 | |
---|
[1856] | 21 | #include <iostream> |
---|
[1853] | 22 | |
---|
[1856] | 23 | using namespace std; |
---|
[1853] | 24 | |
---|
| 25 | |
---|
[1858] | 26 | /** |
---|
| 27 | \brief Create a new World |
---|
| 28 | |
---|
| 29 | This creates a new empty world! |
---|
| 30 | */ |
---|
[1853] | 31 | World::World () { |
---|
[1855] | 32 | lastPlayer = null; |
---|
[1858] | 33 | lastNPC = null; |
---|
[1883] | 34 | lastEnv = null; |
---|
[1853] | 35 | } |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | World::~World () {} |
---|
| 39 | |
---|
| 40 | |
---|
[1855] | 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 | */ |
---|
| 47 | bool World::addPlayer(Player* player) |
---|
| 48 | { |
---|
| 49 | playerList* listMember = new playerList; |
---|
| 50 | listMember->player = player; |
---|
[1856] | 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 | } |
---|
[1855] | 61 | lastPlayer = listMember; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | |
---|
[1858] | 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 | */ |
---|
| 71 | bool World::removePlayer(Player* player) { |
---|
| 72 | cout << "World::removeNPC not implemented yet" << endl; |
---|
| 73 | } |
---|
[1855] | 74 | |
---|
[1872] | 75 | Player* World::getLocalPlayer() |
---|
| 76 | { |
---|
| 77 | return localPlayer; |
---|
| 78 | } |
---|
[1858] | 79 | |
---|
[1872] | 80 | |
---|
[1855] | 81 | /** |
---|
[1858] | 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 | */ |
---|
| 87 | bool 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 | /** |
---|
[1883] | 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 | */ |
---|
| 111 | bool 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 | /** |
---|
[1858] | 130 | \brief Remove Non-Player-Character |
---|
| 131 | \param player A reference to the new npc object |
---|
| 132 | |
---|
| 133 | Remove a new Non-Player-Character to the game. |
---|
| 134 | */ |
---|
| 135 | bool World::removeNPC(NPC* npc) { |
---|
| 136 | cout << "World::removeNPC not implemented yet" << endl; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | /** |
---|
| 142 | \brief Draws the World and all Objects contained |
---|
| 143 | |
---|
[1879] | 144 | Calls the draw function of all: Objects, Players, Environement. This is the core of all graphics here. |
---|
[1858] | 145 | */ |
---|
| 146 | void World::drawWorld(void) |
---|
| 147 | { |
---|
[1879] | 148 | /* first draw all players */ |
---|
[1858] | 149 | playerList* tmpPlayer = lastPlayer; |
---|
| 150 | Player* player = tmpPlayer->player; |
---|
| 151 | while( tmpPlayer != null ) |
---|
| 152 | { |
---|
| 153 | (*tmpPlayer->player).drawPlayer(); |
---|
| 154 | tmpPlayer = tmpPlayer->next; |
---|
| 155 | } |
---|
[1879] | 156 | /* second draw all npcs */ |
---|
[1858] | 157 | npcList* tmpNPC = lastNPC; |
---|
| 158 | while( tmpNPC != null ) |
---|
| 159 | { |
---|
| 160 | (*tmpNPC->npc).drawNPC(); |
---|
| 161 | tmpNPC = tmpNPC->next; |
---|
| 162 | } |
---|
[1879] | 163 | /* now draw the rest of the world: environement */ |
---|
[1883] | 164 | /* second draw all npcs */ |
---|
| 165 | envList* tmpEnv = lastEnv; |
---|
| 166 | while( tmpEnv != null ) |
---|
| 167 | { |
---|
| 168 | (*tmpEnv->env).drawEnvironment(); |
---|
| 169 | tmpEnv = tmpEnv->next; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | /* |
---|
[1879] | 173 | glColor3f(0.0, 1.0, 0.0); |
---|
| 174 | glBegin(GL_LINES); |
---|
[1883] | 175 | for (int x = 0; x <= 35; x += 5) |
---|
| 176 | { |
---|
| 177 | glVertex3f((float)x, -10.0, 0.0); |
---|
| 178 | glVertex3f((float)x, 200.0, 0.0); |
---|
[1879] | 179 | |
---|
[1883] | 180 | glVertex3f(-(float)x, -10.0, 0.0); |
---|
| 181 | glVertex3f(-(float)x, 200.0, 0.0); |
---|
| 182 | } |
---|
| 183 | for (int x = -10; x<= 200; x += 5) |
---|
| 184 | { |
---|
| 185 | glVertex3f(-50.0, (float)x, 0.0); |
---|
| 186 | glVertex3f(50.0, (float)x, 0.0); |
---|
| 187 | } |
---|
| 188 | glEnd(); |
---|
| 189 | */ |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | glColor3f(0.0, 1.0, 0.0); |
---|
| 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 | glBegin(GL_LINES); |
---|
| 207 | for (int y = 0; y < 60; y += 2) |
---|
| 208 | { |
---|
| 209 | for (int x = 0; x < 60; x += 2) |
---|
| 210 | { |
---|
| 211 | glVertex3f((float)(x - 30), (float)(y - 30), surface[x][y]); |
---|
| 212 | glVertex3f((float)(x - 28), (float)(y - 30), surface[x+2][y]); |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | glEnd(); |
---|
| 216 | |
---|
| 217 | } |
---|
[1879] | 218 | |
---|
| 219 | |
---|
[1883] | 220 | void World::initEnvironement() |
---|
| 221 | { |
---|
[1879] | 222 | |
---|
[1883] | 223 | for (int x = 0; x < 60; x += 2) |
---|
| 224 | { |
---|
| 225 | for (int y = 0; y < 60; y += 2) |
---|
| 226 | { |
---|
| 227 | surface[x][y] = 0; |
---|
| 228 | } |
---|
| 229 | } |
---|
[1858] | 230 | } |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | /** |
---|
| 234 | \brief Updates the world and all its objects |
---|
| 235 | |
---|
| 236 | Calculates the new state of the world. User-input and AI of |
---|
| 237 | the enemies are accounted for. |
---|
| 238 | */ |
---|
| 239 | void World::updateWorld(void) |
---|
| 240 | { |
---|
| 241 | |
---|
| 242 | |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | |
---|
| 246 | |
---|
| 247 | /** |
---|
[1855] | 248 | \brief Routine for testing purposes. |
---|
| 249 | |
---|
| 250 | testing, testing, testing... |
---|
| 251 | */ |
---|
[1858] | 252 | void World::testThaTest(void) |
---|
[1855] | 253 | { |
---|
[1856] | 254 | cout << "World::testThaTest() called" << endl; |
---|
| 255 | /* test addPlayer */ |
---|
| 256 | cout << "addPlayer test..." << endl; |
---|
| 257 | playerList* pl = lastPlayer; |
---|
| 258 | while ( pl != null ) |
---|
| 259 | { |
---|
| 260 | cout << "player " << pl->number << " was found" << endl; |
---|
| 261 | pl = pl->next; |
---|
| 262 | } |
---|
[1855] | 263 | |
---|
[1858] | 264 | /* test addNPC */ |
---|
| 265 | cout << "addNPC test..." << endl; |
---|
| 266 | npcList* nl = lastNPC; |
---|
| 267 | while ( nl != null ) |
---|
| 268 | { |
---|
| 269 | cout << "npc " << nl->number << " was found" << endl; |
---|
| 270 | nl = nl->next; |
---|
| 271 | } |
---|
| 272 | |
---|
[1883] | 273 | |
---|
| 274 | /* test addEnv */ |
---|
| 275 | cout << "addEnv test..." << endl; |
---|
| 276 | envList* en = lastEnv; |
---|
| 277 | while ( en != null ) |
---|
| 278 | { |
---|
| 279 | cout << "env " << en->number << " was found" << endl; |
---|
| 280 | en = en->next; |
---|
| 281 | } |
---|
| 282 | |
---|
[1858] | 283 | /* test drawWorld() */ |
---|
[1855] | 284 | } |
---|