当前位置: 首页>>代码示例>>C#>>正文


C# IGraphic.DrawLine方法代码示例

本文整理汇总了C#中IGraphic.DrawLine方法的典型用法代码示例。如果您正苦于以下问题:C# IGraphic.DrawLine方法的具体用法?C# IGraphic.DrawLine怎么用?C# IGraphic.DrawLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IGraphic的用法示例。


在下文中一共展示了IGraphic.DrawLine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Show

 /// <summary>
 /// Shows the missle on canva
 /// </summary>
 /// <param name="canva">The canva.</param>
 /// <param name="visibleStart">The visible map area start.</param>
 /// <param name="visibleFinish">The visible map area finish.</param>
 /// <param name="monsters">The monsters.</param>
 internal void Show(IGraphic canva, Point visibleStart, Point visibleFinish, IEnumerable<Monster> monsters)
 {
   if ((DestroyMe) || ((_position.X - visibleStart.X * Settings.ElemSize < 5)
     || (_position.Y - visibleStart.Y * Settings.ElemSize < 5) || (-_position.X + visibleFinish.X * Settings.ElemSize < 5)
     || (-_position.Y + visibleFinish.Y * Settings.ElemSize < 5)) || (monsters == null))
     return;
   //Getting Monster
   var monster = monsters.FirstOrDefault(elem => elem.ID == _aimID);
   if (monster == null)
   {
     DestroyMe = true;
     return;
   }
   Point aimPos = new Point((int)monster.GetCanvaPos.X, (int)monster.GetCanvaPos.Y);
   switch (_missleType)
   {
     case eTowerType.Simple:
       float tang;
       if ((Math.Abs((_position.X - aimPos.X) - 0) > 0.01) && (Math.Abs((_position.Y - aimPos.Y) - 0) > 0.01))
         tang = Math.Abs((_position.Y - aimPos.Y) / (_position.X - aimPos.X));
       else
         tang = 1;
       Point secondPosition;//Position of second missle point
       #region Second point calculation
       if (_position.X > aimPos.X)
       {
         if (_position.Y > aimPos.Y)
           secondPosition = new Point(
             Convert.ToInt32(_position.X + 10 * Math.Sqrt(1 / (1 + Math.Pow(tang, 2)))),
             Convert.ToInt32(_position.Y + 10 * Math.Sqrt(1 / (1 + Math.Pow(1 / tang, 2)))));
         else
           secondPosition = new Point(
             Convert.ToInt32(_position.X + 10 * Math.Sqrt(1 / (1 + Math.Pow(tang, 2)))),
             Convert.ToInt32(_position.Y - 10 * Math.Sqrt(1 / (1 + Math.Pow(1 / tang, 2)))));
       }
       else
       {
         if (_position.Y > aimPos.Y)
           secondPosition = new Point(
             Convert.ToInt32(_position.X - 10 * Math.Sqrt(1 / (1 + Math.Pow(tang, 2)))),
             Convert.ToInt32((_position.Y + 10 * Math.Sqrt(1 / (1 + Math.Pow(1 / tang, 2))))));
         else
           secondPosition = new Point(
             Convert.ToInt32(_position.X - 10 * Math.Sqrt(1 / (1 + Math.Pow(tang, 2)))),
             Convert.ToInt32(_position.Y - 10 * Math.Sqrt(1 / (1 + Math.Pow(1 / tang, 2)))));
       }
       #endregion
       canva.DrawLine(new Pen(_misslePenColor, 2),
                      new Point((int)((_position.X - visibleStart.X * Settings.ElemSize) * Scaling) + Settings.DeltaX,
                                (int)((_position.Y - visibleStart.Y * Settings.ElemSize) * Scaling) + Settings.DeltaY),
                      new Point((int)((secondPosition.X - visibleStart.X * Settings.ElemSize) * Scaling) + Settings.DeltaX,
                                (int)((secondPosition.Y - visibleStart.Y * Settings.ElemSize) * Scaling) + Settings.DeltaY));
       break;
     case eTowerType.Splash:
       canva.FillEllipse(new SolidBrush(_missleBrushColor),
                         (int)(_position.X - 5 - visibleStart.X * Settings.ElemSize) * Scaling + Settings.DeltaX,
                         (int)(_position.Y - 5 - visibleStart.Y * Settings.ElemSize) * Scaling + Settings.DeltaY,
                         10 * Scaling, 10 * Scaling);
       canva.DrawEllipse(new Pen(_misslePenColor),
                         (int)(_position.X - 5 - visibleStart.X * Settings.ElemSize) * Scaling + Settings.DeltaX,
                         (int)(_position.Y - 5 - visibleStart.Y * Settings.ElemSize) * Scaling + Settings.DeltaY,
                         10 * Scaling, 10 * Scaling);
       break;
   }
 }
