/// <summary>
        /// Draws the monster phases.
        /// </summary>
        /// <param name="direction">The direction.</param>
        private void DrawMonsterPhases(MonsterDirection direction)
        {
            MonsterParam tmp = _levelsConfig[_currentLevel - 1];

            try
            {
                if (tmp[MonsterDirection.Left, 0] == null)
                {
                    return;
                }
                Bitmap tmpForDrawing = new Bitmap(PBMosterPict.Width, (tmp[direction, 0].Height * tmp.NumberOfPhases) + ((20 * tmp.NumberOfPhases) - 1));
                PBMosterPict.Height = tmpForDrawing.Height;
                Graphics canva = Graphics.FromImage(tmpForDrawing);
                canva.FillRectangle(new SolidBrush(Color.Blue), new Rectangle(0, 0, PBMosterPict.Width, PBMosterPict.Height));
                for (int phaseNum = 0; phaseNum < tmp.NumberOfPhases; phaseNum++)
                {
                    canva.DrawImage(tmp[direction, phaseNum], (PBMosterPict.Width / 2) - (tmp[direction, phaseNum].Width / 2), (phaseNum * tmp[direction, phaseNum].Height + 20 * phaseNum),
                                    tmp[direction, phaseNum].Width, tmp[direction, phaseNum].Height);
                }
                PBMosterPict.Image = tmpForDrawing;
                PMonsterPict.Refresh();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return;
            }
        }
