示例#1
0
        public GameScreen(Game game)
            : base()
        {
            _game = (GameManager)game;

            _graphicsService = (GraphicsManager)game.Services.GetService(typeof(IGraphicsService));
            _contentService = (ContentManager)game.Services.GetService(typeof(ContentManager));
            _inputService = (InputManager)game.Services.GetService(typeof(IInputService));
        }
示例#2
0
        protected override void Initialize()
        {
            // ----- Initialize Services.
              // The services are stored in Game.Services to make them accessible for all
              // game components.

              // Add the input service, which manages device input, button presses, etc.
              _inputManager = new InputManager(false);
              Services.AddService(typeof(IInputService), _inputManager);

              // Add the animation service.
              _animationManager = new AnimationManager();
              Services.AddService(typeof(IAnimationService), _animationManager);

              // Add the physics simulation to the service and add some force effects.
              // (TODO: Create a IPhysicsService that owns the simulation.)
              _simulation = new Simulation();
              _simulation.ForceEffects.Add(new Gravity());
              _simulation.ForceEffects.Add(new Damping());
              Services.AddService(typeof(Simulation), _simulation);

              // ----- Add GameComponents
              Components.Add(new GamerServicesComponent(this));               // XNA gamer services needed for avatars.
              Components.Add(new Camera(this));                               // Controls the camera.
              Components.Add(new BallShooter(this));                          // Shoot balls at the target position.
              Components.Add(new Grab(this));                                 // Allows to grab objects with the mouse/gamepad
              Components.Add(new RigidBodyRenderer(this) { DrawOrder = 10 }); // Renders all rigid bodies of the simulation.
              Components.Add(new Reticle(this) { DrawOrder = 20 });           // Draws a cross-hair for aiming.
              Components.Add(new Help(this) { DrawOrder = 30 });              // Draws help text.
              Components.Add(new Profiler(this) { DrawOrder = 40 });          // Displays profiling data.

              // Initialize the sample factory methods. All samples must be added to this
              // array to be shown.
              _createSampleDelegates = new Func<Sample>[]
              {
            () => new BasicAvatarSample(this),
            () => new WrappedAnimationSample(this),
            () => new BakedAnimationSample(this),
            () => new CustomAnimationSample(this),
            () => new AttachmentSample(this),
            () => new RagdollSample(this),
            () => new AdvancedRagdollSample(this),
              };

              // Start the first sample in the array.
              _activeSampleIndex = 0;
              _activeSample = _createSampleDelegates[0]();
              Components.Add(_activeSample);

              base.Initialize();
        }
示例#3
0
        protected override void Initialize()
        {
            // ----- Initialize Services.
              // The services are stored in Game.Services to make them accessible for all
              // game components.

              // Add the input service, which manages device input, button presses, etc.
              _inputManager = new InputManager(false);
              Services.AddService(typeof(IInputService), _inputManager);

              // Add the physics simulation to the service.
              _simulation = new Simulation();
              // We do not add the standard force effects because our bodies should only
              // be modified by Kinect data!
              //_simulation.ForceEffects.Add(new Gravity());
              //_simulation.ForceEffects.Add(new Damping());
              Services.AddService(typeof(Simulation), _simulation);

              // ----- Add GameComponents
              Components.Add(new Camera(this));                         // Controls the camera.
              Components.Add(new RigidBodyRenderer(this, _simulation)); // Renders rigid bodies for debugging.
              Components.Add(new Help(this) { DrawOrder = 30 });        // Draws help text.
              Components.Add(new KinectWrapper(this));                  // Wraps the Kinect sensor.

              // Initialize the sample factory methods. All samples must be added to this
              // array to be shown.
              _createSampleDelegates = new Func<SampleBase>[]
              {
            () => new SkeletonMappingSample(this),
            () => new RagdollMarionetteSample(this),
              };

              // Start the first sample in the array.
              _activeSampleIndex = 0;
              _activeSample = _createSampleDelegates[0]();
              Components.Add(_activeSample);

              base.Initialize();
        }
