예제 #1
0
    /// <summary>
    /// Called in response to the BaseModel.Update signal. This method is responsible for rotating
    /// the turret to face the nearest enemy.
    /// </summary>
    /// <param name="sender">The BaseModel object which sent the Update signal.</param>
    /// <param name="e">The UpdateArgs containing the current TimeSpan.</param>
    void OnUpdate(object sender, UpdateArgs e)
    {
      // Find the nearest enemy.
      Enemy focus = Enemy.FindNearestLiving(this, playerId);

      if (focus != null)
      {
        // Get the difference between the bullet's location and that of the target.
        Vector2 target = focus.Location - Location;

        // Figure out the relative orientation and cap the rate of rotation.
        float orientMod = (float) Math.Atan2(target.Y, target.X) - Orientation;
        float turnSpeed = Constants.TURRET_TURNSPEED / Constants.UPDATES_PER_SECOND;
        while (orientMod < -Math.PI) orientMod += (float) Math.PI * 2;
        if (Math.Abs(orientMod) > turnSpeed)
        {
          orientMod = orientMod > 0 ? turnSpeed : -turnSpeed;
        }
        Orientation += orientMod;
      }
    }
예제 #2
0
 /// <summary>
 /// Called in response to BaseModel.Update when the turret doesn't exist yet. Float around and
 /// rotate idly.
 /// </summary>
 /// <param name="sender">The BaseModel object which sent the Update signal.</param>
 /// <param name="e">The UpdateArgs containing the current TimeSpan.</param>
 void GhostUpdate(object sender, UpdateArgs e)
 {
   BaseModel model = (BaseModel) sender;
   Vector2 originPoint = model.Tower.Location;
   switch (PlayerId)
   {
     case 0:
       originPoint -= new Vector2(0, originPoint.Y / 2);
       break;
     case 1:
       originPoint += new Vector2(originPoint.X / 2, 0);
       break;
     case 2:
       originPoint += new Vector2(0, originPoint.Y / 2);
       break;
     case 3:
       originPoint -= new Vector2(originPoint.X / 2, 0);
       break;
   }
   Vector2 acc = originPoint - Location;
   //acc.Normalize();
   Vector2 vel = Vector2.Transform(acc, Matrix.CreateRotationZ((float) Math.PI / 2)) + (acc / Constants.UPDATES_PER_SECOND);
   Location += vel / Constants.UPDATES_PER_SECOND;
   Orientation += Constants.TURRET_TURNSPEED / Constants.UPDATES_PER_SECOND;
 }
예제 #3
0
 /// <summary>
 /// Called whenever the game sends an update event. This method is responsible for determining whether or not a
 /// Click, Beat or Bar event should occur.
 /// </summary>
 /// <param name="sender">The BaseModel object which sent the Update signal.</param>
 /// <param name="args">UpdateArgs object containing the current TimeSpan snapshot.</param>
 public void OnUpdate(object sender, UpdateArgs args)
 {
     TimeSpan time = args.Time;
     if ((time - lastClick).TotalMilliseconds > ClickDuration())
     {
         if (Click != null) Click(this, null);
         lastClick = time;
         clickCount++;
         if (clickCount % clicksPerBeat == 0)
         {
             if (Beat != null) Beat(this, null);
             lastBeat = time;
             beatCount++;
             if (clickCount % (timeSignature.number * clicksPerBeat) == 0)
             {
                 if (Bar != null) Bar(this, null);
                 lastBar = time;
                 barCount++;
                 clickCount = 0;
                 beatCount = 0;
             }
         }
     }
 }