Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1994 in orxonox.OLD for orxonox/branches/dave


Ignore:
Timestamp:
Jun 21, 2004, 12:39:11 AM (20 years ago)
Author:
dave
Message:

orxonox/branches/dave:[test the Shit]

Location:
orxonox/branches/dave/core
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/dave/core/Makefile

    r1883 r1994  
    2929        orxonox.h \
    3030        data_core.h
    31        
     31
    3232SOURCES = \
    3333        orxonox.cc \
     
    4141        world.o \
    4242        input_output.o \
    43         environment.o
     43        environment.o \
     44        shoot_laser.o \
     45        shoot_rocket.o \
     46        ai.o
    4447
    4548TARGET = orxonox
     
    7376        @echo ""
    7477        @echo "For further info see the README file"
    75        
     78
    7679clean:
    7780        rm -rf *.o *~ orxonox
     
    8588#data_tank.o: data_tank.cc \
    8689#               data_tank.h     
    87        
     90
    8891#EOF
  • orxonox/branches/dave/core/data_tank.cc

    r1856 r1994  
    1919using namespace std;
    2020
     21float DataTank::xOffset = 0;
     22float DataTank::yOffset = 0;
     23float DataTank::zOffset = 0;
    2124
    2225DataTank::DataTank () {}
    23 
    24 
    25 
    2626DataTank::~DataTank () {}
    2727
  • orxonox/branches/dave/core/data_tank.h

    r1850 r1994  
    66class DataTank {
    77
    8  private:
     8 public:
    99  DataTank ();
    1010  ~DataTank ();
     11
     12  static float xOffset;
     13  static float yOffset;
     14  static float zOffset;
    1115
    1216};
  • orxonox/branches/dave/core/environment.cc

    r1883 r1994  
    2323using namespace std;
    2424
    25 
     25//Sorry Bensch
     26#define LEVEL_LENGTH 500
    2627
    2728Environment::Environment ()
    2829{
    2930
    30   for (int x = 1; x < 9; x++)
     31  //Sorry Bensch: x,y = 10
     32  for (int x = 0; x < 50; x++)
    3133    {
    32       for (int y = 1; y < 9; y++)
     34      for (int y = 0; y < 50; y++)
    3335        {
    34           mountainTest[x][y] = (float)random() / 900000000;
     36          mountainTest[x][y] =0;
    3537                                                 
    3638        }
    3739    }
    38 
    39  for (int x = 0; x < 10; x++)
     40  //Sorry Bensch: x,y = 9
     41  for (int x = 1; x < LEVEL_LENGTH; x++)
    4042    {
    41       for (int y = 0; y < 10; y++)
     43      for (int y = 1; y < LEVEL_LENGTH; y++)
    4244        {
    43           cout << " " << mountainTest[x][y] << " ";
    44          
     45          //mountainTest[x][y] = (float)random() / 900000000;
     46          mountainTest[x][y] = (float)(random() % 4);                                       
    4547        }
    46       cout << endl;
    4748    }
    4849}
     
    5758{
    5859  glPushMatrix();
     60  glEnable(GL_DEPTH_TEST);
    5961  //glScalef(0.5, 0.5, 1.0);
    6062  //glTranslatef(xCor, yCor, zCor);
    61   glTranslatef( -16.0, -2.0, 0.0);
     63  glTranslatef( -100.0, -50.0, 0.0);
    6264 
    63   glColor3f(0.0, 1.0, 0.0);
     65  glColor4f(0.0, 0.3, 0.4,1.0);
    6466 
    6567  glBegin(GL_LINES);
    66   for (int x = 0; x < 10; x += 1)
     68  for (int x = 0; x < LEVEL_LENGTH; x += 1)
    6769    {
    68       for (int y = 0; y < 10; y += 1)
     70      for (int y = 0; y < 190; y += 1)
    6971        {
    7072          glVertex3f((float)(2*x), (float)(2*y), mountainTest[x][y]);
     
    7678 
    7779  glBegin(GL_LINES);
    78   for (int y = 0; y < 10; y += 1)
     80  for (int y = 0; y < LEVEL_LENGTH; y += 1)
    7981    {
    80       for (int x = 0; x < 10; x += 1)
     82      for (int x = 0; x < 90; x += 1)
    8183        {
    8284          glVertex3f((float)(2*x), (float)(2*y), mountainTest[x][y]);
  • orxonox/branches/dave/core/environment.h

    r1883 r1994  
    33#include <stdlib.h>
    44
    5 #ifndef PROTO_CLASS_H
    6 #define PROTO_CLASS_H
     5#ifndef ENVIRONEMENT_H
     6#define ENVIRONEMENT_H
    77
    8 
     8#include "data_tank.h"
    99
    1010class Environment {
  • orxonox/branches/dave/core/input_output.cc

    r1879 r1994  
    4040
    4141
     42void InputOutput::setPlayerStep(float step)
     43{
     44  cout << "setting player step to: " << step << endl;
     45  this->step = step;
     46}
     47
    4248
    4349void InputOutput::goUp()
    4450{
    45   (*player).goY(STEP_FRONT);
     51  //cout << "InoutOutput::goUp" << endl;
     52  (*player).goY(step);
    4653}
    4754
    4855void InputOutput::goDown()
    4956{
    50   (*player).goY(-STEP_FRONT);
     57  (*player).goY(-step);
    5158}
    5259
    5360void InputOutput::goLeft()
    5461{
    55   (*player).goX(-STEP_SIDE);
     62  (*player).goX(-step);
    5663
    5764}
     
    6067{
    6168
    62   (*player).goX(STEP_SIDE);
     69  (*player).goX(step);
    6370}
    6471
  • orxonox/branches/dave/core/input_output.h

    r1879 r1994  
    99#include "player.h"
    1010
    11 #define STEP_SIDE 0.4
    12 #define STEP_FRONT 0.2
     11#include "data_tank.h"
    1312
    1413class InputOutput {
     
    1817  Player* player;
    1918
     19  float step;
     20
    2021 public:
    2122  InputOutput (World* wld, Player* player);
    2223  ~InputOutput ();
    2324
     25  void setPlayerStep(float step);
    2426  void goUp(void);
    2527  void goDown(void);
  • orxonox/branches/dave/core/npc.cc

    r1858 r1994  
    2121#include <iostream>
    2222
     23
    2324using namespace std;
    2425
    2526
    26 NPC::NPC () {}
    27 
    28 
     27NPC::NPC ()
     28{
     29  hasDied = 0;
     30}
    2931
    3032NPC::~NPC () {}
    3133
    3234
    33 void NPC::setPosition(int x, int y, int z)
     35void NPC::setPosition(float x, float y, float z)
    3436{
    3537  xCor = x; yCor = y; zCor = z;
    3638}
    3739
    38 void NPC::getPosition(int* x, int* y, int* z)
     40void NPC::getPosition(float* x, float* y, float* z)
    3941{
    4042  *x = xCor;
     
    4345}
    4446
     47void NPC::setCollisionRadius(float r)
     48{
     49  collisionRadius = r;
     50}
     51
     52float NPC::getCollisionRadius()
     53{
     54  return collisionRadius;
     55}
     56
     57
     58void NPC::addAI(AI* ai)
     59{
     60
     61}
    4562
    4663void NPC::drawNPC(void)
    4764{
    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  }
    4974}
     75
     76
     77/* define the reaction, if the ship is been hit */
     78int NPC::hit()
     79{
     80  die();
     81  return 0;
     82}
     83
     84void NPC::die()
     85{
     86  hasDied = 1;
     87}
  • orxonox/branches/dave/core/npc.h

    r1858 r1994  
    33#define NPC_H
    44
     5/* openGL Headers */
     6#include <GL/glut.h>
     7
     8#include "ai.h"
     9#include "data_tank.h"
    510
    611class NPC {
     
    1015  ~NPC ();
    1116
     17  /* collision control */
     18  float collisionRadius;
     19
     20  float xCor;
     21  float yCor;
     22  float zCor;
     23
    1224  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);
    1532
    1633 private:
     
    1835
    1936  int npcType;
     37  int hasDied;
    2038
    21   int xCor;
    22   int yCor;
    23   int zCor;
     39
    2440;
    2541
  • orxonox/branches/dave/core/orxonox.cc

    r1883 r1994  
    2626/* class definition header */
    2727#include "orxonox.h"
    28 #include "environment.h"
    2928
    3029
     
    5049World* Orxonox::world = 0;
    5150InputOutput* Orxonox::io = 0;
     51Player* Orxonox::localPlayer = 0;
    5252bool Orxonox::pause = false;
     53bool Orxonox::inputEnabled = false;
    5354bool Orxonox::upWeGo = false;
    5455bool Orxonox::downWeGo = false;
    5556bool Orxonox::rightWeGo = false;
    5657bool Orxonox::leftWeGo = false;
     58bool Orxonox::shoot1 = false;
     59int Orxonox::fps = 0;
    5760int Orxonox::alpha = 0;
    5861int Orxonox::beta = 0;
     
    7073int Orxonox::globalInit (int argc, char** argv)
    7174{
     75  glEnable(GL_DEPTH_TEST);
     76  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    7277  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);
    7697  //glutFullScreen();
    77   glutInitWindowPosition(100, 100);
     98  glutInitWindowPosition(200, 200);
    7899  glutCreateWindow("orxOnox");
    79   glShadeModel(GL_FLAT);
     100  glShadeModel(GL_SMOOTH);
    80101  /* window event dispatchers */
    81102  glutDisplayFunc(display);
    82103  glutReshapeFunc(reshape);
    83104  glutKeyboardFunc(keyboard);
     105  glutKeyboardUpFunc(upKeyboard);
     106 
     107
     108  glutTimerFunc(1000, timeSlice, 0);
     109  cout << "measuring performance...";
    84110}
    85111
     
    87113int Orxonox::menuInit (void)
    88114{
    89   glClearColor(0.0, 0.0, 0.0, 0.0);
     115  glClearColor(0.0, 0.0, 0.0,1.0);
    90116}
    91117
     
    93119int Orxonox::gameInit (void)
    94120{
    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 */
    96124  world = new World;
    97125  (*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);
    99129  io = new InputOutput(world, localPlayer);
    100130  (*world).addPlayer(localPlayer);
     
    102132  (*world).addEnv(env);
    103133 
     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);
    104159
    105160  glutSpecialFunc(specFunc);
    106161  glutSpecialUpFunc(releaseKey);
    107162
    108   //for testing purps only
    109   //testTheShit();
    110163  glutIdleFunc(continousRedraw);
    111 }
     164  //cout << "Orxonox::gameInit" << endl;
     165}
     166
     167
     168/* this is the time triggered function. heart beat*/
     169
     170void 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
    112182
    113183
     
    131201
    132202    /* game controls */
    133 
    134203  case 'p':
    135204    if (pause)
     
    146215      }
    147216    break;
     217  case 32:
     218    shoot1 = true;
     219    break;
    148220  case 27:
    149221  case 'q':
     
    154226
    155227
     228void 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
    156238void Orxonox::quitGame()
    157239{
    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;
    162241  exit(0);
    163242}
     
    191270{
    192271  switch(key) {
    193 
    194272    /* spacecraft controls */
    195    
    196273  case GLUT_KEY_UP:
    197274    upWeGo = true;
     
    213290{
    214291  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);
    217293  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);
    221297  glutSwapBuffers();
    222298}
     
    225301void Orxonox::continousRedraw()
    226302{
     303  /* increment the frames-per-second counter*/
     304 
     305  fps++;
     306  /* check for collisions */
     307  world->detectCollision();
     308
    227309  /* 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)
    232316      (*io).goDown();
    233     if (rightWeGo)
    234       (*io).goRight();
    235     if (leftWeGo)
     317      if (rightWeGo)
     318        (*io).goRight();
     319      if (leftWeGo)
    236320      (*io).goLeft();
    237   }
     321      if (shoot1)
     322        (*io).shoot();
     323    }
    238324  /* request repaint */
    239 
    240   //cout << "contiousRedraw" << endl;
    241325  glutPostRedisplay();
     326  //cout << "Orxonox::continousRedraw" << endl;
    242327}
    243328
     
    248333  glMatrixMode(GL_PROJECTION);
    249334  glLoadIdentity();
    250   //glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0); pb: //simple and working
    251335  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);
    253336  glMatrixMode(GL_MODELVIEW);
    254337  glLoadIdentity(); //pb why a second time?
  • orxonox/branches/dave/core/orxonox.h

    r1879 r1994  
    1212#include <GL/glut.h>
    1313
     14
     15#include "environment.h"
    1416#include "world.h"
    1517#include "input_output.h"
    1618#include "data_tank.h"
    1719#include "stdincl.h"
    18 
     20#include "player.h"
    1921
    2022
     
    2729  static World* world;
    2830  static InputOutput* io;
     31  static Player* localPlayer;
    2932  static bool pause;
     33  static bool inputEnabled;
    3034  static bool upWeGo;
    3135  static bool downWeGo;
    3236  static bool rightWeGo;
    3337  static bool leftWeGo;
     38  static bool shoot1;
     39  static int fps;
    3440
    3541  static int alpha;
     
    3844  static int offsetY;
    3945
     46  static void timeSlice(int value);
     47
    4048 public:
    4149
     50   
    4251  static Orxonox* getInstance (void);
    43 
    4452  int globalInit (int argc, char** argv);
    4553  int menuInit (void);
     
    5058  static void reshape (int w, int h);
    5159  static void keyboard(unsigned char key, int x, int y);
     60  static void upKeyboard(unsigned char key, int x, int y);
    5261  static void releaseKey(int key, int x, int y);
    5362  static void specFunc(int key, int x, int y);
  • orxonox/branches/dave/core/player.cc

    r1883 r1994  
    1919#include "player.h"
    2020#include <iostream>
     21#include <stdlib.h>
     22
    2123
    2224using namespace std;
     
    2426
    2527Player::Player () {
     28  // cout << "Player::Player" << endl;
    2629  xCor = yCor = zCor = 0;
     30  shootLaser = new ShootLaser;
     31  shootRocket = new ShootRocket;
    2732}
    2833
    29 
    30 
    31 Player::~Player () {}
     34Player::~Player ()
     35{
     36  //delete shootLaser;
     37}
    3238
    3339
     
    3743}
    3844
    39 void Player::getPosition(float* x, float* y, float* z)
     45
     46void Player::getPosition(float* x, float* y, float* z)
    4047{
    4148  *x = xCor; *y = yCor; *z = zCor;
    4249}
    4350
     51
     52void Player::setCollisionRadius(float radius)
     53{
     54  collisionRadius = radius;
     55}
     56
     57
    4458void Player::goX(float x)
    4559{
     60  //cout << "Player::goX" << endl;
    4661  xCor += x;
    4762}
     
    5873}
    5974
    60 void Player::shoot(int n) {
     75void 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
    6184}
    62 
    6385
    6486//void Player::addIO(InputOutput *io) {}
    6587
    6688
    67 void Player::drawPlayer(void)
     89void Player::drawPlayer(float a, float b)
    6890{
    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();*/
    7397  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}
    78139
    79140
    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  
    66#include <GL/glut.h>
    77
    8 //#include "input_output.h"
     8#include "shoot_laser.h"
     9#include "shoot_rocket.h"
     10#include "data_tank.h"
    911
    1012class Player {
     
    1416  ~Player ();
    1517
     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
    1629  void setPosition(float x, float y, float z);
    1730  void getPosition(float* x, float* y, float* z);
     31  void setCollisionRadius(float radius);
    1832  void goX(float x);
    1933  void goY(float y);
     
    2135  void shoot(int n);
    2236  //  void addIO(InputOutput *io);
    23   void drawPlayer(void);
     37  void drawPlayer(float a, float b);
    2438
    2539 private:
    26   /* position of the space craft */
    27   float xCor;
    28   float yCor;
    29   float zCor;
    30 
    3140
    3241
  • orxonox/branches/dave/core/proto_class.h

    r1853 r1994  
    33#define PROTO_CLASS_H
    44
     5#include "data_tank.h"
    56
    67class ProtoClass {
    78
    8  private:
     9 public:
    910  ProtoClass ();
    1011  ~ProtoClass ();
  • orxonox/branches/dave/core/world.cc

    r1883 r1994  
    1 
    21
    32/*
     
    3332  lastNPC = null;
    3433  lastEnv = null;
     34  primitiveMove = 0;
     35  step = 0;
    3536}
    3637
     
    104105
    105106/**
     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*/
     112bool 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/**
    106144   \brief Add environmental object
    107145   \param player A reference to the new env object
     
    127165
    128166
    129 /**
    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 
    139167
    140168
     
    144172   Calls the draw function of all: Objects, Players, Environement. This is the core of all graphics here.
    145173*/
    146 void World::drawWorld(void)
    147 {
     174void 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 
    148182  /* first draw all players */
    149183  playerList* tmpPlayer = lastPlayer;
     
    151185  while( tmpPlayer != null )
    152186    {
    153       (*tmpPlayer->player).drawPlayer();
     187      (*tmpPlayer->player).drawPlayer((float)Zahl1,(float)Zahl2);
    154188      tmpPlayer = tmpPlayer->next;
    155189    }
     
    161195      tmpNPC = tmpNPC->next;
    162196    }
     197
    163198  /* now draw the rest of the world: environement */
    164   /* second draw all npcs */
    165199  envList* tmpEnv = lastEnv;
    166200  while( tmpEnv != null )
     
    169203      tmpEnv = tmpEnv->next;
    170204    }
    171 
    172   /*
    173   glColor3f(0.0, 1.0, 0.0);
     205 
     206  /* draw the ground grid  */
     207  glColor3f(0.3, 0.3, 0.0);
    174208  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        }
    187217    }
    188218  glEnd();
    189   */
    190  
    191  
    192   glColor3f(0.0, 1.0, 0.0);
    193219 
    194220  glBegin(GL_LINES);
     
    201227        }
    202228    }
    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
    216241 
    217242}
     
    231256
    232257
     258void World::setWorldStep(float step)
     259{
     260  this->step = step;
     261  cout << "setting speed to " << step << endl;
     262}
     263
     264
     265
    233266/**
    234267   \brief Updates the world and all its objects
     
    241274 
    242275
     276}
     277
     278
     279/* collision detection */
     280/* fix: bad efficency: stupid brute force */
     281
     282void 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;
    243362}
    244363
  • orxonox/branches/dave/core/world.h

    r1883 r1994  
    66
    77#include <stdlib.h>
     8#include <cmath>
     9
    810
    911#include "npc.h"
    1012#include "player.h"
    1113#include "environment.h"
     14#include "shoot_laser.h"
     15#include "shoot_rocket.h"
    1216#include "stdincl.h"
     17#include "data_tank.h"
    1318
    1419class World {
     
    1722  World ();
    1823  ~World ();
     24
     25  float primitiveMove;
    1926
    2027  /* for easier use: map the first two player here */
     
    4754  envList* lastEnv;
    4855
     56
     57
     58
    4959  bool addPlayer(Player* player);
    5060  bool removePlayer(Player* player);
    5161  Player* getLocalPlayer();
    52 
    5362  bool addNPC(NPC* npc);
    5463  bool removeNPC(NPC* npc);
    55 
    5664  bool addEnv(Environment* env);
    5765
    58   void drawWorld(void);
     66  void drawWorld(float Zahl1, float Zahl2);
    5967  void initEnvironement(void);
     68  void setWorldStep(float step);
    6069  void updateWorld(void);
     70  void detectCollision(void);
    6171  void testThaTest(void);
    6272
    6373 private:
    6474  float surface[120][120];
     75  float step;
    6576
    6677
Note: See TracChangeset for help on using the changeset viewer.