示例#4
0
        protected override void Initialize()
        {
            // ----- Initialize Services.
              // The services are stored in Game.Services to make them accessible for all
              // game components.

              // Add the input service, which manages device input, button presses, etc.
              _inputManager = new InputManager(false);
              Services.AddService(typeof(IInputService), _inputManager);

              // Add the animation service.
              _animationManager = new AnimationManager();
              Services.AddService(typeof(IAnimationService), _animationManager);

              // ----- Add GameComponents
              // Initialize the sample factory methods. All samples must be added to this array
              // to be shown.
              _createSampleDelegates = new Func<Sample>[]
              {
            () => new BasicAnimationSample(this),
            () => new CompositeAnimationSample(this),
            () => new PathAnimationSample(this),
            () => new EasingSample(this),
            () => new CustomAnimationSample(this),
            () => new CrossFadeSample(this),
            () => new AnimatableObjectSample(this),
            () => new BlendedAnimationSample(this),
            () => new AdditiveAnimationSample(this),
            () => new DoubleAnimationSample(this),
            () => new StringAnimationSample(this),
              };

              // Start the first sample in the array.
              _activeSampleIndex = 0;
              _activeSample = _createSampleDelegates[0]();
              Components.Add(_activeSample);

              base.Initialize();
        }
示例#5
0
        protected override void Initialize()
        {
            _serviceContainer = new ServiceContainer();
            ServiceLocator.SetLocatorProvider(() => _serviceContainer);

            _serviceContainer.Register(typeof(Game), null, this);
            _serviceContainer.Register(typeof(ContentManager), null, Content);

            // Adds the input service, which manages device input, button presses etc.
            _inputManager = new InputManager(false);
            _serviceContainer.Register(typeof(IInputService), null, _inputManager);

            // Adds the UI service which manages UI screens
            _uiManager = new UIManager(this, _inputManager);
            _serviceContainer.Register(typeof(IUIService), null, _uiManager);

            _graphicsManager = new GraphicsManager(GraphicsDevice, Window, Content);
            Services.AddService(typeof(IGraphicsService), _graphicsManager);
            _serviceContainer.Register(typeof(IGraphicsService), null, _graphicsManager);

            _animationManager = new AnimationManager();
            _serviceContainer.Register(typeof(IAnimationService), null, _animationManager);

            _gameObjectManager = new GameObjectManager();
            _serviceContainer.Register(typeof(IGameObjectService), null, _gameObjectManager);

            _debugRenderer = new DebugRenderer(_graphicsManager, Content.Load<SpriteFont>("UI/MiramonteBold"));
            _serviceContainer.Register(typeof(DebugRenderer), null, _debugRenderer);

            _serviceContainer.Register(typeof(ContentManager), null, Content);

            _spriteBatch = new SpriteBatch(GraphicsDevice);
            _serviceContainer.Register(typeof(SpriteBatch), null, _spriteBatch);

            _gameLog = new GameLog();
            _serviceContainer.Register(typeof(GameLog), null, _gameLog);

            _gameSettings = new GameSettings();
            _serviceContainer.Register(typeof(GameSettings), null, _gameSettings);

            var uiTheme = Content.Load<Theme>("UI/UITheme");
            UIRenderer renderer = new UIRenderer(this, uiTheme);

            var screen = new UIScreen("Default", renderer)
            {
                Background = new Color(0, 0, 0, 0),
            };

            _uiManager.Screens.Add(screen);

            _mainGameComponent = new MainGameComponent(this);
            Components.Add(new StartScreenComponent(this));
            Components.Add(new GamerServicesComponent(this));

            //_updateAnimation = () => _animationManager.Update(_deltaTime);

            base.Initialize();
        }
