コード例 #1
0
 public override void Run(LinkedList<Monster>[] Monsters)
 {
     /*正在升级*/
     if (FUpdating)
     {
         if (FProgress.Finished)
         {
             FUpdating = false;
             FProgress = null;
         }
     }
     /*处理炮弹*/
     for (int i = 0; i < GetMaxShot(FLevel); i++)
     {
         Shot s = FShots[i];
         /*如果炮弹有效*/
         if (s.Enabled)
         {
             /*处理跟踪*/
             if (s.Tracking)
             {
                 if (s.Destination.Life != 0)
                 {
                     s.Velocity = new PointF(s.Destination.Position.X - s.Position.X, s.Destination.Position.Y - s.Position.Y);
                     float Length = (float)Math.Sqrt(Math.Pow(s.Velocity.X, 2) + Math.Pow(s.Velocity.Y, 2));
                     s.Velocity.X /= Length / GetVelocity(FLevel);
                     s.Velocity.Y /= Length / GetVelocity(FLevel);
                 }
                 else
                 {
                     s.Tracking = false;
                 }
             }
             /*炮弹行走*/
             s.Position.X += s.Velocity.X*2;
             s.Position.Y += s.Velocity.Y*2;
             /*如果炮弹超出射程则禁用*/
             if (Math.Pow(s.Position.X - Position.X, 2) + Math.Pow(s.Position.Y - Position.Y, 2) <= Math.Pow(GetRange(FLevel), 2))
             {
                 foreach (LinkedList<Monster> List in Monsters)
                 {
                     foreach (Monster m in List)
                     {
                         /*如果炮弹击中则调用回调函数并禁用*/
                         if (Math.Pow(m.Position.X - s.Position.X, 2) + Math.Pow(m.Position.Y - s.Position.Y, 2) <= m.Radius * m.Radius)
                         {
                             Hit(FLevel, s.Position, m, Monsters);
                             s.Enabled = false;
                         }
                     }
                 }
             }
             else
             {
                 s.Enabled = false;
             }
         }
         /*如果炮弹禁用并且没有正在升级*/
         if (!s.Enabled && !FUpdating)
         {
             Monster mDest = null;
             float mDist = float.MaxValue;
             /*寻找距离最接近的怪物*/
             foreach (LinkedList<Monster> List in Monsters)
             {
                 foreach (Monster m in List)
                 {
                     float Distance=(float)(Math.Pow(m.Position.X - Position.X, 2) + Math.Pow(m.Position.Y - Position.Y, 2));
                     if (Distance <= Math.Pow(GetRange(FLevel), 2))
                     {
                         if (Distance < mDist)
                         {
                             mDist = Distance;
                             mDest = m;
                         }
                     }
                 }
             }
             /*如果找到则发射炮弹*/
             if (mDest != null)
             {
                 s.Velocity = new PointF(mDest.Position.X - Position.X, mDest.Position.Y - Position.Y);
                 float Length = (float)Math.Sqrt(Math.Pow(s.Velocity.X, 2) + Math.Pow(s.Velocity.Y, 2));
                 s.Velocity.X /= Length / GetVelocity(FLevel);
                 s.Velocity.Y /= Length / GetVelocity(FLevel);
                 s.Position = Position;
                 s.Enabled = true;
                 s.Tracking = GetTracking(FLevel);
                 s.Destination = mDest;
                 return;
             }
         }
     }
 }
コード例 #2
0
 public override bool LevelUp(ref int Money)
 {
     if (Money >= LevelUpMoney())
     {
         Money -= LevelUpMoney();
         FUpdating = true;
         /****绘制升级进度条****/
         FProgress = new ProgressClip(FLevelUpTime[FLevel], Position);
         FGame.AddClip(FProgress);
         /**********************/
         FLevel++;
         return true;
     }
     else
     {
         return false;
     }
 }