Changeset 1994 in orxonox.OLD for orxonox/branches/dave
- Timestamp:
- Jun 21, 2004, 12:39:11 AM (20 years ago)
- Location:
- orxonox/branches/dave/core
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/dave/core/Makefile
r1883 r1994 29 29 orxonox.h \ 30 30 data_core.h 31 31 32 32 SOURCES = \ 33 33 orxonox.cc \ … … 41 41 world.o \ 42 42 input_output.o \ 43 environment.o 43 environment.o \ 44 shoot_laser.o \ 45 shoot_rocket.o \ 46 ai.o 44 47 45 48 TARGET = orxonox … … 73 76 @echo "" 74 77 @echo "For further info see the README file" 75 78 76 79 clean: 77 80 rm -rf *.o *~ orxonox … … 85 88 #data_tank.o: data_tank.cc \ 86 89 # data_tank.h 87 90 88 91 #EOF -
orxonox/branches/dave/core/data_tank.cc
r1856 r1994 19 19 using namespace std; 20 20 21 float DataTank::xOffset = 0; 22 float DataTank::yOffset = 0; 23 float DataTank::zOffset = 0; 21 24 22 25 DataTank::DataTank () {} 23 24 25 26 26 DataTank::~DataTank () {} 27 27 -
orxonox/branches/dave/core/data_tank.h
r1850 r1994 6 6 class DataTank { 7 7 8 p rivate:8 public: 9 9 DataTank (); 10 10 ~DataTank (); 11 12 static float xOffset; 13 static float yOffset; 14 static float zOffset; 11 15 12 16 }; -
orxonox/branches/dave/core/environment.cc
r1883 r1994 23 23 using namespace std; 24 24 25 25 //Sorry Bensch 26 #define LEVEL_LENGTH 500 26 27 27 28 Environment::Environment () 28 29 { 29 30 30 for (int x = 1; x < 9; x++) 31 //Sorry Bensch: x,y = 10 32 for (int x = 0; x < 50; x++) 31 33 { 32 for (int y = 1; y < 9; y++)34 for (int y = 0; y < 50; y++) 33 35 { 34 mountainTest[x][y] = (float)random() / 900000000;36 mountainTest[x][y] =0; 35 37 36 38 } 37 39 } 38 39 for (int x = 0; x < 10; x++)40 //Sorry Bensch: x,y = 9 41 for (int x = 1; x < LEVEL_LENGTH; x++) 40 42 { 41 for (int y = 0; y < 10; y++)43 for (int y = 1; y < LEVEL_LENGTH; y++) 42 44 { 43 cout << " " << mountainTest[x][y] << " ";44 45 //mountainTest[x][y] = (float)random() / 900000000; 46 mountainTest[x][y] = (float)(random() % 4); 45 47 } 46 cout << endl;47 48 } 48 49 } … … 57 58 { 58 59 glPushMatrix(); 60 glEnable(GL_DEPTH_TEST); 59 61 //glScalef(0.5, 0.5, 1.0); 60 62 //glTranslatef(xCor, yCor, zCor); 61 glTranslatef( -1 6.0, -2.0, 0.0);63 glTranslatef( -100.0, -50.0, 0.0); 62 64 63 glColor 3f(0.0, 1.0, 0.0);65 glColor4f(0.0, 0.3, 0.4,1.0); 64 66 65 67 glBegin(GL_LINES); 66 for (int x = 0; x < 10; x += 1)68 for (int x = 0; x < LEVEL_LENGTH; x += 1) 67 69 { 68 for (int y = 0; y < 1 0; y += 1)70 for (int y = 0; y < 190; y += 1) 69 71 { 70 72 glVertex3f((float)(2*x), (float)(2*y), mountainTest[x][y]); … … 76 78 77 79 glBegin(GL_LINES); 78 for (int y = 0; y < 10; y += 1)80 for (int y = 0; y < LEVEL_LENGTH; y += 1) 79 81 { 80 for (int x = 0; x < 10; x += 1)82 for (int x = 0; x < 90; x += 1) 81 83 { 82 84 glVertex3f((float)(2*x), (float)(2*y), mountainTest[x][y]); -
orxonox/branches/dave/core/environment.h
r1883 r1994 3 3 #include <stdlib.h> 4 4 5 #ifndef PROTO_CLASS_H6 #define PROTO_CLASS_H5 #ifndef ENVIRONEMENT_H 6 #define ENVIRONEMENT_H 7 7 8 8 #include "data_tank.h" 9 9 10 10 class Environment { -
orxonox/branches/dave/core/input_output.cc
r1879 r1994 40 40 41 41 42 void InputOutput::setPlayerStep(float step) 43 { 44 cout << "setting player step to: " << step << endl; 45 this->step = step; 46 } 47 42 48 43 49 void InputOutput::goUp() 44 50 { 45 (*player).goY(STEP_FRONT); 51 //cout << "InoutOutput::goUp" << endl; 52 (*player).goY(step); 46 53 } 47 54 48 55 void InputOutput::goDown() 49 56 { 50 (*player).goY(- STEP_FRONT);57 (*player).goY(-step); 51 58 } 52 59 53 60 void InputOutput::goLeft() 54 61 { 55 (*player).goX(- STEP_SIDE);62 (*player).goX(-step); 56 63 57 64 } … … 60 67 { 61 68 62 (*player).goX( STEP_SIDE);69 (*player).goX(step); 63 70 } 64 71 -
orxonox/branches/dave/core/input_output.h
r1879 r1994 9 9 #include "player.h" 10 10 11 #define STEP_SIDE 0.4 12 #define STEP_FRONT 0.2 11 #include "data_tank.h" 13 12 14 13 class InputOutput { … … 18 17 Player* player; 19 18 19 float step; 20 20 21 public: 21 22 InputOutput (World* wld, Player* player); 22 23 ~InputOutput (); 23 24 25 void setPlayerStep(float step); 24 26 void goUp(void); 25 27 void goDown(void); -
orxonox/branches/dave/core/npc.cc
r1858 r1994 21 21 #include <iostream> 22 22 23 23 24 using namespace std; 24 25 25 26 26 NPC::NPC () {} 27 28 27 NPC::NPC () 28 { 29 hasDied = 0; 30 } 29 31 30 32 NPC::~NPC () {} 31 33 32 34 33 void NPC::setPosition( int x, int y, int z)35 void NPC::setPosition(float x, float y, float z) 34 36 { 35 37 xCor = x; yCor = y; zCor = z; 36 38 } 37 39 38 void NPC::getPosition( int* x, int* y, int* z)40 void NPC::getPosition(float* x, float* y, float* z) 39 41 { 40 42 *x = xCor; … … 43 45 } 44 46 47 void NPC::setCollisionRadius(float r) 48 { 49 collisionRadius = r; 50 } 51 52 float NPC::getCollisionRadius() 53 { 54 return collisionRadius; 55 } 56 57 58 void NPC::addAI(AI* ai) 59 { 60 61 } 45 62 46 63 void NPC::drawNPC(void) 47 64 { 48 cout << "Player::drawNPC()" << endl; 65 /* fix: died flag approach is very stupid, just to show @ convention */ 66 if( hasDied == 0 ) { 67 glPushMatrix(); 68 glTranslatef(xCor, yCor, 3.0); 69 //glScalef(1.0, 3.0, 1.0); 70 glutWireSphere(1.0, 10, 10); 71 glPopMatrix(); 72 73 } 49 74 } 75 76 77 /* define the reaction, if the ship is been hit */ 78 int NPC::hit() 79 { 80 die(); 81 return 0; 82 } 83 84 void NPC::die() 85 { 86 hasDied = 1; 87 } -
orxonox/branches/dave/core/npc.h
r1858 r1994 3 3 #define NPC_H 4 4 5 /* openGL Headers */ 6 #include <GL/glut.h> 7 8 #include "ai.h" 9 #include "data_tank.h" 5 10 6 11 class NPC { … … 10 15 ~NPC (); 11 16 17 /* collision control */ 18 float collisionRadius; 19 20 float xCor; 21 float yCor; 22 float zCor; 23 12 24 void drawNPC(void); 13 void setPosition(int x, int y, int z); 14 void getPosition(int* x, int* y, int* z); 25 void setPosition(float x, float y, float z); 26 void getPosition(float* x, float* y, float* z); 27 void addAI(AI* ai); 28 void setCollisionRadius(float r); 29 float getCollisionRadius(void); 30 int hit(void); 31 void die(void); 15 32 16 33 private: … … 18 35 19 36 int npcType; 37 int hasDied; 20 38 21 int xCor; 22 int yCor; 23 int zCor; 39 24 40 ; 25 41 -
orxonox/branches/dave/core/orxonox.cc
r1883 r1994 26 26 /* class definition header */ 27 27 #include "orxonox.h" 28 #include "environment.h"29 28 30 29 … … 50 49 World* Orxonox::world = 0; 51 50 InputOutput* Orxonox::io = 0; 51 Player* Orxonox::localPlayer = 0; 52 52 bool Orxonox::pause = false; 53 bool Orxonox::inputEnabled = false; 53 54 bool Orxonox::upWeGo = false; 54 55 bool Orxonox::downWeGo = false; 55 56 bool Orxonox::rightWeGo = false; 56 57 bool Orxonox::leftWeGo = false; 58 bool Orxonox::shoot1 = false; 59 int Orxonox::fps = 0; 57 60 int Orxonox::alpha = 0; 58 61 int Orxonox::beta = 0; … … 70 73 int Orxonox::globalInit (int argc, char** argv) 71 74 { 75 glEnable(GL_DEPTH_TEST); 76 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 72 77 glutInit(&argc, argv); 73 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 74 glEnable(GL_DEPTH_TEST); 75 glutInitWindowSize(500, 500); 78 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB | GLUT_DEPTH); 79 glEnable(GL_NORMALIZE); 80 glEnable(GL_COLOR_MATERIAL); 81 /*glEnable(GL_LIGHT0); 82 glEnable(GL_LIGHTING); 83 GLfloat LPosition[4]={1.0,1.0,1.0,0.0}; 84 glLightfv(GL_LIGHT0,GL_POSITION,&LPosition[0]); 85 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1); 86 */ 87 88 89 /* muss nicht eingeschaltet werden, da sonst Transparenz aktiviert 90 glEnable(GL_BLEND); 91 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 92 glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE); 93 */ 94 95 96 glutInitWindowSize(1000, 1000); 76 97 //glutFullScreen(); 77 glutInitWindowPosition( 100, 100);98 glutInitWindowPosition(200, 200); 78 99 glutCreateWindow("orxOnox"); 79 glShadeModel(GL_ FLAT);100 glShadeModel(GL_SMOOTH); 80 101 /* window event dispatchers */ 81 102 glutDisplayFunc(display); 82 103 glutReshapeFunc(reshape); 83 104 glutKeyboardFunc(keyboard); 105 glutKeyboardUpFunc(upKeyboard); 106 107 108 glutTimerFunc(1000, timeSlice, 0); 109 cout << "measuring performance..."; 84 110 } 85 111 … … 87 113 int Orxonox::menuInit (void) 88 114 { 89 glClearColor(0.0, 0.0, 0.0, 0.0);115 glClearColor(0.0, 0.0, 0.0,1.0); 90 116 } 91 117 … … 93 119 int Orxonox::gameInit (void) 94 120 { 95 glClearColor(0.0, 0.0, 0.0, 0.0); 121 glClearColor(0.0, 0.0, 0.0,1.0); 122 123 /* world init, shouldnt be done here later */ 96 124 world = new World; 97 125 (*world).initEnvironement(); 98 Player* localPlayer = new Player; 126 localPlayer = new Player; 127 localPlayer->setPosition(0.0, -10.0, 3.0); 128 localPlayer->setCollisionRadius(2.0); 99 129 io = new InputOutput(world, localPlayer); 100 130 (*world).addPlayer(localPlayer); … … 102 132 (*world).addEnv(env); 103 133 134 135 NPC* npc = new NPC; 136 npc->setPosition(3.0, 0.0, 3.0); 137 npc->setCollisionRadius(1.0); 138 world->addNPC(npc); 139 140 NPC* npc2 = new NPC; 141 npc2->setPosition(-2.0, 10.0, 3.0); 142 npc2->setCollisionRadius(1.0); 143 world->addNPC(npc2); 144 145 NPC* npc3 = new NPC; 146 npc3->setPosition(3.0, 30.0, 3.0); 147 npc3->setCollisionRadius(1.0); 148 world->addNPC(npc3); 149 150 NPC* npc4 = new NPC; 151 npc4->setPosition(-2.0, 35.0, 3.0); 152 npc4->setCollisionRadius(1.0); 153 world->addNPC(npc4); 154 155 NPC* npc5 = new NPC; 156 npc5->setPosition(5.0, 45.0, 3.0); 157 npc5->setCollisionRadius(1.0); 158 world->addNPC(npc5); 104 159 105 160 glutSpecialFunc(specFunc); 106 161 glutSpecialUpFunc(releaseKey); 107 162 108 //for testing purps only109 //testTheShit();110 163 glutIdleFunc(continousRedraw); 111 } 164 //cout << "Orxonox::gameInit" << endl; 165 } 166 167 168 /* this is the time triggered function. heart beat*/ 169 170 void Orxonox::timeSlice(int value) 171 { 172 cout << "got " << fps << " fps" << endl; 173 /* this is very very unsafe: io could be uninit */ 174 io->setPlayerStep(19.0/fps); /* set player to propper speed */ 175 localPlayer->shootLaser->setShootStep(20.0/fps); /* set shoot speed */ 176 world->setWorldStep(7.0/fps); /* set the speed of the terrain moving away */ 177 fps = 0; 178 inputEnabled = true; 179 glutTimerFunc(1000, timeSlice, 0); 180 } 181 112 182 113 183 … … 131 201 132 202 /* game controls */ 133 134 203 case 'p': 135 204 if (pause) … … 146 215 } 147 216 break; 217 case 32: 218 shoot1 = true; 219 break; 148 220 case 27: 149 221 case 'q': … … 154 226 155 227 228 void Orxonox::upKeyboard(unsigned char key, int x, int y) 229 { 230 switch(key) { 231 case 32: 232 shoot1 = false; 233 break; 234 } 235 } 236 237 156 238 void Orxonox::quitGame() 157 239 { 158 //glutIgnoreKeyRepeat(0); /* for win32 */ 159 //glutSetKeyRepeat(GLUT_KEY_REPEAT_DEFAULT); /*do not remove or you will have 160 // no repeating keys anymore...*/ 161 cout << "finished garbage colletion, quitting..." << endl; 240 //cout << "finished garbage colletion, quitting..." << endl; 162 241 exit(0); 163 242 } … … 191 270 { 192 271 switch(key) { 193 194 272 /* spacecraft controls */ 195 196 273 case GLUT_KEY_UP: 197 274 upWeGo = true; … … 213 290 { 214 291 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 215 216 glColor3f(0.0, 0.5, 0.6); 292 glColor3f(0.2, 0.0, 0.8); 217 293 glLoadIdentity(); 218 gluLookAt(0.0, -14.0, 15.0, 0.0 + alpha, 0.0 + beta, 0.0, 0.0, 1.0, 0.0);219 (*world).drawWorld();220 294 gluLookAt(0.0, -14.0, 15.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 295 // (*world).drawWorld(); diese und die naechste Zeile bedeuten das gleiche!!! 296 world->drawWorld((float)beta,(float)alpha); 221 297 glutSwapBuffers(); 222 298 } … … 225 301 void Orxonox::continousRedraw() 226 302 { 303 /* increment the frames-per-second counter*/ 304 305 fps++; 306 /* check for collisions */ 307 world->detectCollision(); 308 227 309 /* check for input to pass it over */ 228 if ( !pause && (rightWeGo || leftWeGo || upWeGo || downWeGo)) { 229 if (upWeGo) 230 (*io).goUp(); 231 if (downWeGo) 310 if ( !pause && inputEnabled && 311 (rightWeGo || leftWeGo || upWeGo || downWeGo || shoot1)) 312 { 313 if (upWeGo) 314 (*io).goUp(); 315 if (downWeGo) 232 316 (*io).goDown(); 233 if (rightWeGo)234 235 if (leftWeGo)317 if (rightWeGo) 318 (*io).goRight(); 319 if (leftWeGo) 236 320 (*io).goLeft(); 237 } 321 if (shoot1) 322 (*io).shoot(); 323 } 238 324 /* request repaint */ 239 240 //cout << "contiousRedraw" << endl;241 325 glutPostRedisplay(); 326 //cout << "Orxonox::continousRedraw" << endl; 242 327 } 243 328 … … 248 333 glMatrixMode(GL_PROJECTION); 249 334 glLoadIdentity(); 250 //glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0); pb: //simple and working251 335 glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 200.0); 252 //glFrustum(-10.0, 10.0, -5.0, 10.0, 0.0, 100.0);253 336 glMatrixMode(GL_MODELVIEW); 254 337 glLoadIdentity(); //pb why a second time? -
orxonox/branches/dave/core/orxonox.h
r1879 r1994 12 12 #include <GL/glut.h> 13 13 14 15 #include "environment.h" 14 16 #include "world.h" 15 17 #include "input_output.h" 16 18 #include "data_tank.h" 17 19 #include "stdincl.h" 18 20 #include "player.h" 19 21 20 22 … … 27 29 static World* world; 28 30 static InputOutput* io; 31 static Player* localPlayer; 29 32 static bool pause; 33 static bool inputEnabled; 30 34 static bool upWeGo; 31 35 static bool downWeGo; 32 36 static bool rightWeGo; 33 37 static bool leftWeGo; 38 static bool shoot1; 39 static int fps; 34 40 35 41 static int alpha; … … 38 44 static int offsetY; 39 45 46 static void timeSlice(int value); 47 40 48 public: 41 49 50 42 51 static Orxonox* getInstance (void); 43 44 52 int globalInit (int argc, char** argv); 45 53 int menuInit (void); … … 50 58 static void reshape (int w, int h); 51 59 static void keyboard(unsigned char key, int x, int y); 60 static void upKeyboard(unsigned char key, int x, int y); 52 61 static void releaseKey(int key, int x, int y); 53 62 static void specFunc(int key, int x, int y); -
orxonox/branches/dave/core/player.cc
r1883 r1994 19 19 #include "player.h" 20 20 #include <iostream> 21 #include <stdlib.h> 22 21 23 22 24 using namespace std; … … 24 26 25 27 Player::Player () { 28 // cout << "Player::Player" << endl; 26 29 xCor = yCor = zCor = 0; 30 shootLaser = new ShootLaser; 31 shootRocket = new ShootRocket; 27 32 } 28 33 29 30 31 Player::~Player () {} 34 Player::~Player () 35 { 36 //delete shootLaser; 37 } 32 38 33 39 … … 37 43 } 38 44 39 void Player::getPosition(float* x, float* y, float* z) 45 46 void Player::getPosition(float* x, float* y, float* z) 40 47 { 41 48 *x = xCor; *y = yCor; *z = zCor; 42 49 } 43 50 51 52 void Player::setCollisionRadius(float radius) 53 { 54 collisionRadius = radius; 55 } 56 57 44 58 void Player::goX(float x) 45 59 { 60 //cout << "Player::goX" << endl; 46 61 xCor += x; 47 62 } … … 58 73 } 59 74 60 void Player::shoot(int n) { 75 void Player::shoot(int n) 76 { 77 shootLaser->addShoot(xCor,yCor+1.0,5); 78 //shootLaser->addShootExt(xCor,yCor,zCor,.1,.4,.0); 79 //shootLaser->addShootdExt(xCor,yCor,zCor,-.1,.4,.0); 80 shootRocket->addBackParable(xCor,yCor,zCor); 81 82 83 61 84 } 62 63 85 64 86 //void Player::addIO(InputOutput *io) {} 65 87 66 88 67 void Player::drawPlayer( void)89 void Player::drawPlayer(float a, float b) 68 90 { 69 //cout << "Player::drawPlayer()" << endl; 70 //glColor3f(0.0, 0.9, 0.7); 71 //glRectf(-0.5 + yCor, -0.5 + xCor, 0.5 + yCor, 2.0 + xCor); 72 91 92 /*glPushMatrix(); 93 glTranslatef(xCor, yCor, 3.0); 94 glScalef(1.0, 3.0, 1.0); 95 glutWireCube(1.0); 96 glPopMatrix();*/ 73 97 glPushMatrix(); 74 glScalef(1.0, 3.0, 1.0); 75 glTranslatef(xCor, yCor, 3.0); 76 glutWireCube(1.0); 77 glPopMatrix(); 98 //glEnable(GL_DEPTH_TEST); 99 glTranslatef(xCor,yCor,5.0); 100 glRotatef(3*a,1.0,0.0,0.0); 101 glRotatef(3*b,0.0,1.0,0.0); 102 //glTranslatef(xCor,yCor,3.0); 103 glBegin(GL_QUADS); 104 glColor3f(1.0,0.0,0.0); 105 glNormal3f(-1.0,0.0,0.0); 106 glVertex3f(-1.0,-1.0,-1.0); 107 glVertex3f(-1.0,-1.0,1.0); 108 glVertex3f(-.6,1.0,0.4); 109 glVertex3f(-.6,1.0,-0.4); 110 111 glNormal3f(0.0,-1.0,0.0); 112 glColor3f(0.0,1.0,0.0); 113 glVertex3f(-.6,1.0,.4); 114 glVertex3f(-.6,1.0,-.4); 115 glVertex3f(.6,1.0,-.4); 116 glVertex3f(.6,1.0,.4); 117 118 glNormal3f(-1.0,0.0,0.0); 119 glColor3f(0.0,0.0,1.0); 120 glVertex3f(.6,1.0,.4); 121 glVertex3f(.6,1.0,-.4); 122 glVertex3f(1.0,-1.0,-1.0); 123 glVertex3f(1.0,-1.0,1.0); 124 125 126 127 glEnd(); 128 glPopMatrix(); 129 130 131 132 133 134 /* draw all the shoots additionaly */ 135 shootLaser->drawShoot(); 136 shootRocket->drawShoot(); 137 //cout << "Player::drawPlayer" << endl; 138 } 78 139 79 140 80 //cout << "x: " << xCor << " y: " << yCor << endl; 81 } 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 -
orxonox/branches/dave/core/player.h
r1879 r1994 6 6 #include <GL/glut.h> 7 7 8 //#include "input_output.h" 8 #include "shoot_laser.h" 9 #include "shoot_rocket.h" 10 #include "data_tank.h" 9 11 10 12 class Player { … … 14 16 ~Player (); 15 17 18 /* position of the spacecraft */ 19 float xCor; 20 float yCor; 21 float zCor; 22 23 float collisionRadius; 24 25 /* this player wanna shoot? so include a ref to ShootLaser */ 26 ShootLaser* shootLaser; 27 ShootRocket* shootRocket; 28 16 29 void setPosition(float x, float y, float z); 17 30 void getPosition(float* x, float* y, float* z); 31 void setCollisionRadius(float radius); 18 32 void goX(float x); 19 33 void goY(float y); … … 21 35 void shoot(int n); 22 36 // void addIO(InputOutput *io); 23 void drawPlayer( void);37 void drawPlayer(float a, float b); 24 38 25 39 private: 26 /* position of the space craft */27 float xCor;28 float yCor;29 float zCor;30 31 40 32 41 -
orxonox/branches/dave/core/proto_class.h
r1853 r1994 3 3 #define PROTO_CLASS_H 4 4 5 #include "data_tank.h" 5 6 6 7 class ProtoClass { 7 8 8 p rivate:9 public: 9 10 ProtoClass (); 10 11 ~ProtoClass (); -
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 -
orxonox/branches/dave/core/world.h
r1883 r1994 6 6 7 7 #include <stdlib.h> 8 #include <cmath> 9 8 10 9 11 #include "npc.h" 10 12 #include "player.h" 11 13 #include "environment.h" 14 #include "shoot_laser.h" 15 #include "shoot_rocket.h" 12 16 #include "stdincl.h" 17 #include "data_tank.h" 13 18 14 19 class World { … … 17 22 World (); 18 23 ~World (); 24 25 float primitiveMove; 19 26 20 27 /* for easier use: map the first two player here */ … … 47 54 envList* lastEnv; 48 55 56 57 58 49 59 bool addPlayer(Player* player); 50 60 bool removePlayer(Player* player); 51 61 Player* getLocalPlayer(); 52 53 62 bool addNPC(NPC* npc); 54 63 bool removeNPC(NPC* npc); 55 56 64 bool addEnv(Environment* env); 57 65 58 void drawWorld( void);66 void drawWorld(float Zahl1, float Zahl2); 59 67 void initEnvironement(void); 68 void setWorldStep(float step); 60 69 void updateWorld(void); 70 void detectCollision(void); 61 71 void testThaTest(void); 62 72 63 73 private: 64 74 float surface[120][120]; 75 float step; 65 76 66 77
Note: See TracChangeset
for help on using the changeset viewer.