Exemple #1
0
        /// <summary>
        /// Targets the nearest ship that meets the condition defined in selector.
        /// </summary>
        /// <param name="selector"></param>
        public bool TargetNearest(Func <SpaceShip, bool> selector)
        {
            Target = null;
            TargetDistanceSquared = int.MaxValue;
            int range;

            foreach (var ship in GameControl.Ships)
            {
                if (ship.IsAirborne && !ship.DeleteFlag && selector(ship))
                {
                    range = (int)Vector2.DistanceSquared(ship.Position, Owner.Position);
                    if (range < TargetDistanceSquared)
                    {
                        Target = ship;
                        TargetDistanceSquared = range;
                    }
                }
            }

            if (Target != null)
            {
                return(true);
            }
            return(false);
        }
 void Owner_ReachedTarget(SpaceShip obj)
 {
     index++;
     if (index == ScreenPositions.Length)
     {
         index = 0;
     }
 }
Exemple #3
0
 void ship_HitpointsChanged(SpaceShip obj)
 {
     for (int i = 0; i < Carrier.Slots.Length; i++)
     {
         if (Carrier.Slots[i].Flyers.Contains(obj))
         {
             showDeploySlotTimer[i] = lastUpdate;
         }
     }
 }
Exemple #4
0
        protected override void EndedShelling(GameTime gameTime)
        {
            OldTarget = Target;
            if (TargetDistanceSquared > RangeSquared)
            {
                OldTarget = null;
            }

            base.EndedShelling(gameTime);
        }
 public DummyWeapon(SpaceShip owner) : base(owner)
 {
     Name             = "None";
     Cycling          = true;
     Damage           = 0;
     RangeSquared     = (int)Math.Pow(0, 2);
     Cooldown         = TimeSpan.FromMilliseconds(1000);
     ShellingDuration = TimeSpan.FromMilliseconds(100);
     TargetSelector   = TargetNearestEnemy;
     AssignRandomCooldownPosition();
 }
Exemple #6
0
        public bool TargetSingle()
        {
            Debug.Assert(SingleTarget != null);

            Target = SingleTarget;
            if (Target != null)
            {
                RangeSquared = (int)Vector2.DistanceSquared(Target.Position, Owner.Position);
                return(true);
            }
            return(false);
        }
Exemple #7
0
        public Laser(SpaceShip owner, Vector2 weaponPosition)
            : base(owner)
        {
            WeaponPosition = weaponPosition;

            Name             = "Laser";
            Cycling          = true;
            Damage           = 2;
            RangeSquared     = (int)Math.Pow(200, 2);
            Cooldown         = TimeSpan.FromMilliseconds(2750);
            ShellingDuration = TimeSpan.FromMilliseconds(150);
            TargetSelector   = TargetNearestEnemy;
            AssignRandomCooldownPosition();
        }
        private void CreatePlayer(int p, ControlKeySettings keys, GameTime gameTime)
        {
            Player[p] = new Player() { Keys = keys };

            var motherShip = new Carrier(Hud, Player[p]) { Position = new Vector2(300 + 300 * p, 500), Ki = new SpaceShip.NoScreenMovement() };
            Player[p].AssignCarrier(motherShip);
            Ships.Add(motherShip);

            for (int i = 0; i < 4; i++)
            {
                var ship = new SpaceShip(Player[p]) { Carrier = motherShip,Status= SpaceShip.Conditions.InHangar };
                Player[p].AddShipToCarrier(ship);
                Ships.Add(ship);
                motherShip.Slots[i] = new DeploySlots(ship);
            }
        }
Exemple #9
0
        void ship_StatusChanged(SpaceShip ship)
        {
            if (ship.Status != SpaceShip.Conditions.ReturningPhase2)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (Carrier.Slots[i].Flyers.Contains(ship))
                    {
                        showDeploySlotTimer[i] = lastUpdate;
                    }
                }
            }

            if (ship.Status == SpaceShip.Conditions.Airborne)//Ship have just finished deployment
            {
                ship.Ki = new SpaceShip.KeepScreenPosition(ship.TargetPosition + GameControl.Hud.Camera);
            }
        }
Exemple #10
0
        /// <summary>
        /// Targets the ship with the fewest hitpoints that meets the condition defined in selector.
        /// </summary>
        /// <param name="selector"></param>
        public bool TargetLowestHitpoints(Func <SpaceShip, bool> selector)
        {
            Target = null;
            int hitpoints = int.MaxValue;

            foreach (var ship in GameControl.Ships)
            {
                if (ship.IsAirborne && !ship.DeleteFlag && selector(ship))
                {
                    if (ship.Hitpoints < hitpoints)
                    {
                        Target    = ship;
                        hitpoints = ship.Hitpoints;
                    }
                }
            }

            if (Target != null)
            {
                RangeSquared = (int)Vector2.DistanceSquared(Target.Position, Owner.Position);
                return(true);
            }
            return(false);
        }
Exemple #11
0
 void Carrier_HitpointsChanged(SpaceShip none)
 {
     showDamageTimer = lastUpdate;
 }
Exemple #12
0
 public void AddShipToCarrier(SpaceShip ship)//TODO: make carrier-spaceship interface more clear (maybe remove slots).
 {
     ship.Carrier           = Carrier;
     ship.StatusChanged    += ship_StatusChanged;
     ship.HitpointsChanged += ship_HitpointsChanged;
 }
Exemple #13
0
 public Weapon(SpaceShip owner)
 {
     Owner  = owner;
     Status = Conditions.CoolingDown;
 }
 public FixedEnemy(SpaceShip target)
 {
     this.target = target;
 }
Exemple #15
0
 void ReturningPhase2End(SpaceShip none)
 {
     Status = Conditions.InHangar;
     track.Clear();
 }
Exemple #16
0
 void ReturningPhase1End(SpaceShip none)
 {
     Status         = Conditions.ReturningPhase2;
     TargetPosition = Carrier.Position + new Vector2(0, Carrier.Sprite.TextureOrigin.Y / 2);
     ReachedTarget += ReturningPhase2End;
 }