Changeset 1994 in orxonox.OLD for orxonox/branches/dave/core/world.cc
- Timestamp:
- Jun 21, 2004, 12:39:11 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/dave/core/world.cc
r1883 r1994 1 2 1 3 2 /* … … 33 32 lastNPC = null; 34 33 lastEnv = null; 34 primitiveMove = 0; 35 step = 0; 35 36 } 36 37 … … 104 105 105 106 /** 107 \brief Remove Non-Player Character 108 \param player A reference to the new npc object 109 110 Remove a new Non-Player-Character to the game. 111 */ 112 bool World::removeNPC(NPC* npc) { 113 114 npcList* npcRef = lastNPC; 115 npcList* lastRef = lastNPC; 116 while ( npcRef != null ) 117 { 118 if ( npcRef->npc == npc ) { 119 cout << "found" << endl; 120 if ( npcRef == lastRef ) { 121 lastNPC = lastNPC->next; 122 delete npcRef; 123 npcRef = lastNPC; 124 lastRef = lastNPC; 125 } 126 else { 127 lastRef->next = npcRef->next; 128 delete npcRef; 129 npcRef = lastRef->next; 130 } 131 cout << "killed ..." << endl; 132 } 133 else { 134 lastRef = npcRef; 135 npcRef = npcRef->next; 136 } 137 } 138 cout << "npc left" << endl; 139 } 140 141 142 143 /** 106 144 \brief Add environmental object 107 145 \param player A reference to the new env object … … 127 165 128 166 129 /**130 \brief Remove Non-Player-Character131 \param player A reference to the new npc object132 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 167 140 168 … … 144 172 Calls the draw function of all: Objects, Players, Environement. This is the core of all graphics here. 145 173 */ 146 void World::drawWorld(void) 147 { 174 void World::drawWorld(float Zahl1,float Zahl2) 175 { 176 glLoadIdentity(); 177 gluLookAt(0.0, -14.0 + DataTank::yOffset, 15.0, 0.0, 0.0 + DataTank::yOffset, 0.0, 0.0, 1.0, 0.0); 178 179 //glRotatef(Zahl1,1.0,0.0,0.0); 180 //glRotatef(Zahl2,0.0,1.0,0.0); 181 148 182 /* first draw all players */ 149 183 playerList* tmpPlayer = lastPlayer; … … 151 185 while( tmpPlayer != null ) 152 186 { 153 (*tmpPlayer->player).drawPlayer( );187 (*tmpPlayer->player).drawPlayer((float)Zahl1,(float)Zahl2); 154 188 tmpPlayer = tmpPlayer->next; 155 189 } … … 161 195 tmpNPC = tmpNPC->next; 162 196 } 197 163 198 /* now draw the rest of the world: environement */ 164 /* second draw all npcs */165 199 envList* tmpEnv = lastEnv; 166 200 while( tmpEnv != null ) … … 169 203 tmpEnv = tmpEnv->next; 170 204 } 171 172 /* 173 glColor3f(0. 0, 1.0, 0.0);205 206 /* draw the ground grid */ 207 glColor3f(0.3, 0.3, 0.0); 174 208 glBegin(GL_LINES); 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); 179 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); 209 /* for the moment, we've got only pseudo moving ground 210 for (int y = 0; y < 60; y += 2) 211 { 212 for (int x = 0; x < 60; x += 2) 213 { 214 glVertex3f((float)(x - 30), (float)(y - 30), surface[x][y]); 215 glVertex3f((float)(x - 28), (float)(y - 30), surface[x+2][y]); 216 } 187 217 } 188 218 glEnd(); 189 */190 191 192 glColor3f(0.0, 1.0, 0.0);193 219 194 220 glBegin(GL_LINES); … … 201 227 } 202 228 } 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(); 229 glEnd();*/ 230 231 //primitiveMove+=0.07; 232 DataTank::yOffset += step; 233 234 tmpPlayer = lastPlayer; 235 while( tmpPlayer != null ) 236 { 237 tmpPlayer->player->yCor += step; 238 tmpPlayer = tmpPlayer->next; 239 } 240 216 241 217 242 } … … 231 256 232 257 258 void World::setWorldStep(float step) 259 { 260 this->step = step; 261 cout << "setting speed to " << step << endl; 262 } 263 264 265 233 266 /** 234 267 \brief Updates the world and all its objects … … 241 274 242 275 276 } 277 278 279 /* collision detection */ 280 /* fix: bad efficency: stupid brute force */ 281 282 void World::detectCollision() 283 { 284 //cout << "World::detectCollision" << endl; 285 float xOff, yOff, zOff, radius; 286 npcList* tmpNPC, *tmpRef; 287 288 //cout << "World::detectCollsions" << endl; 289 /* first: check if any player's shoots trigger a collision */ 290 playerList* tmpPlayer = lastPlayer; 291 Player* player = tmpPlayer->player; 292 int state; 293 while( tmpPlayer != null ) 294 { 295 tmpNPC = lastNPC; 296 while( tmpNPC != null ) 297 { 298 //cout << "npc != null" << endl; 299 radius = tmpNPC->npc->collisionRadius; 300 //cout << "worki" << endl; 301 ShootLaser::shoot* shoota = tmpPlayer->player->shootLaser->lastShoot; 302 while( shoota != null ) 303 { 304 xOff = shoota->xCor - tmpNPC->npc->xCor; 305 yOff = shoota->yCor - tmpNPC->npc->yCor; 306 zOff = shoota->zCor - tmpNPC->npc->zCor; 307 if ( sqrt(xOff*xOff + yOff*yOff + zOff*zOff) < radius ) 308 { 309 //cout << "COLLISION " << endl; 310 int state = tmpNPC->npc->hit(); 311 /* state is a value that marks if the ship dies or not */ 312 /* if state == 0 the ship dies and we have to remove it */ 313 /* 314 if ( state == 0 ) { 315 tmpRef = tmpNPC; 316 tmpNPC = tmpNPC->next; 317 removeNPC(tmpRef->npc); 318 break; 319 } 320 */ 321 } 322 shoota = shoota->next; 323 } 324 //cout << "changing npc..." << endl; 325 tmpNPC = tmpNPC->next; 326 //cout << "..changing npc done" << endl; 327 } 328 //cout << "changing play..." << endl; 329 tmpPlayer = tmpPlayer->next; 330 //cout << "changing play done" << endl; 331 } 332 333 //cout << "World::detectCollisions middle" << endl; 334 335 /* second: check if any player hits an enemy */ 336 tmpPlayer = lastPlayer; 337 while( tmpPlayer != null ) 338 { 339 tmpNPC = lastNPC; 340 while( tmpNPC != null ) 341 { 342 radius = tmpNPC->npc->collisionRadius + tmpPlayer->player->collisionRadius; 343 xOff = tmpPlayer->player->xCor - tmpNPC->npc->xCor; 344 yOff = tmpPlayer->player->yCor - tmpNPC->npc->yCor; 345 zOff = tmpPlayer->player->zCor - tmpNPC->npc->zCor; 346 if ( sqrt(xOff*xOff + yOff*yOff + zOff*zOff) < radius ) { 347 //cout << "COLLISION " << endl; 348 tmpNPC->npc->hit(); 349 } 350 351 tmpNPC = tmpNPC->next; 352 } 353 354 tmpPlayer = tmpPlayer->next; 355 } 356 357 358 359 /* third: check if any enemy shoots a player */ 360 361 //cout << "World::detectCollisions end" << endl; 243 362 } 244 363
Note: See TracChangeset
for help on using the changeset viewer.