示例#6
0
        protected override void Initialize()
        {
            // ----- Initialize Services.
              // The services are stored in Game.Services to make them accessible for all
              // game components.

              // Add the input service, which manages device input, button presses, etc.
              _inputManager = new InputManager(false);
              Services.AddService(typeof(IInputService), _inputManager);

              // Add the animation service.
              _animationManager = new AnimationManager();
              Services.AddService(typeof(IAnimationService), _animationManager);

              // Add the physics simulation to the service.
              // (TODO: Create a IPhysicsService that owns the simulation.)
              _simulation = new Simulation();
              // Add standard force effects:
              _simulation.ForceEffects.Add(new Gravity());
              _simulation.ForceEffects.Add(new Damping());
              Services.AddService(typeof(Simulation), _simulation);

              // ----- Add GameComponents
              Components.Add(new Camera(this));                               // Controls the camera.
              Components.Add(new BallShooter(this));                          // Shoot balls at the target position.
              Components.Add(new Grab(this));                                 // Allows to grab objects with the mouse/gamepad
              Components.Add(new RigidBodyRenderer(this) { DrawOrder = 10 }); // Renders all rigid bodies of the simulation.
              Components.Add(new Reticle(this) { DrawOrder = 20 });           // Draws a cross-hair for aiming.
              Components.Add(new Help(this) { DrawOrder = 30 });              // Draws help text.
              Components.Add(new Profiler(this) { DrawOrder = 40 });          // Displays profiling data.

              // Initialize the sample factory methods. All samples must be added to this
              // array to be shown.
              _createSampleDelegates = new Func<Sample>[]
              {
            () => new BindPoseSample(this),
            () => new SkeletonManipulationSample(this),
            () => new DudeWalkingSample(this),
            () => new AttachmentSample(this),
            () => new CrossFadeSample(this),
            () => new StressTestSample(this),
            () => new CompressionSample(this),
            () => new MixingSample(this),
            () => new BoneJiggleSample(this),
            () => new SkeletonMappingSample(this),
            () => new LookAtIKSample(this),
            () => new JacobianTransposeIKSample(this),
            () => new CcdIKSample(this),
            () => new ClosedFormIKSample(this),
            () => new TwoJointIKSample(this),
            () => new CollisionDetectionOnlyRagdollSample(this),
            () => new KinematicRagdollSample(this),
            () => new PassiveRagdollSample(this),
            () => new ActiveRagdollSample(this),
              };

              // Start the first sample in the array.
              _activeSampleIndex = 0;
              _activeSample = _createSampleDelegates[0]();
              Components.Add(_activeSample);

              base.Initialize();
        }
示例#7
0
        protected override void Initialize()
        {
            // create all application services and add to main services container.
            _services = new ServiceContainer();
            ServiceLocator.SetLocatorProvider(() => _services);

            var vfsStorage = new VfsStorage();
            var pathStorage = new FileSystemStorage("data");
            var uiAssetsStorage = new ZipStorage(pathStorage, "UI_Assets.zip");
            vfsStorage.MountInfos.Add(new VfsMountInfo(uiAssetsStorage, null));

            // Register the virtual file system as a service.
            _services.Register(typeof(IStorage), null, vfsStorage);

            // The GraphicsDeviceManager needs to be registered in the service container.
            // (This is required by the XNA content managers.)
            _services.Register(typeof(IGraphicsDeviceService), null, _graphicsDeviceManager);
            _services.Register(typeof(GraphicsDeviceManager), null, _graphicsDeviceManager);

            var uiContentManager = new StorageContentManager(_services, uiAssetsStorage);
            _services.Register(typeof(ContentManager), "UIContent", uiContentManager);

            // ----- Initialize Services
            // Register the game class.
            _services.Register(typeof(Microsoft.Xna.Framework.Game), null, this);
            _services.Register(typeof(kbPCB), null, this);

            // Input
            _inputManager = new InputManager(false);
            _services.Register(typeof(IInputService), null, _inputManager);

            // Graphics
            _graphicsManager = new GraphicsManager(GraphicsDevice, Window, uiContentManager);
            _services.Register(typeof(IGraphicsService), null, _graphicsManager);

            // GUI
            _uiManager = new UIManager(this, _inputManager);
            _services.Register(typeof(IUIService), null, _uiManager);

            // Animation
            _animationManager = new AnimationManager();
            _services.Register(typeof(IAnimationService), null, _animationManager);

            // Game logic
            _gameObjectManager = new GameObjectManager();
            _services.Register(typeof(IGameObjectService), null, _gameObjectManager);

            // Profiler
            _profiler = new HierarchicalProfiler("Main");
            _services.Register(typeof(HierarchicalProfiler), "Main", _profiler);

            // add more stuff here
            var editor2D = new Editor2D(this);
            Components.Add(editor2D);

            base.Initialize();
        }
