Esempio n. 1
0
        internal GameEngine(IUniverse universe, IGravitySimulator gravitySimulator, IGameObjectFactory gameObjectFactory, IKeyboardHandler keyboardHandler, IActionHandler actionHandler, IDrawingManager drawingManager)
        {
            _universe = universe;
            _drawingManager = drawingManager;
            _gravitySimulator = gravitySimulator;

            _gameObjectFactory = gameObjectFactory;

            _keyboardHandler = keyboardHandler;
            _actionHandler = actionHandler;
            _controllerFactory = new ControllerFactory(_keyboardHandler);
            actionHandler.RegisterTriggerAction(Keys.Space, () => _paused = !_paused);
        }
Esempio n. 2
0
        //TODO Could set these actions based on key bindings loaded from a file.
        //Could also be moved into GameEngine or Somewhere else (ActionHandler? BindingsConfigurator?)
        private void SetUpActions(IActionHandler actionHandler)
        {
            actionHandler.RegisterTriggerAction(Keys.Escape, _gameEngine.ResetGame);

            actionHandler.RegisterTriggerAction(Keys.X, () =>
            {
                var ship = _gameObjectFactory.GameObjects.OfType<Ship>().SingleOrDefault(x => x.Name == "ship 1");
                if (ship != null)
                {
                    ship.Damage(10f);
                }
            });

            actionHandler.RegisterContinuousAction(Keys.T, () => _drawingManager.MoveCamera(Vector3.Forward));
            actionHandler.RegisterContinuousAction(Keys.Y, () => _drawingManager.MoveCamera(Vector3.Up));
            actionHandler.RegisterContinuousAction(Keys.U, () => _drawingManager.ZoomCamera(-10));
            actionHandler.RegisterContinuousAction(Keys.J, () => _drawingManager.ZoomCamera(10));
            actionHandler.RegisterContinuousAction(Keys.I, () => _universe.Volume.Contract(10));
            actionHandler.RegisterContinuousAction(Keys.K, () => _universe.Volume.Expand(10));
        }