Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2007, 12:01:20 PM (17 years ago)
Author:
rennerc
Message:

ActionboxEnemy

Location:
branches/vs-enhencements/src/world_entities/npcs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/vs-enhencements/src/world_entities/npcs/actionbox_enemy.cc

    r10662 r10667  
    4141  this->dPitch = 0.0;
    4242 
    43   this->maxSpeed = 10;
     43  this->maxSpeed = 30;
    4444  this->acceleration = 3;
    4545  this->speed = 0;
    4646 
     47  this->onEscape = false;
     48 
    4749  if ( root )
    4850    this->loadParams( root );
     
    6062void ActionboxEnemy::tick( float dt )
    6163{
     64  this->bFire = false;
     65 
     66  if ( !State::getPlayer() || !State::getPlayer()->getPlayable() )
     67    return;
     68 
     69  Vector playerDir = State::getPlayer()->getPlayable()->getAbsDir().apply( Vector(1, 0, 0) );
     70  Vector dist = this->getAbsCoor() - State::getPlayer()->getPlayable()->getAbsCoor();
     71 
     72  bool behindPlayer = playerDir.dot( dist ) < 0;
     73 
     74  if ( behindPlayer )
     75    return;
     76 
    6277  myDir = this->getAbsDir();
    6378  myCoor = this->getAbsCoor();
     
    7388  qPitch = Quaternion( pitch, Vector( 1, 0, 0 ) );
    7489 
    75   moveTowardsBox( NULL, dt );
    76    
    7790  if ( isActive && State::getActionBox() )
    7891  {
     
    8598    {
    8699      moveTowardsBox( box, dt );
     100      onEscape = false;
    87101    }
    88102  }
     
    96110void ActionboxEnemy::attackPlayer( ActionBox * box, float dt )
    97111{
    98 }
    99 
    100 void ActionboxEnemy::moveTowardsBox( ActionBox * box, float dt )
    101 {
    102   //Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor();
    103   static float time = 0;
    104   time += dt;
    105   Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor() + State::getPlayer()->getPlayable()->getAbsDir().apply(Vector(1, 0, 0))*50*(1.5 + sin(time/5));
    106   Vector targetDir = targetPos - myCoor;
    107  
     112  if ( !State::getPlayer() || !State::getPlayer()->getPlayable() || !box )
     113    return;
     114 
     115  float distance = (State::getPlayer()->getPlayable()->getAbsCoor() - getAbsCoor() ).len();
     116 
     117  if ( distance > box->getDepth()/4.0 && !onEscape )
     118  {
     119    Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor();
     120    Vector targetDir = State::getPlayer()->getPlayable()->getAbsCoor()-this->getAbsCoor();
     121    moveTowards( targetPos, targetDir, dt );
     122    if ( this->getAbsDir().apply( Vector(1, 0, 0) ).dot(targetDir) > 0.9 )
     123    {
     124      this->bFire = true;
     125      PRINTF(0)("FIRE\n");
     126    }
     127  }
     128  else
     129  {
     130    if ( !onEscape )
     131    {
     132      Vector ds = this->getAbsCoor() - State::getPlayer()->getPlayable()->getAbsCoor();
     133      float projy = box->getAbsDir().apply( Vector(0, 1, 0) ).dot( ds );
     134      float projz = box->getAbsDir().apply( Vector(0, 0, 1) ).dot( ds );
     135      this->escapePoint = Vector( 0, projy, projz );
     136      this->escapePoint.normalize();
     137      this->escapePoint*= 2*box->getWidth_2();
     138      PRINTF(0)("ESCAPE\n");
     139    }
     140    onEscape = true;
     141   
     142    Vector rEscapePoint = box->getAbsDir().apply(escapePoint);
     143    Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor() + rEscapePoint;
     144    Vector targetDir = State::getPlayer()->getPlayable()->getAbsCoor() + rEscapePoint - this->getAbsCoor();
     145    moveTowards( targetPos, targetDir, dt );   
     146  }
     147}
     148
     149void ActionboxEnemy::moveTowards( Vector targetPos, Vector targetDir, float dt )
     150{
    108151  Quaternion cur = myDir;
    109152  Quaternion rx( dt, Vector( 0, 0, 1 ) );
     
    144187}
    145188
     189void ActionboxEnemy::moveTowardsBox( ActionBox * box, float dt )
     190{
     191   
     192  Vector targetPos = box->getAbsCoor() + box->getAbsDir().apply( Vector( 1, 0, 0 ) )*box->getDepth()*0.66f;
     193  Vector targetDir = targetPos - myCoor;
     194 
     195  moveTowards(targetPos, targetDir, dt);
     196}
     197
    146198void ActionboxEnemy::draw( ) const
    147199{
  • branches/vs-enhencements/src/world_entities/npcs/actionbox_enemy.h

    r10662 r10667  
    3333    Vector     myCoor;
    3434   
     35    bool       bFire;
     36   
     37    Vector     escapePoint;
     38    bool       onEscape;
     39   
    3540    void attackPlayer( ActionBox* box, float dt );
    3641    void moveTowardsBox( ActionBox* box, float dt );
     42    void moveTowards( Vector targetPos, Vector targetDir, float dt );
    3743};
    3844
Note: See TracChangeset for help on using the changeset viewer.