示例#8
0
    // Initializes services and adds game components.
    protected override void Initialize()
    {
#if WINDOWS || WINDOWS_UWP || XBOX
      if (GraphicsDevice.GraphicsProfile == GraphicsProfile.Reach)
      {
        throw new NotSupportedException(
          "The DigitalRune Samples and Content for Windows, Universal Windows Apps and Xbox 360 are " +
          "designed for the HiDef graphics profile. A graphics cards supporting DirectX 10.0 or better " +
          "is required.");
      }
#endif

      // ----- Service Container
      // The DigitalRune ServiceContainer is an "inversion of control" container.
      // All game services (such as input, graphics, physics, etc.) are registered
      // in this container. Other game components can access these services via lookup
      // in the service container.
      // The DigitalRune ServiceContainer replaces the XNA GameServiceContainer (see 
      // property Game.Services).

      // Note: The DigitalRune libraries do not require the use of the ServiceContainer
      // or any other IoC container. The ServiceContainer is only used in the sample
      // for convenience - but it is not mandatory.
      _services = new ServiceContainer();

      // The service container is either passed directly to the game components
      // or accessed through the global variable ServiceLocator.Current.
      // The following call makes the service container publicly available in 
      // ServiceLocator.Current.
      ServiceLocator.SetLocatorProvider(() => _services);

      // ----- Storage
      // For XNA the assets are stored in the following folders:
      //
      //   <gameLocation>/
      //     Content/
      //       DigitalRune/
      //         ... DigitalRune assets ...
      //       ... other assets ...
      //
      // For MonoGame the assets (*.xnb files) are stored in ZIP packages. The
      // sample assets are stored in "Content/Content.zip" and the DigitalRune
      // assets are stored in "Content/DigitalRune.zip".
      //
      //   <gameLocation>/
      //     Content/
      //       Content.zip
      //       DigitalRune.zip
      //
      // DigitalRune introduces the concept of "storages". Storages can be used
      // to access files on disk or files stored in packages (e.g. ZIP archives).
      // These storages can be mapped into a "virtual file system", which makes
      // it easier to write portable code. (The game logic can read the files
      // from the virtual file system and does not need to know the specifics
      // about the platform.)
      //
      // The virtual files system should look like this:
      //
      //   /                                     <-- root of virtual file system
      //       DigitalRune/
      //           ... DigitalRune assets ...
      //       ... other assets ...

      // The VfsStorage creates a virtual file system.
      var vfsStorage = new VfsStorage();

      // The TitleStorage reads files from the game's default storage location.
      // --> Create a TitleStorage that reads files from "<gameLocation>/Content".
      var titleStorage = new TitleStorage("Content");

#if MONOGAME
      // A ZipStorage can be used to access files inside a ZIP archive.
      // --> Mount the sample assets to the root of the virtual file system.
      var assetsStorage = new ZipStorage(titleStorage, "Content.zip");
      vfsStorage.MountInfos.Add(new VfsMountInfo(assetsStorage, null));

#if !ANDROID && !IOS && !LINUX && !MACOS
      // --> Mount the DigitalRune assets to the root of the virtual file system.
      var drStorage = new ZipStorage(titleStorage, "DigitalRune.zip");
      vfsStorage.MountInfos.Add(new VfsMountInfo(drStorage, null));
#endif
#endif

      // Finally, map the TitleStorage to the root of the virtual file system.
      // (The TitleStorage is added as the last mount point. The ZIP archives
      // have priority.)
      vfsStorage.MountInfos.Add(new VfsMountInfo(titleStorage, null));

      // Register the virtual file system as a service.
      _services.Register(typeof(IStorage), null, vfsStorage);

      // ----- Content Managers
      // The GraphicsDeviceManager needs to be registered in the service container.
      // (This is required by the XNA content managers.)
      _services.Register(typeof(IGraphicsDeviceService), null, _graphicsDeviceManager);
      _services.Register(typeof(GraphicsDeviceManager), null, _graphicsDeviceManager);

      // Register a default, shared content manager.
      // The new StorageContentManager can be used to read assets from the virtual
      // file system. (Replaces the content manager stored in Game.Content.)
      Content = new StorageContentManager(_services, vfsStorage);
      _services.Register(typeof(ContentManager), null, Content);

      // Create and register content manager that will be used to load the GUI.
#if !MONOGAME
      var uiContentManager = new ContentManager(_services, "Content");
#else
      var uiContentManager = new StorageContentManager(_services, assetsStorage);
#endif
      _services.Register(typeof(ContentManager), "UIContent", uiContentManager);

      // Create content manager that will be used exclusively by the graphics service
      // to load the pre-built effects and resources of DigitalRune.Graphics. (We
      // could use Game.Content, but it is recommended to separate the content. This 
      // allows to unload the content of the samples without unloading the other 
      // content.)
      var graphicsContentManager = new StorageContentManager(_services, vfsStorage);

      // ----- Initialize Services
      // Register the game class.
      _services.Register(typeof(Microsoft.Xna.Framework.Game), null, this);
      _services.Register(typeof(SampleGame), null, this);

#if XBOX
      // On Xbox, we use the XNA gamer services (e.g. for text input).
      Components.Add(new GamerServicesComponent(this));
#endif

      // Input
#if XBOX
      const bool useGamerServices = true;
#else
      const bool useGamerServices = false;
#endif
      _inputManager = new InputManager(useGamerServices);
      _services.Register(typeof(IInputService), null, _inputManager);

      // Graphics
      _graphicsManager = new GraphicsManager(GraphicsDevice, Window, graphicsContentManager);
      _services.Register(typeof(IGraphicsService), null, _graphicsManager);

      // GUI
      _uiManager = new UIManager(this, _inputManager);
      _services.Register(typeof(IUIService), null, _uiManager);

      // Animation
      _animationManager = new AnimationManager();
      _services.Register(typeof(IAnimationService), null, _animationManager);

      // Particle simulation
      _particleSystemManager = new ParticleSystemManager();
      _services.Register(typeof(IParticleSystemService), null, _particleSystemManager);

      // Physics simulation
      ResetPhysicsSimulation();

      // Game logic
      _gameObjectManager = new GameObjectManager();
      _services.Register(typeof(IGameObjectService), null, _gameObjectManager);

      // Profiler
      _profiler = new HierarchicalProfiler("Main");
      _services.Register(typeof(HierarchicalProfiler), "Main", _profiler);

      // Initialize delegates for running tasks in parallel.
      // (Creating delegates allocates memory, therefore we do this only once and
      // cache the delegates.)
      _updateAnimation = () => _animationManager.Update(_deltaTime);
      _updatePhysics = () => _simulation.Update(_deltaTime);
      _updateParticles = () => _particleSystemManager.Update(_deltaTime);

      // SampleFramework
      // The SampleFramework automatically discovers all samples using reflection, provides 
      // controls for switching samples and starts the initial sample.
#if KINECT
      var initialSample = typeof(Kinect.KinectSkeletonMappingSample);
#elif WINDOWS || WINDOWS_UWP
      var initialSample = typeof(Graphics.DeferredLightingSample);
#else
      var initialSample = typeof(Graphics.BasicEffectSample);
#endif
      _sampleFramework = new SampleFramework(this, initialSample);
      _services.Register(typeof(SampleFramework), null, _sampleFramework);

      base.Initialize();
    }
