void Pellet::Update()
{
  if (!HasImpacted())
  {
     //calculate the steering force
    Vector2D DesiredVelocity = Vec2DNormalize(m_vTarget - Pos()) * MaxSpeed();

    Vector2D sf = DesiredVelocity - Velocity();

    //update the position
    Vector2D accel = sf / m_dMass;

    m_vVelocity += accel;

    //make sure vehicle does not exceed maximum velocity
    m_vVelocity.Truncate(m_dMaxSpeed);

    //update the position
    m_vPosition += m_vVelocity; 

    TestForImpact();
  }
  else if (!isVisibleToPlayer())
  {
    m_bDead = true;
  }
}
//------------------------------ Update ---------------------------------------
//-----------------------------------------------------------------------------
void Rocket::Update()
{
  if (!m_bImpacted)
  {
    m_vVelocity = MaxSpeed() * Heading();

    //make sure vehicle does not exceed maximum velocity
    m_vVelocity.Truncate(m_dMaxSpeed);

    //update the position
    m_vPosition += m_vVelocity;

    TestForImpact();  
  }

  else
  {
    m_dCurrentBlastRadius += script->GetDouble("Rocket_ExplosionDecayRate");

    //when the rendered blast circle becomes equal in size to the blast radius
    //the rocket can be removed from the game
    if (m_dCurrentBlastRadius > m_dBlastRadius)
    {
      m_bDead = true;
    }
  }
}
예제 #3
0
파일: CLander.cpp 프로젝트: pxli168/source
//----------------------UpdateShipFromAction---------------------------
//
//  this is the main workhorse. It reads the ships decoded string of
//  actions and performs them, updating the lander accordingly. It also 
//  checks for impact and updates the fitness score.
//
//----------------------------------------------------------------------
bool CLander::UpdateShip()
{
   //just return if ship has crashed or landed
  if (m_bCheckedIfLanded)
  {
    return false;
  }
 
  //this will be the current action
  action_type action;

  //check that we still have an action to perform. If not then
  //just let the lander drift til it hits the ground
  if (m_cTick >= m_vecActions.size())
  {
    action = non;
  }

  else
  {
    action = m_vecActions[m_cTick++];
  }
  	

	//switch the jet graphic off
  m_bJetOn = false;
  
	switch (action)
	{
	case rotate_left:

		m_dRotation -= ROTATION_PER_TICK;

		if (m_dRotation < -PI)
		{
			m_dRotation += TWO_PI;
		}
		break;

	case rotate_right:

		m_dRotation += ROTATION_PER_TICK;

		if (m_dRotation > TWO_PI)
		{
			m_dRotation -= TWO_PI;
		}
		break;

	case thrust:
    {
      //the lander's acceleration per tick calculated from
      //the force the thruster exerts and the lander's mass
      double ShipAcceleration = THRUST_PER_TICK/m_dMass;

	    //resolve the acceleration vector into its x, y components
      //and add to the lander's velocity vector
      m_vVelocity.x += ShipAcceleration * sin(m_dRotation);
		  m_vVelocity.y += ShipAcceleration * cos(m_dRotation);
		  
      //switch the jet graphic on
      m_bJetOn = true;
    }

		break;

	case non:

		break;

	}//end switch


  //now add in the gravity vector
	m_vVelocity.y += GRAVITY_PER_TICK;

  //update the lander's position	
  m_vPos += m_vVelocity;

	
	//bounds checking
	if (m_vPos.x > WINDOW_WIDTH)
	{
		m_vPos.x = 0;
	}
	
	if (m_vPos.x < 0)
	{
		m_vPos.x = WINDOW_WIDTH;
	}

  //now we check to see if the lander has crashed or landed

  //create a copy of the landers verts before we transform them
	m_vecShipVBTrans = m_vecShipVB;

	//transform the vertices
  WorldTransform(m_vecShipVBTrans);

	//if we are lower than the ground then we have finished this run
	if (TestForImpact(m_vecShipVBTrans))
  {
    //check if user has landed ship
    if (!m_bCheckedIfLanded)
    {
       //calculate fitness if we haven't already
      if (!m_dFitness)
      {
        CalculateFitness();
    
        m_bCheckedIfLanded = true;
      }
    
      return false;
    }
  }
    
  return true;
}