Esempio n. 1
0
        protected override void LoadContent()
        {
            Content.RootDirectory = Path.GetFullPath(Settings.DataFolder);
            Environment.CurrentDirectory = Path.GetFullPath(Settings.DataFolder);
            FastSpriteBatch = new FastSpriteBatch(GraphicsDevice);

            Services.AddService(FastSpriteBatch);

            Services.AddService(Content);

            Timer = new TimerService();
            Services.AddService<ITimerService>(Timer);

            Coroutines = new CoroutineService();
            Services.AddService<ICoroutineService>(Coroutines);

            Services.AddService(GraphicsDevice);

            SpriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(SpriteBatch);

            Keyboard = new KeyboardService(Coroutines);
            Services.AddService<IKeyboardService>(Keyboard);

            Services.AddService(Window);

            Mouse = new MouseService(Coroutines);
            Services.AddService<IMouseService>(Mouse);

            Services.AddService<IAnimationService>(new AnimationService(Coroutines, Timer));

            Gui = new GuiService();
            Services.AddService<IGuiService>(Gui);

            SpriteManager = new SpriteManagerService(Content);
            Services.AddService<ISpriteManagerService>(SpriteManager);

            ShapeManager = new ShapeManagerService();
            Services.AddService<IShapeManagerService>(ShapeManager);

            Services.AddService(new SpaceBackgroundGeneratorService());

            GalaxyGenerator = new GalaxyGeneratorService();

            var testShips = new[] { "Ships/Jaeger.json", "Ships/Scimitar.json" }
                            .Select(s => Persistence.LoadFromFile<Game.Ships.Ship>(s))
                            .ToList();

            Game.Space.Star.LoadStellarClasses();

            Galaxy = GalaxyGenerator.CreateGalaxy();

            //ShipRefitScene = new ShipRefitScene(testShips);
            //ShipRefitScene.LoadContent();

            MainMenuScene = new MainMenuScene();
            MainMenuScene.LoadContent();

            SystemMapScene = new SystemMapScene(Galaxy.StarSystems[0]);
            SystemMapScene.LoadContent();

            //CurrentScene = MainMenuScene;
            //CurrentScene = SystemMapScene;
            MainGameScene = new MainGameScene();
            MainGameScene.LoadContent();

            CurrentScene = MainGameScene;

            CombatEntityFactory.LoadWeapons();
            CombatEntityFactory.LoadProjectiles();
            base.LoadContent();
        }
        internal void Initialize(D3D11Host host)
        {
            Services = new GameServiceContainer();

            ServiceLocator.Initialize(Services);

            Artemis.System.EntitySystem.BlackBoard.SetEntry("GraphicsDevice", host.GraphicsDevice);
            Artemis.System.EntitySystem.BlackBoard.SetEntry("ServiceProvider", Services);

            Services.AddService<IGraphicsDeviceService>(host);
            Services.AddService(host.GraphicsDevice);

            _mouse = new MouseService(host);
            Services.AddService<IMouseService>(_mouse);
            _mouse.ButtonDown += OnMouseButtonDown;
            _keyboard = new KeyboardService(host);
            Services.AddService<IKeyboardService>(_keyboard);
            _timer = new TimerService();
            Services.AddService<ITimerService>(_timer);
            Services.AddService(new FastSpriteBatch(host.GraphicsDevice));

            _timer.LastFrameUpdateTime = _gameTime;
            _timer.LastFrameRenderTime = _gameTime;

            SpriteBatch = new SpriteBatch(host.GraphicsDevice);
            Services.AddService(SpriteBatch);

            Content = new ContentManager(Services);
            Content.RootDirectory = Environment.CurrentDirectory;

            SpriteManager = new SpriteManagerService(Content);
            Services.AddService<ISpriteManagerService>(SpriteManager);

            SpriteManager.LoadSpriteSheet("Textures/Hulls.json");

            Host = host;
            World = new EntityWorld(false, false, false);
            int drawDepth = 0;
            World.CreateComponentPool<Transform>(200, 200);
            World.SystemManager.SetSystem(new GridRendererSystem(), Artemis.Manager.GameLoopType.Draw, drawDepth++);
            World.InitializeAll();
            World.CreateCamera(Constants.ActiveCameraTag, Host.GraphicsDevice);
            Emitter = new ParticleEmitterComponent();
        }
