Пример #1
0
 public async Task GetDamage(Mobs mob, int type)
 {
     if (type == 0)
     {
         WarMan.Hp -= mob.Damage;
         DeleteCanvasItem(null, ObjList[WarMan.Hp]);
         if (WarMan.Hp <= 0)
         {
             Die();
         }
     }
     else
     {
         mob.Hp -= WarMan.Damage;
         if (mob.Hp <= 0)
         {
             if (mob.Type == "Monster")
             {
                 glory += 1;
                 UpdateStats();
                 InitCanvas(mob, null, mob.corpse);
                 DeleteCanvasItem(mob);
                 WarMan.targetList.Remove(mob);
             }
             else if (mob.Type == "Boss")
             {
                 Win();
             }
         }
     }
 }
Пример #2
0
 public void DeleteCanvasItem(Mobs mob = null, StaticObject obj = null, Image img = null)
 {
     if (mob != null)
     {
         if (mob.Type == "Monster" && glory <= 2)
         {
             SpawnEnemies(0);
         }
         if (glory >= 3)
         {
             SpawnEnemies(1);
         }
         MyCanvas.Children.Remove(mob.image);
         Moblist.Remove(mob);
         mob = null;
     }
     if (obj != null)
     {
         MyCanvas.Children.Remove(obj.image);
         ObjList.Remove(obj);
         obj = null;
     }
     if (img != null)
     {
         MyCanvas.Children.Remove(img);
     }
 }
Пример #3
0
 public void InitCanvas(Mobs mob = null, StaticObject obj = null, Image img = null)
 {
     if (mob != null && img == null)
     {
         MyCanvas.Children.Add(mob.image);
         mob.image.Stretch = Stretch.None;
         if (mob.dir == 0)
         {
             mob.image.FlowDirection = System.Windows.FlowDirection.LeftToRight;
         }
         else
         {
             mob.image.FlowDirection = System.Windows.FlowDirection.RightToLeft;
         }
         Canvas.SetLeft(mob.image, mob.position.x);
         Canvas.SetTop(mob.image, mob.position.y);
     }
     else if (obj != null)
     {
         MyCanvas.Children.Add(obj.image);
         obj.image.Stretch = Stretch.None;
         Canvas.SetLeft(obj.image, obj.position.x);
         Canvas.SetTop(obj.image, obj.position.y);
     }
     else if (img != null && mob == null)
     {
         MyCanvas.Children.Add(img);
         img.Stretch = Stretch.None;
         if (WarMan.dir == 0)
         {
             img.FlowDirection = System.Windows.FlowDirection.LeftToRight;
         }
         else
         {
             img.FlowDirection = System.Windows.FlowDirection.RightToLeft;
         }
         Canvas.SetLeft(img, WarMan.position.x);
         Canvas.SetTop(img, WarMan.position.y);
     }
     else if (img != null && mob != null)
     {
         MyCanvas.Children.Add(img);
         img.Stretch = Stretch.None;
         if (mob.dir == 0)
         {
             img.FlowDirection = System.Windows.FlowDirection.LeftToRight;
         }
         else
         {
             img.FlowDirection = System.Windows.FlowDirection.RightToLeft;
         }
         Canvas.SetLeft(img, mob.position.x);
         Canvas.SetTop(img, mob.position.y);
     }
 }
Пример #4
0
 public void SpawnEnemies(int type)
 {
     if (type == 0)
     {
         Mobs enemie1 = new Mobs("Monster", 300, 240);
         Moblist.Add(enemie1);
         InitCanvas(enemie1);
     }
     else
     {
         Mobs enemie1 = new Mobs("Boss", 350, 208);
         Moblist.Add(enemie1);
         InitCanvas(enemie1);
     }
 }