示例#9
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            // The services are stored in Game.Services to make them accessible by all
            // game components.

            _spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), _spriteBatch);

            Services.AddService(typeof(ContentManager), Content);

            // Add the input service, which manages device input, button presses, etc.
            _inputManager = new InputManager(false);
            Services.AddService(typeof(IInputService), _inputManager);

            // Add the UI service, which manages UI screens.
            _uiManager = new UIManager(this, _inputManager);
            Services.AddService(typeof(IUIService), _uiManager);

            // Add the animation service.
            _animationManager = new AnimationManager();
            Services.AddService(typeof(IAnimationService), _animationManager);

            _consoleManager = new ConsoleManager();
            Services.AddService(typeof(ConsoleManager), _consoleManager);

            _contentController = new ContentController(GraphicsDevice, Content);
            _contentController.LoadContent();
            Services.AddService(typeof(ContentController), _contentController);

            _gameContentManager = new GameContentManager(Services);
            _gameContentManager.LoadGameContent();
            Services.AddService(typeof(GameContentManager), _gameContentManager);

            _galaxyManager = new GalaxyManager(Services);
            Services.AddService(typeof(GalaxyManager), _galaxyManager);

            _gameManager = new GameManager(Services);
            _gameManager.NewGame();
            Services.AddService(typeof(GameManager), _gameManager);

            _eventManager = new EventManager();
            Services.AddService(typeof(EventManager), _eventManager);

            // ----- Add GameComponents
            // The component that shows the individual screen.
            Components.Add(new CentauriGame(this));

            base.Initialize();
        }