Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10019 in orxonox.OLD for branches/playability


Ignore:
Timestamp:
Dec 5, 2006, 10:47:43 PM (18 years ago)
Author:
muellmic
Message:

finally: vertical scroller moves implemented :-)

Location:
branches/playability/src/world_entities/space_ships
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/playability/src/world_entities/space_ships/space_ship.cc

    r10017 r10019  
    9090 */
    9191SpaceShip::SpaceShip(const std::string& fileName)
    92     : secWeaponMan(this),
    93     supportedPlaymodes(Playable::Vertical) ,
    94     playmode(Playable::Vertical)
     92    : secWeaponMan(this) //,
     93    //supportedPlaymodes(Playable::Vertical) ,
     94    //playmode(Playable::Vertical)
    9595{
    9696  this->init();
     
    113113*/
    114114SpaceShip::SpaceShip(const TiXmlElement* root)
    115     : secWeaponMan(this),
    116     supportedPlaymodes(Playable::Vertical) ,
    117     playmode(Playable::Vertical)
     115    : secWeaponMan(this) //,
     116    //supportedPlaymodes(Playable::Vertical) ,
     117    //playmode(Playable::Vertical)
    118118{
    119119  this->init();
     
    129129void SpaceShip::init()
    130130{
     131
     132  this->setSupportedPlaymodes(Playable::Vertical);
    131133
    132134  //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
     
    231233  this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
    232234
    233   this->travelSpeed = 0.0;
    234   this->cameraLook = 0.0f;
    235   this->acceleration = 20.0f;
    236   //this->airFriction = 0.0f;
    237   this->cameraSpeed = 0.0;
    238235  /*
    239236  this->velocity = this->getAbsDirX()*travelSpeed;
     
    366363  registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) );
    367364
    368   this->enterPlaymode(Playable::Vertical);
    369365  //this->airFriction = 0.5f;
    370   this->travelDistance = Vector2D(50.0, 50.0);
    371   this->travelSpeed = 50;
     366  this->travelDistancePlus = Vector2D(38.0, 43.0);
     367  this->travelDistanceMinus = Vector2D(-38.0, -43.0);
     368  this->travelSpeed = 80;
    372369  this->cameraSpeed = 40;
     370  this->cameraLook = 0.0f;
     371  this->acceleration = 120.0f;
     372  //this->airFriction = 0.0f;
    373373
    374374  this->travelNode->debugDraw();
     
    404404*/
    405405
    406 
     406/*
    407407void SpaceShip::setTravelDistance(const Vector2D& distance)
    408408{
     
    414414  this->setTravelDistance(Vector2D(x, y));
    415415}
     416*/
    416417
    417418
     
    432433  this->secWeaponMan.showCrosshair();
    433434  //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( true);
    434   this->attachCamera();
     435  if (!this->setPlaymode(Playable::Vertical))
     436    std::cout << "playmode not supported";
     437  //this->attachCamera();
    435438}
    436439
     
    439442  this->secWeaponMan.hideCrosshair();
    440443  //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( false);
    441   this->detachCamera();
     444  //this->detachCamera();
    442445}
    443446
     
    786789
    787790        State::getCameraNode()->setParentSoft(this->travelNode);
    788         State::getCameraNode()->setRelCoorSoft(0, 40,0);
     791        State::getCameraNode()->setRelCoorSoft(-0.01, 40,0);
    789792        State::getCameraTargetNode()->setParentSoft(this->travelNode);
    790         State::getCameraTargetNode()->setRelCoorSoft(5,0,0);
     793        State::getCameraTargetNode()->setRelCoorSoft(0,0,0);
    791794
    792795        this->debugNode(1);
    793796        this->travelNode->debugNode(1);
    794         std::cout << "testprint";
    795797      }
    796798      break;
     
    799801      PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName());
    800802  }
     803  std::cout << Playable::playmodeToString(this->getPlaymode());
    801804}
    802805
     
    808811void SpaceShip::movement (float dt)
    809812{
    810     // these routines will change the travel movement into zero in a short amout of time, if the player
    811     // doesn't press any buttons.
    812     if (this->velocity.x >= 0)
    813     {
    814       if (this->velocity.x > 2*this->acceleration * dt)
    815         this->velocity.x -= 2* this->acceleration * dt;
    816       else
    817         this->velocity.x = 0;
    818     }
    819     else
    820     {
    821       if (this->velocity.x < -2*this->acceleration * dt)
    822         this->velocity.x += 2* this->acceleration * dt;
    823       else
    824         this->velocity.x = 0;
    825     }
     813  //by releasing the buttons, the velocity decreases with airCoeff*Acceleration. Should be strong enough so
     814  //the ship doesn't slide too much.
     815  float airCoeff = 2.5;
     816
     817  float pi = 3.14;
     818
     819  // these routines will change the travel movement into zero in a short amout of time, if the player
     820  // doesn't press any buttons.
     821  if (this->velocity.x >= 0)
     822  {
     823    if (this->velocity.x > airCoeff*this->acceleration * dt)
     824      this->velocity.x -= airCoeff* this->acceleration * dt;
     825    else
     826      this->velocity.x = 0;
     827  }
     828  else
     829  {
     830    if (this->velocity.x < -airCoeff*this->acceleration * dt)
     831      this->velocity.x += airCoeff* this->acceleration * dt;
     832    else
     833      this->velocity.x = 0;
     834  }
     835  if (this->velocity.z >= 0)
     836  {
     837    if (this->velocity.z > airCoeff*this->acceleration * dt)
     838      this->velocity.z -= airCoeff* this->acceleration * dt;
     839    else
     840      this->velocity.z = 0;
     841  }
     842  else
     843  {
     844    if (this->velocity.z < -airCoeff*this->acceleration * dt)
     845      this->velocity.z += airCoeff* this->acceleration * dt;
     846    else
     847      this->velocity.z = 0;
     848  }
     849
     850  // this will evite, that the ship moves outside the travelDistance- borders,when the player releases all buttons
     851  // and its continuing to slide a bit.
     852  Vector oldCoor = this->getRelCoor();
     853  if (this->getRelCoor().x > this->travelDistancePlus.x) this->setRelCoor(this->travelDistancePlus.x, oldCoor.y, oldCoor.z);
     854  if (this->getRelCoor().x < this->travelDistanceMinus.x) this->setRelCoor(this->travelDistanceMinus.x, oldCoor.y, oldCoor.z);
     855  if (this->getRelCoor().z > this->travelDistancePlus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistancePlus.y);
     856  if (this->getRelCoor().z < this->travelDistanceMinus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistanceMinus.y);
    826857
    827858  if( this->bForward )
    828859  {
    829     if(this->getRelCoor().x < this->travelDistance.x)
     860    if(this->getRelCoor().x < this->travelDistancePlus.x)
    830861    {
    831862      if (this->velocity.x < this->travelSpeed)
    832863      {
    833         this->velocity.x += 3*this->acceleration*dt;
     864        this->velocity.x += (airCoeff + 1.0)*this->acceleration*dt;
    834865      }
    835866      else
     
    846877  if( this->bBackward )
    847878  {
    848     if(this->getRelCoor().x > -this->travelDistance.x)
     879    if(this->getRelCoor().x > this->travelDistanceMinus.x)
    849880    {
    850881      if (this->velocity.x > -this->travelSpeed)
    851882      {
    852         this->velocity.x -= 3*this->acceleration*dt;
     883        this->velocity.x -= (airCoeff + 1.0)*this->acceleration*dt;
    853884      }
    854885      else
     
    862893    }
    863894  }
     895
    864896  if( this->bLeft)
    865897  {
     898    if(this->getRelCoor().z > this->travelDistanceMinus.y)
     899    {
     900      if (this->velocity.z > -this->travelSpeed)
     901      {
     902        this->velocity.z -= (airCoeff + 1.0)*this->acceleration*dt;
     903      }
     904      else
     905      {
     906        this->velocity.z = -this->travelSpeed;
     907      }
     908    }
     909    else
     910    {
     911      this->velocity.z = 0.0f;
     912    }
    866913  }
    867914
    868915  if( this->bRight)
    869916  {
    870   }
    871 
     917    if(this->getRelCoor().z < this->travelDistancePlus.y)
     918    {
     919      if (this->velocity.z < this->travelSpeed)
     920      {
     921        this->velocity.z += (airCoeff + 1.0)*this->acceleration*dt;
     922      }
     923      else
     924      {
     925        this->velocity.z = this->travelSpeed;
     926      }
     927    }
     928    else
     929    {
     930      this->velocity.z = 0.0f;
     931    }
     932  }
     933 
     934  this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0));
     935  this->shiftCoor (this->velocity * dt);
     936 
     937  float angle = this->velocity.z / travelSpeed * pi / 3;
     938  if (angle > pi/3) angle = pi/3;
     939  if (angle < -pi/3) angle = -pi/3;
     940  this->setRelDirSoft(Quaternion(angle, Vector(1,0,0)), 5.0f);
     941
     942  /*
    872943  switch(this->getPlaymode())
    873944  {
    874     case Playable::Full3D:
    875     /*
    876       {
    877         Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration);
    878 
    879         // this is the air friction (necessary for a smooth control)
    880         Vector damping = (this->velocity * this->airFriction);
    881 
    882 
    883         this->velocity += (accelerationDir - damping)* dt;
    884         this->shiftCoor (this->velocity * dt);
    885 
    886         // limit the maximum rotation speed.
    887         if (this->rotation != 0.0f)
    888         {
    889           float maxRot = 10.0 * dt;
    890           if (unlikely(this->rotation > maxRot)) this->rotation = maxRot;
    891           if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot;
    892           this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0));
    893 
    894           this->rotation = 0.0f;
    895         }
    896 
    897         this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5);
    898       }
     945    case Playable::Vertical:
    899946      break;
    900     */
    901     case Playable::Vertical:
    902       {
    903         /*
    904         if (this->toTravelHeight != NULL)
    905         {
    906           this->travelNode->shiftCoor(Vector(0, (*toTravelHeight - this->travelNode->getAbsCoor().y) * dt * 10.0, 0));
    907           if (fabsf(this->travelNode->getAbsCoor().y - *this->toTravelHeight) < .1)
    908           {
    909             delete this->toTravelHeight;
    910             this->toTravelHeight = NULL;
    911           }
    912         }
    913         */
    914         this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0));
    915 
    916         /*
    917         accel.y = 0.0;
    918 
    919         Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration);
    920         accelerationDir.y = 0.0;
    921 
    922         // this is the air friction (necessary for a smooth control)
    923         Vector damping = (this->velocity * this->airFriction);
    924 
    925 
    926         this->velocity += (accelerationDir - damping)* dt;
    927 
    928         if (this->getRelCoor().z > this->travelDistance.y && velocity.z > 0.0)
    929           this->velocity.z = 0.0f;
    930         if (this->getRelCoor().z < -this->travelDistance.y && velocity.z < 0.0)
    931           this->velocity.z = 0.0f;
    932 
    933         if (this->getRelCoor().x > this->travelDistance.x && velocity.x > 0.0)
    934           this->velocity.x = 0.0f;
    935         if (this->getRelCoor().x < -this->travelDistance.x && velocity.x < 0.0)
    936           this->velocity.x = 0.0f;
    937 
    938         */
    939         this->shiftCoor (this->velocity * dt);
    940    
    941 
    942         /*
    943         if (accel.z == 0)
    944           this->setRelDirSoft(Quaternion(0, Vector(0,0,0)), 5.0f);
    945         else
    946           this->setRelDirSoft(Quaternion(this->velocity.z * 5, Vector(1,0,0)), 4.5f);
    947         */
    948       }
    949       break;
    950 
    951947    default:
    952948      PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName());
    953949  }
    954 }
    955 
     950  */
     951}
     952
  • branches/playability/src/world_entities/space_ships/space_ship.h

    r10017 r10019  
    3131    virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f);
    3232    void setTravelSpeed(float travelSpeed);
     33    /*
    3334    void setTravelHeight(float travelHeight);
    3435    void setTravelDistance(const Vector2D& distance);
    3536    void setTravelDistance(float x, float y);
     37    */
    3638
    3739    //void setAirFriction(float friction) { this->airFriction = friction; };
     
    150152    PNode*                travelNode;
    151153    float                 travelSpeed;        //!< the current speed of the Ship (to make soft movement)
    152     Vector2D              travelDistance;     //!< Travel-Distance away from the TravelNode
     154    Vector2D              travelDistancePlus;     //!< Travel-Distance away from the TravelNode
     155    Vector2D              travelDistanceMinus;
    153156
    154157// Camera
Note: See TracChangeset for help on using the changeset viewer.