示例#1
0
        //fleet functions
        //bool good-to-go
        bool CheckShipEquipment(Ship _s)
        {
            foreach (Item _i in _s.Inventory.FindAll(
                x => x.HasTag("weapon")))
                _i.Use();

            //equip all weapons available
            if (_s.Components.FindAll(
                x => x.Item.HasTag("weapon")).Count == 0)
                return false;

            if (targets.Count == 0)
            {
                foreach (ShipComponent _c in
                    _s.Components
                    .FindAll(x => x.Item.HasTag("weapon"))
                    .Cast<Weapon>()
                ) {
                    Weapon _w = _c as Weapon;
                    _w.Targets.Clear();
                    _w.Active = true;
                }
                return false;
            }

            return true;
        }
示例#2
0
 void ShipFire(Ship _s)
 {
     foreach (ShipComponent _c in
         _s.Components
         .FindAll(x => x.Item.HasTag("weapon"))
         .Cast<Weapon>()
     ) {
         Weapon _w = _c as Weapon;
         _w.Targets = new List<SpaceObject> { fleetTargets[_s] };
         _w.Active = true;
     }
 }
示例#3
0
文件: Game1.cs 项目: Koneke/Apollyon
        protected override void Initialize()
        {
            StationState stationState;

            Game.AddState("space", new SpaceState());
            //Game.SpaceState = spaceState = new SpaceState();
            stationState = new StationState();

            base.Initialize();

            graphics.PreferredBackBufferWidth = 1600;
            graphics.PreferredBackBufferHeight = 900;
            graphics.ApplyChanges();

            Game.ScreenSize.X = graphics.PreferredBackBufferWidth;
            Game.ScreenSize.Y = graphics.PreferredBackBufferHeight;
            Game.Camera = new Camera();
            Game.World = (new DevWorldGenerator()).Generate(new World());

            UIBindings.Bind("Selected", new List<SpaceObject>());
            UIBindings.Bind("Targeted", new List<SpaceObject>());
            UIBindings.Bind("All", new List<SpaceObject>());

            //spaceState.World = Game.World;
            ((SpaceState)Game.GetState("space")).World = Game.World;
            Game.ActiveStates.Add(Game.GetState("space"));

            stationState.Station = new Station(Game.World);
            stationState.Station.Name = "The Spooky Sailor Cafe";
            Ship _s = new Ship(
                Vector2.Zero,
                Game.World
            );
            _s.Faction = Game.PlayerFaction;
            Game.World.SpaceObjects.Add(_s);
            stationState.Station.Dock(_s);
            Game.ActiveStates.Add(stationState);

            foreach (GameState _gs in Game.ActiveStates)
                _gs.Load();

            Audio.bgm = Audio.Play("mus/mAmbience.ogg", 0.05f, false, true);
            Audio.bgm.Volume = Audio.Mute ? 0 : 0.05f;

            //REMEMBER: convenience while deving
            //(so i can spawn at 0,0 and still see stuff)
            Game.Camera.X -= 600;
            Game.Camera.Y -= 400;
        }