Пример #5
0
        public async Task AttackAnim(Mobs mob = null, Image img = null, int?time = null)
        {
            if (mob != null && img == null)
            {
                MyCanvas.Children.Add(mob.attackImage);
                mob.attackImage.Stretch = Stretch.None;
                if (mob.dir == 0)
                {
                    mob.attackImage.FlowDirection = System.Windows.FlowDirection.LeftToRight;
                    Canvas.SetLeft(mob.attackImage, mob.position.x + 8);
                }
                else
                {
                    mob.attackImage.FlowDirection = System.Windows.FlowDirection.RightToLeft;
                    Canvas.SetLeft(mob.attackImage, mob.position.x - 8);
                }
                if (mob.Type == "Boss")
                {
                    Canvas.SetTop(mob.attackImage, mob.position.y + 32);
                }
                else
                {
                    Canvas.SetTop(mob.attackImage, mob.position.y);
                }
                await Task.Delay(200);

                MyCanvas.Children.Remove(mob.attackImage);
            }
            else
            {
                MyCanvas.Children.Add(img);
                img.Stretch = Stretch.None;
                if (mob.dir == 0)
                {
                    img.FlowDirection = System.Windows.FlowDirection.LeftToRight;
                    Canvas.SetLeft(img, mob.position.x + 32);
                }
                else
                {
                    img.FlowDirection = System.Windows.FlowDirection.RightToLeft;
                    Canvas.SetLeft(img, mob.position.x - 32);
                }
                Canvas.SetTop(img, mob.position.y + 48);
                await Task.Delay(Convert.ToInt32(time));

                MyCanvas.Children.Remove(img);
            }
        }
Пример #6
0
        public Position DistTo(Mobs self, Mobs target, int type)
        {
            Position dist = new Position();

            if (type == 0)
            {
                dist.x = Math.Abs(self.position.x - target.position.x);
                dist.y = Math.Abs(self.position.y - target.position.y);
            }
            else
            {
                dist.x = self.position.x - target.position.x;
                dist.y = self.position.y - target.position.y;
            }
            return(dist);
        }
Пример #7
0
 public async Task Attack(Mobs mob = null, int?type = null)
 {
     if (mob != null)
     {
         if (type == 0 && mob.AttackColdown <= 0)
         {
             if (WarMan.block)
             {
                 AttackAnim(mob);
                 BlockDown();
                 mob.AttackColdown = mob.AttackSpeed;
             }
             else
             {
                 AttackAnim(mob);
                 GetDamage(mob, 0);
                 mob.AttackColdown = mob.AttackSpeed;
             }
         }
     }
     else
     {
         if (WarMan.AttackColdown <= 0)
         {
             BlockDown();
             GetTarget();
             if (WarMan.targetList.Count > 0)
             {
                 AttackAnim(WarMan);
                 foreach (Mobs target in WarMan.targetList)
                 {
                     GetDamage(target, 1);
                     WarMan.AttackColdown = WarMan.AttackSpeed;
                 }
             }
             else
             {
                 AttackAnim(WarMan);
                 WarMan.AttackColdown = WarMan.AttackSpeed;
             }
         }
     }
 }
Пример #8
0
        public async Task BossAttack(Mobs mob)
        {
            if (mob.SuperAttackColdown <= 0 && DistTo(mob, WarMan, 0).x <= mob.SuperAttackDistance + 32)
            {
                mob.SuperAttackColdown = mob.SuperAttackSpeed;
                await AttackAnim(mob, mob.targetBossImage, 1000);

                await Task.Delay(300);

                AttackAnim(mob, mob.bigAttackImage, 900);
                if (DistTo(mob, WarMan, 0).x <= mob.SuperAttackDistance)
                {
                    GetDamage(mob, 0);
                }
            }
            else if (mob.SuperAttackColdown >= mob.SuperAttackSpeed / 4 && mob.SuperAttackColdown <= mob.SuperAttackSpeed / 2 && DistTo(mob, WarMan, 0).x <= mob.AttackDistance + 32 && mob.AttackColdown <= 0)
            {
                Attack(mob, 0);
            }
        }
Пример #9
0
        public async Task MoveTo(Mobs mob)
        {
            if (DistTo(mob, WarMan, 1).x > 16)
            {
                mob.position.x -= mob.Speed;
                mob.dir         = 1;
            }
            else if (DistTo(mob, WarMan, 1).x < -16)
            {
                mob.position.x += mob.Speed;
                mob.dir         = 0;
            }

            /* if (DistTo(mob, WarMan, 1).y > 16)
             * {
             *   mob.position.y -= mob.Speed;
             * }
             * else if (DistTo(mob, WarMan, 1).y < -16)
             * {
             *   mob.position.y += mob.Speed;
             * }*/
        }