示例#2
0
    public void GenerateDirectionPossibilities(PossibleDirections possibleDirections)
    {
        ClearState();

        var directionsCount = MonsterDirection.CountPossibleDirections(possibleDirections);
        var equalPosibility = 1f / directionsCount;

        if ((possibleDirections & PossibleDirections.Up) == PossibleDirections.Up)
        {
            _possibilities.Add(PossibleDirections.Up, equalPosibility);
        }

        if ((possibleDirections & PossibleDirections.Down) == PossibleDirections.Down)
        {
            _possibilities.Add(PossibleDirections.Down, equalPosibility);
        }

        if ((possibleDirections & PossibleDirections.Left) == PossibleDirections.Left)
        {
            _possibilities.Add(PossibleDirections.Left, equalPosibility);
        }

        if ((possibleDirections & PossibleDirections.Right) == PossibleDirections.Right)
        {
            _possibilities.Add(PossibleDirections.Right, equalPosibility);
        }
    }
 public void Start()
 {
     _player           = FindObjectOfType <PlayerInMaze>();
     _monsterDirection = GetComponent <MonsterDirection>();
 }
 /// <summary>
 /// Gets the <see cref="System.Drawing.Bitmap"/> with the specified direction and phase.
 /// </summary>
 public Bitmap this[MonsterDirection direction, int phase]
 {
   get
   {
     if (MonsterPict == null)
       return null;
     if (_cache == null)
       _cache = new Dictionary<MonsterDirection, List<CacheElem>>();
     if (!_cache.ContainsKey(direction))
     {
       _cache.Add(direction, new List<CacheElem>());
     }
     if (_cache[direction].Find(x => x.ID == phase).CachedBitmap != null)
     {
       return _cache[direction].Find(x => x.ID == phase).CachedBitmap;
     }
     int phaseLength = MonsterPict.Size.Width / NumberOfPhases;
     Bitmap tmp = MonsterPict.Clone(new Rectangle(phaseLength * phase, 0, phaseLength, MonsterPict.Size.Height), System.Drawing.Imaging.PixelFormat.Undefined);
     if ((NumberOfDirectionsInFile == 2) && (tmp.Size.Width > tmp.Size.Height))
     {
       throw new Exception("Incorrect phases number");
     }
     if ((NumberOfDirectionsInFile == 4) && ((tmp.Size.Width * 2) > tmp.Size.Height))//Длина одной фазы*2 будет меньше высоты, если число фаз указано верно
     //в противном случае будет превышать высоту
     {
       throw new Exception("Incorrect phases number");
     }
     switch (direction)
     {
       case MonsterDirection.Right:
         #region Обработка в зависимости от числа направлений в файле
         switch (NumberOfDirectionsInFile)
         {
           case 1:
             tmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
             break;
           case 2:
             tmp = tmp.Clone(new Rectangle(0, 0, tmp.Size.Width, tmp.Size.Height - tmp.Size.Width), System.Drawing.Imaging.PixelFormat.Undefined);
             tmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
             break;
           case 4:
             tmp = tmp.Clone(new Rectangle(0, (tmp.Size.Height / 2) - tmp.Size.Width, tmp.Size.Width, (tmp.Size.Height / 2) - tmp.Size.Width),
               System.Drawing.Imaging.PixelFormat.Undefined);
             break;
         }
         #endregion
         break;
       case MonsterDirection.Left:
         #region Обработка в зависимости от числа направлений в файле
         switch (NumberOfDirectionsInFile)
         {
           //case 1:В файле и так одно направление, влево
           //break;
           case 2:
             tmp = tmp.Clone(new Rectangle(0, 0, tmp.Size.Width, tmp.Size.Height - tmp.Size.Width), System.Drawing.Imaging.PixelFormat.Undefined);
             break;
           case 4:
             tmp = tmp.Clone(new Rectangle(0, 0, tmp.Size.Width, (tmp.Size.Height / 2) - tmp.Size.Width), System.Drawing.Imaging.PixelFormat.Undefined);
             break;
         }
         #endregion
         break;
       case MonsterDirection.Up:
         #region Обработка в зависимости от числа направлений в файле
         switch (NumberOfDirectionsInFile)
         {
           case 1:
             tmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
             break;
           case 2:
             tmp = tmp.Clone(new Rectangle(0, tmp.Size.Height - tmp.Size.Width, tmp.Size.Width, tmp.Size.Width),
               System.Drawing.Imaging.PixelFormat.Undefined);
             break;
           case 4:
             tmp = tmp.Clone(new Rectangle(0, tmp.Size.Height - (tmp.Size.Width * 2), tmp.Size.Width, tmp.Size.Width),
               System.Drawing.Imaging.PixelFormat.Undefined);
             break;
         }
         #endregion
         break;
       case MonsterDirection.Down:
         #region Обработка в зависимости от числа направлений в файле
         switch (NumberOfDirectionsInFile)
         {
           case 1:
             tmp.RotateFlip(RotateFlipType.Rotate270FlipNone);
             break;
           case 2:
             tmp = tmp.Clone(new Rectangle(0, tmp.Size.Height - tmp.Size.Width, tmp.Size.Width, tmp.Size.Width),
               System.Drawing.Imaging.PixelFormat.Undefined);
             tmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
             break;
           case 4:
             tmp = tmp.Clone(new Rectangle(0, tmp.Size.Height - tmp.Size.Width, tmp.Size.Width, tmp.Size.Width),
               System.Drawing.Imaging.PixelFormat.Undefined);
             break;
         }
         #endregion
         break;
     }
     CacheElem tmpCache = new CacheElem {ID = phase};
     tmp.MakeTransparent(Color.FromArgb(255, 0, 255));
     tmpCache.CachedBitmap = new Bitmap(tmp);
     _cache[direction].Add(tmpCache);
     return tmp;
   }
 }
 /// <summary>
 /// Draws the monster phases.
 /// </summary>
 /// <param name="direction">The direction.</param>
 private void DrawMonsterPhases(MonsterDirection direction)
 {
   MonsterParam tmp = _levelsConfig[_currentLevel - 1];
   try
   {
     if (tmp[MonsterDirection.Left, 0] == null)
       return;
     Bitmap tmpForDrawing = new Bitmap(PBMosterPict.Width, (tmp[direction, 0].Height * tmp.NumberOfPhases) + ((20 * tmp.NumberOfPhases) - 1));
     PBMosterPict.Height = tmpForDrawing.Height;
     Graphics canva = Graphics.FromImage(tmpForDrawing);
     canva.FillRectangle(new SolidBrush(Color.Blue), new Rectangle(0, 0, PBMosterPict.Width, PBMosterPict.Height));
     for (int phaseNum = 0; phaseNum < tmp.NumberOfPhases; phaseNum++)
     {
       canva.DrawImage(tmp[direction, phaseNum], (PBMosterPict.Width / 2) - (tmp[direction, phaseNum].Width / 2), (phaseNum * tmp[direction, phaseNum].Height + 20 * phaseNum),
         tmp[direction, phaseNum].Width, tmp[direction, phaseNum].Height);
     }
     PBMosterPict.Image = tmpForDrawing;
     PMonsterPict.Refresh();
   }
   catch (Exception e)
   {
     MessageBox.Show(e.Message);
     return;
   }
 }