示例#4
0
        public override World Generate(World _world)
        {
            Faction _f = new Faction("The Rude Dudes");
            Faction _aifactionA = new Faction("The Lumberjack Organization");
            Faction _aifactionB = new Faction("The Lumberjack Organization B");

            Game.PlayerFaction = _f;

            Faction.SetRelations(_f, _aifactionA, 0f);
            Faction.SetRelations(_aifactionB, _aifactionA, -1f);

            Ship _s = new Ship(new Vector2(100, 300), _world);
            _world.SpaceObjects.Add(_s);

            _s.AddItem(ItemDatabase.Spawn(_world,
                ItemDatabase.Items.Find(x => x.ID == 1102)));
            _s.AddItem(ItemDatabase.Spawn(_world,
                ItemDatabase.Items.Find(x => x.ID == 1102)));
            _s.AddItem(ItemDatabase.Spawn(_world,
                ItemDatabase.Items.Find(x => x.ID == 1102)));
            _s.AddItem(ItemDatabase.Spawn(_world, //spawn into inventory
                ItemDatabase.Items.Find(x => x.ID == 1199)));
            ItemDatabase.Spawn(_world, //spawn into space
                ItemDatabase.Items.Find(x => x.ID == 1100))
                .SetPosition(new Vector2(100, 100));

            _s.Faction = _f;

            AISimpleMiner _AI = new AISimpleMiner();
            Game.AIs.Add(_AI);
            AISimpleFighter _AI2 = new AISimpleFighter();
            _AI2.Faction = _aifactionA;
            Game.AIs.Add(_AI2);

            AISimpleFighter _AI3 = new AISimpleFighter();
            _AI3.Faction = _aifactionB;
            Game.AIs.Add(_AI3);

            for (int i = 0; i < 3; i++)
            {
                _s = new Ship(new Vector2(
                    (float)Game.Random.NextDouble()*7000,
                    (float)Game.Random.NextDouble()*7000
                    ),
                    _world
                );
                _world.SpaceObjects.Add(_s);
                _s.AddItem(ItemDatabase.Spawn(_world,
                    ItemDatabase.Items.Find(x => x.ID == 1101)));
                _AI2.Fleet.Add(_s);
                _s.Faction = _aifactionA;

                _s = new Ship(new Vector2(
                    (float)Game.Random.NextDouble()*7000,
                    (float)Game.Random.NextDouble()*7000
                    ),
                    _world
                );
                _world.SpaceObjects.Add(_s);
                _s.AddItem(ItemDatabase.Spawn(_world,
                    ItemDatabase.Items.Find(x => x.ID == 1101)));
                _AI3.Fleet.Add(_s);
                _s.Faction = _aifactionB;
            }

            _s = new Ship(new Vector2(100, 100), _world);
            _world.SpaceObjects.Add(_s);
            _s.AddItem(ItemDatabase.Spawn(_world,
                ItemDatabase.Items.Find(x => x.ID == 1102)));
            _s.AddItem(ItemDatabase.Spawn(_world,
                ItemDatabase.Items.Find(x => x.ID == 1102)));
            _AI.Fleet.Add(_s);
            _s.Faction = _aifactionA;

            Asteroid _a = new Asteroid("Asteroid", _world);
            _a.Position = new Vector2(400, 400);

            _a = new Asteroid("Asteroid", _world);
            _a.Position = new Vector2(0, 80);

            Container _c = new Container("Generic Container", _world);

            return _world;
        }
示例#5
0
 public void Undock(Ship _s)
 {
     DockedShips.Remove(_s);
     Utility.Untag(_s, "docked");
 }
示例#6
0
 public void Dock(Ship _s)
 {
     DockedShips.Add(_s);
     _s.Position = Position;
     Utility.Tag(_s, "docked");
 }
示例#7
0
        void ShipMove(Ship _s, float _targetRange)
        {
            float _distance = Vector2.Distance(
                _s.Position,
                fleetTargets[_s].Position);

            if (
                _distance > _targetRange * 0.9f ||
                _distance < _targetRange * 0.7f
                )
            {
                double _angle = Math.Atan2(
                    fleetTargets[_s].Position.Y - _s.Position.Y,
                    fleetTargets[_s].Position.X - _s.Position.X);

                //aiming at 90% of the range so we have a bit of margin if
                //we/they move

                _s.TargetPosition =
                    new Vector2(
                        fleetTargets[_s].Position.X +
                            (float)Math.Cos(_angle) * _targetRange * 0.9f,
                        fleetTargets[_s].Position.Y +
                            (float)Math.Sin(_angle) * _targetRange * 0.9f
                        );
            }
            else
            {
                _s.Stop();
            }
        }
示例#8
0
        //returns optim range
        float ShipTarget(Ship _s)
        {
            float _targetRange =
                //find all our weapons
                _s.Components.FindAll(
                    x => x.Item.HasTag("weapon"))
                //and select the one with the worst range
                .Cast<Weapon>().OrderBy(x => x.Range).ToList()[0].Range;

            bool _retarget = false;

            if (!fleetTargets.Keys.Contains(_s))
                _retarget = true;

            else if(fleetTargets[_s].Health <= 0)
                _retarget = true;

            if (_retarget)
            {
                //retarget closest target
                fleetTargets[_s] = targets.OrderBy(
                    x => Vector2.Distance(x.Position, _s.Position))
                    .ToList()[0];
            }

            return _targetRange;
        }