Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1900 in orxonox.OLD for orxonox/trunk/core


Ignore:
Timestamp:
May 23, 2004, 11:21:38 PM (20 years ago)
Author:
patrick
Message:

orxonox/trunk: hardware independant game speed, more shoots, more speed - see mail

Location:
orxonox/trunk/core
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/core/input_output.cc

    r1896 r1900  
    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{
    4551  //cout << "InoutOutput::goUp" << endl;
    46   (*player).goY(STEP_FRONT);
     52  (*player).goY(step);
    4753}
    4854
    4955void InputOutput::goDown()
    5056{
    51   (*player).goY(-STEP_FRONT);
     57  (*player).goY(-step);
    5258}
    5359
    5460void InputOutput::goLeft()
    5561{
    56   (*player).goX(-STEP_SIDE);
     62  (*player).goX(-step);
    5763
    5864}
     
    6167{
    6268
    63   (*player).goX(STEP_SIDE);
     69  (*player).goX(step);
    6470}
    6571
  • orxonox/trunk/core/input_output.h

    r1896 r1900  
    99#include "player.h"
    1010
    11 #define STEP_SIDE 0.4
    12 #define STEP_FRONT 0.4
    1311
    1412class InputOutput {
     
    1816  Player* player;
    1917
     18  float step;
     19
    2020 public:
    2121  InputOutput (World* wld, Player* player);
    2222  ~InputOutput ();
    2323
     24  void setPlayerStep(float step);
    2425  void goUp(void);
    2526  void goDown(void);
  • orxonox/trunk/core/orxonox.cc

    r1899 r1900  
    5151Player* Orxonox::localPlayer = 0;
    5252bool Orxonox::pause = false;
     53bool Orxonox::inputEnabled = false;
    5354bool Orxonox::upWeGo = false;
    5455bool Orxonox::downWeGo = false;
     
    8788
    8889  glutTimerFunc(1000, timeSlice, 0);
     90  cout << "measuring performance...";
    8991}
    9092
     
    114116  world->addNPC(npc);
    115117
     118  NPC* npc2 = new NPC;
     119  npc2->setPosition(-2.0, 10.0, 3.0);
     120  npc2->setCollisionRadius(1.0);
     121  world->addNPC(npc2);
     122
    116123  glutSpecialFunc(specFunc);
    117124  glutSpecialUpFunc(releaseKey);
     
    126133void Orxonox::timeSlice(int value)
    127134{
    128   cout << "fps: " << fps << endl;
     135  cout << "got " << fps << endl;
     136  /* this is very very unsafe: io could be uninit */
     137  io->setPlayerStep(19.2 / fps); /* set player to propper speed */
     138  //localPlayer->shootLaser->setShootStep(fps/48.0); /* set shoot speed */
    129139  fps = 0;
     140  inputEnabled = true;
    130141  glutTimerFunc(1000, timeSlice, 0);
    131142}
     
    259270
    260271  /* check for input to pass it over */
    261   if ( !pause && (rightWeGo || leftWeGo || upWeGo || downWeGo || shoot1)) {
    262     if (upWeGo)
    263       (*io).goUp();
    264     if (downWeGo)
     272  if ( !pause && inputEnabled &&
     273       (rightWeGo || leftWeGo || upWeGo || downWeGo || shoot1))
     274    {
     275      if (upWeGo)
     276        (*io).goUp();
     277      if (downWeGo)
    265278      (*io).goDown();
    266     if (rightWeGo)
    267       (*io).goRight();
    268     if (leftWeGo)
     279      if (rightWeGo)
     280        (*io).goRight();
     281      if (leftWeGo)
    269282      (*io).goLeft();
    270     if (shoot1)
    271       (*io).shoot();
    272   }
     283      if (shoot1)
     284        (*io).shoot();
     285    }
    273286  /* request repaint */
    274287  glutPostRedisplay();
  • orxonox/trunk/core/orxonox.h

    r1897 r1900  
    3131  static Player* localPlayer;
    3232  static bool pause;
     33  static bool inputEnabled;
    3334  static bool upWeGo;
    3435  static bool downWeGo;
  • orxonox/trunk/core/player.cc

    r1899 r1900  
    4747}
    4848
     49
     50void Player::setCollisionRadius(float radius)
     51{
     52  collisionRadius = radius;
     53}
     54
     55
    4956void Player::goX(float x)
    5057{
     
    6774{
    6875  shootLaser->addShoot(xCor, yCor, zCor);
     76  shootLaser->addShootExt(xCor, yCor, zCor, .1, .4, .0);
     77  shootLaser->addShootExt(xCor, yCor, zCor, -0.1, .4, .0);
    6978  //cout << "Player::shoot" << endl;
    7079}
  • orxonox/trunk/core/player.h

    r1899 r1900  
    1919  float yCor;
    2020  float zCor;
     21 
     22  float collisionRadius;
    2123
    2224  /* this player wanna shoot? so include a ref to ShootLaser */
     
    2527  void setPosition(float x, float y, float z);
    2628  void getPosition(float* x, float* y, float* z);
     29  void setCollisionRadius(float radius);
    2730  void goX(float x);
    2831  void goY(float y);
  • orxonox/trunk/core/shoot_laser.cc

    r1899 r1900  
    2929{
    3030  lastShoot = null;
     31  step = 1.0;
    3132}
    3233
     
    4647      glPushMatrix();
    4748      glTranslatef(tmpShoot->xCor, tmpShoot->yCor, tmpShoot->zCor);
     49      tmpShoot->xCor+=tmpShoot->xInc;
    4850      tmpShoot->yCor+=tmpShoot->yInc;
    4951      glScalef(0.1, 0.1, 0.1);
     
    5557      /* fix2: conditions, that a struct tree can be cut off */
    5658      /* fix3: more efficent and nicer please */
    57       if (tmpShoot->yCor > 50)
     59      if (tmpShoot->yCor > 20)
    5860        {
     61          /* normal case: delete one element, link the others */
    5962          if (lastRef != null)
    6063            {
    61               cout << "garbage collection" << endl;
     64              //cout << "garbage collection" << endl;
    6265              lastRef->next = tmpShoot->next;
    6366              delete tmpShoot;
    64               tmpShoot = lastRef;         
    65               lastRef = tmpShoot;
    66               tmpShoot = tmpShoot->next;
    67               cout << "garbage collection left" << endl;
     67              tmpShoot = lastRef->next;
     68              //cout << "garbage collection left" << endl;
    6869            }
    6970          else
    7071            {
    71               cout << "garbage collecton on last el" << endl;
     72              /* special case: first element to be processed */
     73              //cout << "garbage collecton: first el in queue" << endl;
    7274              lastRef = tmpShoot->next;
    7375              delete tmpShoot;
    7476              tmpShoot = lastRef;
    75               if (tmpShoot != null) {
    76                 lastRef = tmpShoot;
    77                 tmpShoot = tmpShoot->next;
    78                 cout << "noch nich null" << endl;
    79               }
    80               else {
    81                 lastRef = null;
    82                 tmpShoot = null;
    83                 lastShoot = null;
    84                 cout << "endl null" << endl;
    85               }
    86               cout << "garbage collection on last el left" << endl;
     77              lastShoot = tmpShoot;
     78              if (tmpShoot != null)
     79                {
     80                  tmpShoot = tmpShoot->next;
     81                  //cout << "noch nich null" << endl;
     82                }
     83              else
     84                {
     85                  lastRef = null;
     86                  tmpShoot = null;
     87                  lastShoot = null;
     88                  //cout << "endl null" << endl;
     89                }
     90             
     91              //cout << "garbage collection: firtst el in queue left" << endl;
    8792            }
    8893        }
     
    108113  shoot* sh = new shoot;
    109114  sh->xCor = x; sh->yCor = y; sh->zCor = z;
    110   sh->xInc = 0; sh->yInc = .2; sh->zInc = 0;
     115  sh->xInc = 0; sh->yInc = .4/step; sh->zInc = 0;
    111116  sh->next = lastShoot;
    112117  lastShoot = sh;
    113118}
    114119
     120void ShootLaser::addShootExt(float x, float y, float z,
     121                             float xInc, float yInc, float zInc)
     122{
     123  //cout << "ShootLaser::addShootExtended" << endl;
     124  shoot* sh = new shoot;
     125  sh->xCor = x; sh->yCor = y; sh->zCor = z;
     126  sh->xInc = xInc/step; sh->yInc = yInc/step; sh->zInc = zInc/step;
     127  sh->next = lastShoot;
     128  lastShoot = sh;
     129}
     130
     131void ShootLaser::setShootStep(float step)
     132{
     133  cout << "ShootLaser::setShootStep to " << step << endl;
     134  this->step = step;
     135}
     136
     137
     138/* Exterminate shoot from game, implement this method  */
     139/* if you like to add animatiion */
     140void ShootLaser::removeShoot(shoot* sh)
     141{
     142  glPushMatrix();
     143  glTranslatef(sh->xCor, sh->yCor, sh->zCor);
     144  glutWireCube(1.0);
     145  glPopMatrix();
     146}
  • orxonox/trunk/core/shoot_laser.h

    r1899 r1900  
    2929  ~ShootLaser ();
    3030
    31   void drawShoot();
     31  void drawShoot(void);
    3232  void addShoot(shoot* sh);
    3333  void addShoot(float x, float y, float z);
     34  void addShootExt(float x, float y, float z, float xInc, float yInc, float zInc);
     35  void setShootStep(float step);
     36  void removeShoot(shoot* sh);
    3437
    3538
    3639 private:
    3740
     41  float step;
     42
    3843};
    3944
  • orxonox/trunk/core/world.cc

    r1899 r1900  
    1 
    21
    32/*
     
    232231void World::detectCollision()
    233232{
     233  //cout << "World::detectCollision" << endl;
    234234  float xOff, yOff, zOff, radius;
    235235  npcList* tmpNPC;
     
    263263  /* second: check if any player hits an enemy */
    264264
     265  /*
     266  tmpPlayer = lastPlayer;
     267  while( tmpPlayer != null )
     268    {
     269      tmpNPC = lastNPC;
     270      while( tmpNPC != null )
     271        {
     272          radius = tmpNPC->npc->collisionRadius + tmpPlayer->player->collisionRadius;
     273          xOff = tmpPlayer->player->xCor - tmpNPC->npc->xCor;
     274          yOff = tmpPlayer->player->yCor - tmpNPC->npc->yCor;
     275          zOff = tmpPlayer->player->zCor - tmpNPC->npc->zCor;
     276          if ( sqrt(xOff*xOff + yOff*yOff + zOff*zOff) < radius )
     277            cout << "COLLISION " << endl;
     278         
     279          tmpNPC = tmpNPC->next;
     280        }
     281     
     282      tmpPlayer = tmpPlayer->next;
     283    }
     284 
     285  */
     286
    265287  /* third: check if any enemy shoots a player */
    266288
Note: See TracChangeset for help on using the changeset viewer.