Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6804 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Jan 28, 2006, 11:29:03 AM (19 years ago)
Author:
bensch
Message:

trunk: remastered Playables a bit

Location:
trunk/src/world_entities
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/creatures/md2_creature.cc

    r6561 r6804  
    3939
    4040CREATE_FACTORY(MD2Creature, CL_MD2_CREATURE);
    41 
    42 /**
    43  *  creates the controlable MD2Creature
    44  */
    45 MD2Creature::MD2Creature()
    46 {
    47   this->init();
    48 }
    4941
    5042/**
     
    231223void MD2Creature::collidesWith(WorldEntity* entity, const Vector& location)
    232224{
    233   if (entity->isA(CL_TURRET_POWER_UP) )
    234   {
    235     this->ADDWEAPON();
    236     }
    237 //  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
     225
    238226}
    239227
     
    254242void MD2Creature::tick (float time)
    255243{
     244  Playable::tick(time);
    256245  if( likely(this->getModel(0) != NULL))
    257246    ((MD2Model*)this->getModel(0))->tick(time);
     
    284273  this->setAbsDir(mouseDirX);
    285274  this->cameraConnNode.setRelDir(mouseDirY);
    286 
    287   this->getWeaponManager()->tick(time);
    288   // weapon system manipulation
    289   this->weaponAction();
    290275}
    291276
     
    348333
    349334
    350 /**
    351  * weapon manipulation by the player
    352 */
    353 void MD2Creature::weaponAction()
    354 {
    355   if( this->bFire)
    356     {
    357       this->getWeaponManager()->fire();
    358     }
    359 }
    360335
    361336/**
     
    364339void MD2Creature::process(const Event &event)
    365340{
     341  Playable::process(event);
    366342  if( event.type == SDLK_a)
    367343      this->bStrafeL = event.bPressed;
    368344  else if( event.type == SDLK_d)
    369345      this->bStrafeR = event.bPressed;
    370   else if( event.type == KeyMapper::PEV_FIRE1)
    371       this->bFire = event.bPressed;
    372   else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
    373     this->getWeaponManager()->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange;
    374   else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
    375     this->getWeaponManager()->previousWeaponConfig();
    376346  else if( event.type == SDLK_w)
    377347    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
     
    390360  }
    391361}
    392 
    393 #include "weapons/aiming_turret.h"
    394 // FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG
    395 void MD2Creature::ADDWEAPON()
    396 {
    397   Weapon* turret = NULL;
    398 
    399   if ((float)rand()/RAND_MAX < .1)
    400   {
    401     //if (this->getWeaponManager()->hasFreeSlot(2, WTYPE_TURRET))
    402     {
    403       turret = new Turret();
    404       this->getWeaponManager()->addWeapon(turret, 2);
    405       this->getWeaponManager()->changeWeaponConfig(2);
    406     }
    407   }
    408   else
    409   {
    410     //if (this->getWeaponManager()->hasFreeSlot(3))
    411     {
    412       turret = new AimingTurret();
    413       this->getWeaponManager()->addWeapon(turret, 3);
    414 
    415       this->getWeaponManager()->changeWeaponConfig(3);
    416     }
    417   }
    418 
    419   if(turret != NULL)
    420   {
    421     turret->setName("Turret");
    422     turret->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1);
    423   }
    424 }
  • trunk/src/world_entities/creatures/md2_creature.h

    r6561 r6804  
    1919  public:
    2020
    21     MD2Creature();
    2221    MD2Creature(const char* fileName);
    23     MD2Creature(const TiXmlElement* root);
     22    MD2Creature(const TiXmlElement* root = NULL);
    2423    virtual ~MD2Creature();
    2524
    26     void init();
    2725    virtual void loadParams(const TiXmlElement* root);
    2826
     
    4240
    4341  private:
     42    void init();
    4443
    4544    void calculateVelocity(float time);
    46     void weaponAction();
    47 
    48     // !! temporary !!
    49     void ADDWEAPON();
    5045
    5146    bool                  bUp;                //!< up button pressed.
  • trunk/src/world_entities/playable.cc

    r6710 r6804  
    3838  // the reference to the Current Player is NULL, because we dont have one at the beginning.
    3939  this->currentPlayer = NULL;
     40
     41  this->bFire = false;
    4042
    4143  this->setSynchronized(true);
     
    201203}
    202204
     205/**
     206 * @brief ticks a Playable
     207 * @param dt: the passed time since the last Tick
     208 */
     209void Playable::tick(float dt)
     210{
     211  this->weaponMan->tick(dt);
     212  if (this->bFire)
     213    weaponMan->fire();
     214}
     215
     216
     217/**
     218 * @brief processes Playable events.
     219 * @param event the Captured Event.
     220 */
     221void Playable::process(const Event &event)
     222{
     223  if( event.type == KeyMapper::PEV_FIRE1)
     224    this->bFire = event.bPressed;
     225  else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
     226  {
     227    this->nextWeaponConfig();
     228  }
     229  else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
     230    this->previousWeaponConfig();
     231}
     232
     233
    203234
    204235void  Playable::attachCamera()
     
    210241
    211242
     243
     244
    212245void  Playable::detachCamera()
    213246{
  • trunk/src/world_entities/playable.h

    r6568 r6804  
    2525{
    2626  public:
    27     Playable();
    2827    virtual ~Playable();
    2928
     
    4948
    5049    virtual void collidesWith(WorldEntity* entity, const Vector& location);
    51     virtual void process(const Event &event) = 0;
     50    virtual void process(const Event &event);
    5251
    53 
     52    virtual void tick(float dt);
    5453
    5554    /** @return a List of Events in PEV_* sytle */
     
    5756
    5857  protected:
     58    Playable();
     59
    5960    void registerEvent(int eventType);
    6061    void unregisterEvent(int eventType);
     
    6667    Player*               currentPlayer;      //!< The Player currently connected to this Playable (the one that has controll) otherwise NULL
    6768
     69    bool                  bFire;              //!< If the Ship is firing.
     70
    6871};
    6972
  • trunk/src/world_entities/space_ships/helicopter.cc

    r6724 r6804  
    124124
    125125  //cycle = 0.0;
    126  
     126
    127127  // cameraissue
    128128  this->cameraNode.setParent(this);
    129129  this->cameraNode.setParentMode(PNODE_ALL);
    130  
    131  
     130
     131
    132132  // rotors
    133133  this->topRotor.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
    134134  this->tailRotor.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
    135  
     135
    136136  this->topRotor.setParent(this);
    137137  this->tailRotor.setParent(this);
    138  
     138
    139139  this->topRotor.setRelCoor(Vector(-0.877,0.627,0));
    140140  this->tailRotor.setRelCoor(Vector(-4.43,0.297,0.068));
    141141  this->tailRotor.setAbsDir(Quaternion(M_PI_2,Vector(1,0,0)));
    142  
     142
    143143  this->loadModel("models/ships/rotor.obj",1.0,3);
    144144  this->loadModel("models/ships/rotor.obj",0.2,4);
     
    274274void Helicopter::tick (float time)
    275275{
     276  Playable::tick(time);
     277
    276278  if( xMouse != 0 || yMouse != 0)
    277279   {
     
    281283    else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY;
    282284  }
    283  
     285
    284286  // rotorrotation
    285287  this->topRotor.shiftDir(Quaternion(time*10, Vector(0,1,0)));
    286288  this->tailRotor.shiftDir(Quaternion(time*10, Vector(0,1,0)));
    287  
     289
    288290  // spaceship controlled movement
    289291  this->calculateVelocity(time);
     
    293295  // this is the air friction (necessary for a smooth control)
    294296  if(velocity.len() != 0) velocity -= velocity*0.1;
    295  
     297
    296298  //travelSpeed = velocity.len();
    297299
     
    301303  this->shiftCoor(getAbsDirY()*rotorspeed);
    302304  */
    303  
     305
    304306  /*
    305307  //hoover effect
     
    316318  this->shiftCoor (move);
    317319  //this->shiftDir(Quaternion(-M_PI/4*tailrotorspeed, Vector(0,1,0)));
    318 
    319   this->getWeaponManager()->tick(time);
    320   // weapon system manipulation
    321   this->weaponAction();
    322320}
    323321
     
    338336     //this->shiftCoor(this->getAbsDirX());
    339337     //accel -= this->getAbsDirY();
    340      
     338
    341339     accel += Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z);
    342340     if((this->getAbsDirX()).y >= -0.1) rotValZ -= time;
     
    351349     //this->shiftCoor((this->getAbsDirX())*-1);
    352350     //accel -= this->getAbsDirY();
    353      
     351
    354352     accel -= Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z);
    355353     rotValZ += time;
     
    365363    //accel -= this->getAbsDirY();
    366364    //velocityDir.normalize();
    367    
     365
    368366    accel -= Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z);
    369367    rotValX -= time;
     
    379377    //accel += this->getAbsDirY();
    380378    //velocityDir.normalize();
    381    
     379
    382380    accel += Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z);
    383381    rotValX += time;
     
    446444{
    447445  WorldEntity::draw();
    448  
     446
    449447  glMatrixMode(GL_MODELVIEW);
    450448    glPushMatrix();
     
    474472}
    475473
    476 
    477 /**
    478  * weapon manipulation by the player
    479 */
    480 void Helicopter::weaponAction()
    481 {
    482   if( this->bFire)
    483     {
    484       this->getWeaponManager()->fire();
    485     }
    486 }
    487 
    488474/**
    489475 * @todo switch statement ??
     
    491477void Helicopter::process(const Event &event)
    492478{
    493 
     479  Playable::process(event);
    494480
    495481  if( event.type == KeyMapper::PEV_LEFT)
     
    497483  else if( event.type == KeyMapper::PEV_RIGHT)
    498484      this->bRight = event.bPressed;
    499   else if( event.type == KeyMapper::PEV_FIRE1)
    500       this->bFire = event.bPressed;
    501   else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
    502     this->getWeaponManager()->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange;
    503   else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
    504     this->getWeaponManager()->previousWeaponConfig();
    505485  else if( event.type == SDLK_e)
    506486    this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0);
     
    517497
    518498    this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0)));
    519    
     499
    520500    Quaternion yDir = Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1));
    521501
    522    
     502
    523503    if ((this->cameraNode.getAbsDirY()).y < 0.5)
    524504    {
  • trunk/src/world_entities/space_ships/helicopter.h

    r6724 r6804  
    2121    virtual ~Helicopter();
    2222
    23     void init();
    2423    virtual void loadParams(const TiXmlElement* root);
    2524
     
    4039
    4140  private:
     41    void init();
    4242    void calculateVelocity(float time);
    43     void weaponAction();
    4443
    4544    // !! temporary !!
     
    6362    int                   controlVelocityY;
    6463    //float                 cycle;              //!< hovercycle
    65    
     64
    6665    PNode                 topRotor;
    6766    PNode                 tailRotor;
    68    
     67
    6968    PNode                 cameraNode;
    7069
  • trunk/src/world_entities/space_ships/hover.cc

    r6803 r6804  
    252252 * @param time The timespan passed since last update
    253253*/
    254 void Hover::tick (float time)
    255 {
     254void Hover::tick (float dt)
     255{
     256  Playable::tick(dt);
     257
    256258  if( xMouse != 0 || yMouse != 0)
    257259   {
     
    263265
    264266  // spaceship controlled movement
    265   this->calculateVelocity(time);
    266 
    267   Vector move = (velocity)*time;
     267  this->calculateVelocity(dt);
     268
     269  Vector move = (velocity)*dt;
    268270
    269271  // this is the air friction (necessary for a smooth control)
     
    271273  this->shiftCoor (move);
    272274
    273   this->getWeaponManager()->tick(time);
    274   // weapon system manipulation
    275   this->weaponAction();
    276275}
    277276
     
    400399{
    401400  Vector tmpRot;
    402 
    403401  WorldEntity::draw();
    404402
     
    463461void Hover::process(const Event &event)
    464462{
    465 
     463  Playable::process(event);
    466464
    467465  if( event.type == KeyMapper::PEV_LEFT)
     
    469467  else if( event.type == KeyMapper::PEV_RIGHT)
    470468      this->bRight = event.bPressed;
    471   else if( event.type == KeyMapper::PEV_FIRE1)
    472       this->bFire = event.bPressed;
    473   else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
    474     this->getWeaponManager()->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange;
    475   else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
    476     this->getWeaponManager()->previousWeaponConfig();
    477469  else if( event.type == SDLK_e)
    478470    this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0);
  • trunk/src/world_entities/space_ships/space_ship.cc

    r6803 r6804  
    306306void SpaceShip::tick (float time)
    307307{
    308   this->getWeaponManager()->tick(time);
    309   // weapon system manipulation
    310   this->weaponAction();
     308  Playable::tick(time);
    311309
    312310  if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == this->getHostID() )
     
    464462
    465463/**
    466  * weapon manipulation by the player
    467 */
    468 void SpaceShip::weaponAction()
    469 {
    470   if( this->bFire)
    471     {
    472       this->getWeaponManager()->fire();
    473     }
    474 }
    475 
    476 /**
    477464 * @todo switch statement ??
    478465 */
    479466void SpaceShip::process(const Event &event)
    480467{
     468  Playable::process(event);
     469
    481470  if( event.type == KeyMapper::PEV_LEFT)
    482471      this->bRollL = event.bPressed;
    483472  else if( event.type == KeyMapper::PEV_RIGHT)
    484473      this->bRollR = event.bPressed;
    485   else if( event.type == KeyMapper::PEV_FIRE1)
    486       this->bFire = event.bPressed;
    487   else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
    488   {
    489     this->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange;
    490   }
    491   else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
    492     this->previousWeaponConfig();
    493474  else if( event.type == KeyMapper::PEV_UP)
    494475    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
  • trunk/src/world_entities/space_ships/space_ship.h

    r6756 r6804  
    2727    virtual ~SpaceShip();
    2828
    29     void init();
    3029    virtual void loadParams(const TiXmlElement* root);
    3130
     
    4746
    4847  private:
     48    void init();
    4949
    5050    void calculateVelocity(float time);
    51     void weaponAction();
    5251
    5352    // !! temporary !!
Note: See TracChangeset for help on using the changeset viewer.