Esempio n. 3
0
        internal void Initialize(D3D11Host host)
        {
            if (IsInitialized) return;
            IsInitialized = true;

            Services = new GameServiceContainer();

            ServiceLocator.Initialize(Services);
            _host = host;

            Artemis.System.EntitySystem.BlackBoard.SetEntry("GraphicsDevice", _host.GraphicsDevice);
            Artemis.System.EntitySystem.BlackBoard.SetEntry("ServiceProvider", Services);

            Services.AddService<IGraphicsDeviceService>(host);
            Services.AddService(host.GraphicsDevice);

            _mouse = new MouseService(host);
            Services.AddService<IMouseService>(_mouse);
            _mouse.ButtonDown += OnMouseButtonDown;
            _keyboard = new KeyboardService(host);
            Services.AddService<IKeyboardService>(_keyboard);
            _timer = new TimerService();
            Services.AddService<ITimerService>(_timer);
            Services.AddService(new FastSpriteBatch(host.GraphicsDevice));

            _timer.LastFrameUpdateTime = _gameTime;
            _timer.LastFrameRenderTime = _gameTime;

            SpriteBatch = new SpriteBatch(host.GraphicsDevice);
            Services.AddService(SpriteBatch);

            Content = new ContentManager(Services);
            Content.RootDirectory = Environment.CurrentDirectory;

            SpriteManager = new SpriteManagerService(Content);
            Services.AddService<ISpriteManagerService>(SpriteManager);

            //LoadHullSprites("textures/hulls.json");

            Artemis.System.EntitySystem.BlackBoard.SetEntry("ContentManager", Content);

            World = new EntityWorld(false, false, false);

            World.CreateComponentPool<Transform>(200, 200);

            _gridSystem = new GridRendererSystem();
            _gridSystem.IsEnabled = false;
            World.SystemManager.SetSystem(_gridSystem, Artemis.Manager.GameLoopType.Draw, 1);
            //World.SystemManager.SetSystem(new ShipRendererSystem(), Artemis.Manager.GameLoopType.Draw, 2);
            World.SystemManager.SetSystem(new SceneGraphRendererSystem<StandardShipModelRenderer>(new StandardShipModelRenderer()), Artemis.Manager.GameLoopType.Draw, 3);
            World.SystemManager.SetSystem(new BoundingBoxRendererSystem(), Artemis.Manager.GameLoopType.Draw, 4);
            World.SystemManager.SetSystem(new GenericDrawableRendererSystem(), Artemis.Manager.GameLoopType.Draw, 5);
            _hardpointRendererSystem = new HardpointRendererSystem();
            _hardpointRendererSystem.IsEnabled = false;
            World.SystemManager.SetSystem(_hardpointRendererSystem, Artemis.Manager.GameLoopType.Draw, 6);

            World.SystemManager.SetSystem(new CameraControlSystem(), Artemis.Manager.GameLoopType.Update, 1);
            _transformSystem = new MouseControlledTransformSystem();
            World.SystemManager.SetSystem(_transformSystem, Artemis.Manager.GameLoopType.Update, 2);
            World.SystemManager.SetSystem(new ShipUpdateSystem(), Artemis.Manager.GameLoopType.Update, 3);
            World.SystemManager.SetSystem(new BoundingBoxSelectionSystem(), Artemis.Manager.GameLoopType.Update, 4);
            World.SystemManager.SetSystem(new ShowThrusterTrailsOverrideSystem(), Artemis.Manager.GameLoopType.Update, 5);

            World.InitializeAll();

            CameraEntity = World.CreateCamera(Constants.ActiveCameraTag, _host.GraphicsDevice);
            CameraEntity.Tag = Constants.ActiveCameraTag;
            Camera = CameraEntity.GetComponent<Camera>();

            GridEntity = World.CreateGrid(new Vector2(50, 50), GridColor);

            World.CreateCircle(Vector2.Zero, 10, 8, XnaColor.Red * 0.4f);

            host.PreviewKeyDown += HandleKeyboardInput;

            EditorService = new ShipEditorService(_mouse, World);
            CreateNewShipModelCommand.Execute(null);
            EditorService.SelectedPartEntities.CollectionChanged += (o, e) =>
            {
                if (e.NewItems != null && e.NewItems.Count > 0) {
                    var color = e.NewItems.Cast<Entity>().First().GetComponent<IShipPartComponent>().Part.Color;
                    _selectedColor = System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B);
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedColor)));
                }
            };

            
            _mouse.WheelChanged += OnWheelChanged;
            IsHardpointsVisible = false;
            LoadHullSprites("textures/hulls.json");
            IsGridVisible = true;
        }