开发者ID:tupieurods,项目名称:tower-defense-csharp-opengl.gamelogic,代码行数:72,代码来源:Missle.cs

示例2: ShowMonster

    /// <summary>
    /// Shows the monster.
    /// </summary>
    /// <param name="canva">The canva.</param>
    /// <param name="visibleStart">The visible map area start.</param>
    /// <param name="visibleFinish">The visible map area finish.</param>
    internal void ShowMonster(IGraphic canva, Point visibleStart, Point visibleFinish)
    {
      if (_currentBaseParams.Invisible)
        return;
      if (!InVisibleMapArea(visibleStart, visibleFinish))
        return;
      //Unit picture
      Bitmap tmp = _params[GetDirection, _movingPhase];
      //Real coords calculating
      int realX = Settings.DeltaX + (int)((_canvaPos.X - visibleStart.X * Settings.ElemSize) * Scaling);
      int realY = Settings.DeltaY + (int)((_canvaPos.Y - visibleStart.Y * Settings.ElemSize) * Scaling);
      canva.DrawImage(tmp, (int)(realX - (tmp.Width / 2.0) * Scaling), (int)(realY - (tmp.Height / 2.0) * Scaling), (int)(tmp.Width * Scaling), (int)(tmp.Height * Scaling));
      #region Effect Colors
      int r = 0;
      int g = 0;
      int b = 0;
      foreach (var effect in _effects)//Effects visualization
      {
        r += effect.EffectColor.R;
        g += effect.EffectColor.G;
        b += effect.EffectColor.B;
      }
      if (r != 0 || g != 0 || b != 0)
        canva.FillEllipse(new SolidBrush(Color.FromArgb((byte)r, (byte)g, (byte)b)), realX - 5 * Scaling, realY - 5 * Scaling, 10 * Scaling, 10 * Scaling);
      #endregion Effect Colors

      //HP bar showing

      int hpLineLength = (int)(Math.Round(_currentBaseParams.HealthPoints * 100.0 / _params.Base.HealthPoints) / 10.0);

      if (hpLineLength < 0)
        hpLineLength = 0;
      switch (GetDirection)
      {
        case MonsterDirection.Left:
        case MonsterDirection.Right:
          canva.DrawLine(Helpers.BlackPen, realX - 5 * Scaling, realY, realX + 5 * Scaling, realY);
          if (hpLineLength == 0)
            break;
          canva.DrawLine(Helpers.GreenPen, realX - 5 * Scaling, realY, realX + (-5 + hpLineLength) * Scaling, realY);
          break;
        case MonsterDirection.Up:
        case MonsterDirection.Down:
          canva.DrawLine(Helpers.BlackPen, realX, realY + 5 * Scaling, realX, realY - 5 * Scaling);
          if (hpLineLength == 0)
            break;
          canva.DrawLine(Helpers.GreenPen, realX, realY - 5 * Scaling, realX, realY + (-5 + hpLineLength) * Scaling);
          break;
      }
    }
开发者ID:tupieurods,项目名称:tower-defense-csharp-opengl.gamelogic,代码行数:56,代码来源:Monster.cs


注:本文中的IGraphic.DrawLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。