Ejemplo n.º 1
0
        public void Shoot()
        {
            switch (kolobok.TankDirection)
            {
            case Direction.Left:
                PackmanProjectiles.Add(new PackmanProjectile(kolobok.X - 21, kolobok.Y - 5, kolobok.TankDirection));
                break;

            case Direction.Right:
                PackmanProjectiles.Add(new PackmanProjectile(kolobok.X + 11, kolobok.Y - 5, kolobok.TankDirection));
                break;

            case Direction.Up:
                PackmanProjectiles.Add(new PackmanProjectile(kolobok.X - 5, kolobok.Y - 21, kolobok.TankDirection));
                break;

            case Direction.Down:
                PackmanProjectiles.Add(new PackmanProjectile(kolobok.X - 5, kolobok.Y + 11, kolobok.TankDirection));
                break;
            }
        }
Ejemplo n.º 2
0
        private void DoWithProjectiles()
        {
            //полёт снарядов
            foreach (var p in Projectiles)
            {
                p.Run();
            }
            foreach (var p in PackmanProjectiles)
            {
                p.Run();
            }

            //столкновение снаряда с границей
            foreach (var t in Projectiles)
            {
                switch (t._direction)
                {
                case Direction.Left:
                    if (t.X + 10 < 0)
                    {
                        Projectiles.Remove(t);
                    }
                    break;

                case Direction.Right:
                    if (t.X + 20 > _fieldWidth)
                    {
                        Projectiles.Remove(t);
                    }
                    break;

                case Direction.Up:
                    if (t.Y + 10 < 0)
                    {
                        Projectiles.Remove(t);
                    }
                    break;

                case Direction.Down:
                    if (t.Y + 20 > _fieldHeight)
                    {
                        Projectiles.Remove(t);
                    }
                    break;
                }
                break;
            }

            foreach (var t in PackmanProjectiles)
            {
                switch (t._direction)
                {
                case Direction.Left:
                    if (t.X + 10 < 0)
                    {
                        PackmanProjectiles.Remove(t);
                    }
                    break;

                case Direction.Right:
                    if (t.X + 20 > _fieldWidth)
                    {
                        PackmanProjectiles.Remove(t);
                    }
                    break;

                case Direction.Up:
                    if (t.Y + 10 < 0)
                    {
                        PackmanProjectiles.Remove(t);
                    }
                    break;

                case Direction.Down:
                    if (t.Y + 20 > _fieldHeight)
                    {
                        PackmanProjectiles.Remove(t);
                    }
                    break;
                }
                break;
            }

            //столкновение снаряда со стеной
            foreach (var a in Walls)
            {
                for (int i = 0; i < Projectiles.Count; i++)
                {
                    if (AllCollision.BoxCollides(Projectiles[i].X + 10, Projectiles[i].Y + 10, 10, 10, a.XLeft, a.YUp, a.XRight - a.XLeft, a.YDown - a.YUp))
                    {
                        Projectiles.Remove(Projectiles[i]);
                    }
                }
            }

            foreach (var a in Walls)
            {
                for (int i = 0; i < PackmanProjectiles.Count; i++)
                {
                    if (AllCollision.BoxCollides(PackmanProjectiles[i].X + 10, PackmanProjectiles[i].Y + 10, 10, 10, a.XLeft, a.YUp, a.XRight - a.XLeft, a.YDown - a.YUp))
                    {
                        PackmanProjectiles.Remove(PackmanProjectiles[i]);
                    }
                }
            }
        }