public override void Execute(Ship ship)
        {
            if (!Completed)
            {
                base.Execute(ship);

                ElapsedTime++;
                if (ElapsedTime >= Amount)
                    Completed = true;
            }
        }
 public virtual void Execute(Ship ship)
 {
     if (!Completed)
     {
         timeoutTime++;
         if (timeoutTime > 500)
         {
             timeoutTime = 0;
             Completed = true;
         }
     }
 }
        public override void Execute(Ship ship)
        {
            if (!Completed)
            {
                base.Execute(ship);

                double angle = ship.GetAngle();
                double radangle = (angle - 90) * 0.017453292519943295769236907684886;
                double xdir = Math.Cos(radangle);
                double ydir = Math.Sin(radangle);

                if (Forward)
                    ship.UpdatePosition(xdir * Speed, ydir * Speed);
                else
                    ship.UpdatePosition(xdir * -Speed, ydir * -Speed);

                if (ship.GetX() < MainWindow._instance.WindowXOffset ||
                    ship.GetX() > MainWindow._instance.WindowWidthOffset-ship.Width ||
                    ship.GetY() < MainWindow._instance.WindowYOffset ||
                    ship.GetY() > MainWindow._instance.WindowHeightOffset-ship.Height)
                {
                    Completed = true;
                    if (ship.GetX() < MainWindow._instance.WindowXOffset)
                    {
                        ship.SetX(MainWindow._instance.WindowXOffset);
                        ship.Commander.ExecuteOnCollideWithLeft();
                    }
                    else
                    if (ship.GetX() > MainWindow._instance.WindowWidthOffset - ship.Width)
                    {
                        ship.SetX(MainWindow._instance.WindowWidthOffset - ship.Width);
                        ship.Commander.ExecuteOnCollideWithRight();
                    }
                    else
                    if (ship.GetY() < MainWindow._instance.WindowYOffset)
                    {
                        ship.SetY(MainWindow._instance.WindowYOffset);
                        ship.Commander.ExecuteOnCollideWithTop();
                    }
                    else
                    if (ship.GetY() > MainWindow._instance.WindowHeightOffset - ship.Height)
                    {
                        ship.SetY(MainWindow._instance.WindowHeightOffset - ship.Height);
                        ship.Commander.ExecuteOnCollideWithBottom();
                    }
                }

                ElapsedTime++;
                if (ElapsedTime >= Amount)
                    Completed = true;
            }
        }
        public override void Execute(Ship ship)
        {
            base.Execute(ship);
            if (ship != null && ship.CanScan)
            {
                ship.CanScan = false;
                Bullet b = new Bullet("Data\\scanBullet.png", ship.GetX() + ship.Width / 2 - 30, ship.GetY() + ship.Height / 2 - 5, ship);
                b.SetAngle(ship.GetAngle());
                b.Speed = 15;
                b.drawOrder = 250;
                b.IsScanner = true;
                MainWindow._instance.AddedComponents.Add(b);
            }

            Completed = true;
        }
        public override void Execute(Ship ship)
        {
            base.Execute(ship);
            if (ship != null)
            {
                if (Type == 0 && ship.CanFireBullet)
                {
                    ship.CanFireBullet = false;
                    Bullet b = new Bullet("Data\\Ships\\bullet1.png", ship.GetX() + ship.Width / 2 - 15, ship.GetY() + ship.Height / 2 - 15, ship);
                    b.SetAngle(ship.GetAngle());
                    b.Speed = 5;
                    b.Damage = 5;
                    b.drawOrder = ship.DrawOrder + 100;
                    MainWindow._instance.AddedComponents.Add(b);
                }
                else
                    if (Type == 1 && ship.CanFirePlasma)
                    {
                        ship.CanFirePlasma = false;
                        Bullet b = new Bullet("Data\\Ships\\bullet2.png", ship.GetX() + ship.Width / 2 - 18, ship.GetY() + ship.Height / 2 - 18, ship);
                        b.SetAngle(ship.GetAngle());
                        b.Speed = 6;
                        b.Damage = 10;
                        b.drawOrder = ship.DrawOrder + 100;
                        MainWindow._instance.AddedComponents.Add(b);
                    }
                    else
                        if (Type == 2 && ship.CanFireMissile)
                        {
                            ship.CanFireMissile = false;
                            Bullet b = new Bullet("Data\\Ships\\bullet3.png", ship.GetX() + ship.Width / 2 - 15, ship.GetY() + ship.Height / 2 - 21, ship);
                            b.SetAngle(ship.GetAngle());
                            b.Speed = 4;
                            b.Damage = 15;
                            b.drawOrder = ship.DrawOrder + 100;
                            MainWindow._instance.AddedComponents.Add(b);
                        }
            }

            Completed = true;
        }
        public ShipCommander(String filename, double startX, double startY)
        {
            controller = new ShipController();
            ship = new Ship("Data\\Ships\\ship1.png", startX, startY);
            ship.drawOrder = 200;
            ship.Commander = this;
            MainWindow._instance.AddedComponents.Add(ship);

            try
            {
                assembly = Assembly.LoadFile(filename);
                type = assembly.GetTypes()[0];
                if (type != null)
                {
                    controller.SetShip(ship);
                    ship.Controller = controller;
                    classInstance = Activator.CreateInstance(type, new object[] { controller });

                    runMethodInfo = type.GetMethod("Run");
                    bulletHitBulletMethodInfo = type.GetMethod("OnBulletHitBullet");
                    bulletHitMethodInfo = type.GetMethod("OnBulletHit");
                    bulletMissedMethodInfo = type.GetMethod("OnBulletMissed");
                    hitByBulletMethodInfo = type.GetMethod("OnHitByBullet");
                    scannedShipMethodInfo = type.GetMethod("OnScannedShip");
                    deathMethodInfo = type.GetMethod("OnDeath");
                    winMethodInfo = type.GetMethod("OnWin");

                    collideWithShipMethodInfo = type.GetMethod("OnCollideWithShip");
                    collideWithTopMethodInfo = type.GetMethod("OnCollideWithTop");
                    collideWithBottomMethodInfo = type.GetMethod("OnCollideWithBottom");
                    collideWithLeftMethodInfo = type.GetMethod("OnCollideWithLeft");
                    collideWithRightMethodInfo = type.GetMethod("OnCollideWithRight");
                }
            }
            catch (ReflectionTypeLoadException e)
            {

            }
        }
        public override void Execute(Ship ship)
        {
            if (!Completed)
            {
                base.Execute(ship);

                if (Math.Round(ship.GetAngle()) == Math.Round(EndValue))
                    Completed = true;
                else
                {
                    if (Clockwise)
                        ship.UpdateAngle(1);
                    else
                        ship.UpdateAngle(-1);

                    double angle = ship.GetAngle();
                    if (angle < 0) angle = 360;
                    if (angle > 360) angle = 0;
                    ship.SetAngle(angle);
                }
            }
        }
示例#8
0
 public Bullet(string filename, double x, double y, Ship owner)
     : base(filename, x, y)
 {
     Alive = true;
     Owner = owner;
 }
 public void SetShip(IDrawableEntity ship)
 {
     Ship = ship as Ship;
 }