public override void Update(float secondsElapsed)
        {
            //throw new NotImplementedException();
            Vector2 aim = this.Aimpoint;
            Boolean fire = this.Fire;

            if (target == null || target.IsDestroyed)
            {
                target = null;

                List<Ship> ships = new List<Ship>();
                foreach (SmallShip t in this.game.GameObjectCollection.GetMasterList().GetList<SmallShip>())
                {
                    if (Vector2.Distance(t.Position, this.Focus.Position) < 3000)
                    {
                        ships.Add(t);
                    }
                }

                ships.Remove(this.Focus);
                if (ships.Count > 0)
                {
                    target = ships[RandomUtils.random.Next(ships.Count)];
                }
            }
            else
            {
                aim = target.Position - this.Focus.Position;
                fire = Vector2.Distance(target.Position, this.Focus.Position) < 3000;
            }

            this.Aimpoint = aim;
            this.Fire = fire;
        }
Пример #2
0
        public static void ServerInitialize(Bullet obj, Ship owner, Vector2 position, float direction)
        {
            MovingGameObject.ServerInitialize(obj, position, Utils.Vector2Utils.ConstructVectorFromPolar(speed, direction) /*+ owner.Velocity*/, direction, 0, direction);

            obj.owner.Value = owner;
            obj.start.Value = position;
        }
Пример #3
0
        public static void ServerInitialize(Ship ship, Vector2 position, Vector2 velocity, float direction, int health, float maxSpeed, float acceleration, float maxAgularSpeed, ControlState controller)
        {
            MovingGameObject.ServerInitialize(ship, position, new Vector2(0), direction, 0, 0);
            ship.health.Value = health;
            ship.maxSpeed.Value = maxSpeed;
            ship.acceleration.Value = acceleration;
            ship.maxAgularSpeed.Value = maxAgularSpeed;

            ship.controller = controller;
        }
Пример #4
0
        public override void Update(float secondsElapsed)
        {
            //throw new NotImplementedException();
            Vector2 aim = this.Aimpoint;
            float targetAngle = 0;
            float angleControl = 0;
            Boolean fire = this.Fire;

            if (target == null || target.IsDestroyed)
            {
                target = null;

                List<Ship> ships = new List<Ship>();
                foreach (Tower t in this.game.GameObjectCollection.GetMasterList().GetList<Tower>())
                {
                    ships.Add(t);
                }
                foreach (BigShip t in this.game.GameObjectCollection.GetMasterList().GetList<BigShip>())
                {
                    ships.Add(t);
                }

                ships.Remove(this.Focus);
                if (ships.Count > 0)
                {
                    target = ships[RandomUtils.random.Next(ships.Count)];
                }
            }
            else
            {
                if (Vector2.Distance(target.Position, this.Focus.Position) > 1000)
                {
                    flyTowardsRelative = new Vector2(0);
                }

                if (Vector2.Distance(target.Position, this.Focus.Position) < 500 && flyTowardsRelative == new Vector2(0))
                {
                    flyTowardsRelative = Utils.Vector2Utils.ConstructVectorFromPolar(2000, (float)(RandomUtils.random.NextDouble() * Math.PI * 2));
                }

                aim = target.Position - this.Focus.Position;
                targetAngle = Utils.Vector2Utils.RestrictAngle(Utils.Vector2Utils.Vector2Angle(target.Position - (this.Focus.Position + flyTowardsRelative)));
                angleControl = 1;
                fire = Vector2.Distance(target.Position, this.Focus.Position) < 3000;
            }

            this.Aimpoint = aim;
            this.AngleControl = angleControl;
            this.TargetAngle = targetAngle;
            this.MovementControl = 1;
            this.Fire = fire;
        }
Пример #5
0
        public override void Update(float secondsElapsed)
        {
            this.Fire = false;

            if (target == null || target.IsDestroyed)
            {
                target = null;

                List<Ship> ships = new List<Ship>();
                foreach (SmallShip t in this.game.GameObjectCollection.GetMasterList().GetList<SmallShip>())
                {
                    if (Vector2.Distance(t.Position, this.Focus.Position) < 3000)
                    {
                        ships.Add(t);
                    }
                }

                ships.Remove(this.Focus);
                if (ships.Count > 0)
                {
                    target = ships[RandomUtils.random.Next(ships.Count)];
                }
            }
            else
            {
                this.Aimpoint = target.Position - this.Focus.Position;
                this.Fire = Vector2.Distance(target.Position, this.Focus.Position) < 3000;
            }

            float newDistance = Vector2.Distance(targetPosition, this.Focus.Position);

            this.TargetAngle = Utils.Vector2Utils.RestrictAngle(Utils.Vector2Utils.Vector2Angle(targetPosition - this.Focus.Position));

            if (newDistance < 300)
            {
                this.MovementControl = 0;
                this.AngleControl = 0;
            }
        }
 /*
 public override void SendUpdateMessage(Lobby lobby, GameTime gameTime)
 {
     //TODO: what about if a new player joins?  This is similar to other game set up data like world-size
     if (sendUpdate)
     {
         sendUpdate = false;
         lobby.BroadcastTCP(new GameObjectUpdate(gameTime, this));
     }
 }*/
 public void SetFocus(Player player, Ship obj)
 {
     focusList.Value[player.Id] = obj;
     sendUpdate = true;
 }