public Breakout(IGameLoop gameLoop, IGraphics graphics, IAudio audio, IKeyboard keyboard, IFileSystem fileSystem) : base(nameof(Breakout), gameLoop, graphics, audio, keyboard, null, fileSystem) { Keyboard = new StatefulKeyboard(keyboard); // the state machine we'll be using to transition between various states // in our game instead of clumping them together in our update and draw // methods // // our current game state can be any of the following: // 1. 'start' (the beginning of the game, where we're told to press Enter) // 2. 'paddle-select' (where we get to choose the color of our paddle) // 3. 'serve' (waiting on a key press to serve the ball) // 4. 'play' (the ball is in play, bouncing between paddles) // 5. 'victory' (the current level is over, with a victory jingle) // 6. 'game-over' (the player has lost; display score and allow restart) StateMachine = new StateMachine(new Dictionary <string, State> { ["start"] = new StartState(), ["play"] = new PlayState(), ["serve"] = new ServeState(), ["game-over"] = new GameOverState(), ["victory"] = new VictoryState(), ["high-scores"] = new HighScoreState(), ["enter-high-score"] = new EnterHighScoreState(), ["paddle-select"] = new PaddleSelectState(), }); Instance = this; }
public void StartGame(IGameLoop gameLoop, IGame game) { do { string key; do { Console.WriteLine("1. New game"); Console.WriteLine("2. Quit"); key = Console.ReadLine(); Console.Clear(); } while (key != "1" && key != "2"); switch (key) { case "1": game.Initialize(); gameLoop.Run(game); break; case "2": Environment.Exit(0); break; } Console.Clear(); } while (true); }
public Game CreateGame(string gameName, IGameLoop gameLoop, IGraphics graphics, IAudio audio, IKeyboard keyboard, IMouse mouse, IFileSystem fileSystem) { var gameType = typeof(Game); var game = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(assembly => assembly.GetTypes()) .SingleOrDefault(type => type.Name == gameName && type.IsSubclassOf(gameType) && !type.IsAbstract); var constructors = game.GetConstructors(); var constructor = constructors.FirstOrDefault(); var parameters = constructor.GetParameters(); var arguments = new List <object>(); arguments.Add(gameLoop); arguments.Add(graphics); arguments.Add(audio); arguments.Add(keyboard); if (parameters.Any(p => p.Name == nameof(mouse))) { arguments.Add(mouse); } if (parameters.Any(p => p.Name == nameof(fileSystem))) { arguments.Add(fileSystem); } var gameInstance = (Game)Activator.CreateInstance(game, arguments.ToArray()); return(gameInstance); }
protected ActorCommandBase(IGameLoop gameLoop, ISectorManager sectorManager, ISectorUiState playerState) : base(gameLoop) { SectorManager = sectorManager; PlayerState = playerState; }
public MoveCommand(IGameLoop gameLoop, ISectorManager sectorManager, IPlayerState playerState) : base(gameLoop, sectorManager, playerState) { _path = new List <IMapNode>(); }
/// <inheritdoc /> public void MainLoop() { if (_mainLoop == null) { _mainLoop = new GameLoop(_time) { SleepMode = SleepMode.Delay, DetectSoftLock = true }; } _uptimeStopwatch.Start(); _mainLoop.Tick += (sender, args) => Update(args); _mainLoop.Update += (sender, args) => { ServerUpTime.Set(_uptimeStopwatch.Elapsed.TotalSeconds); }; // set GameLoop.Running to false to return from this function. _mainLoop.Run(); _time.InSimulation = true; Cleanup(); _shutdownEvent.Set(); }
public void OnHostClick() { if (m_GameLoop == null) { m_GameLoop = new ServerLoop(); } m_GameLoop.Start(); }
public static T GetPresenter <T>(this IGameLoop gameLoop) where T : IPresenter { // HACK. 面倒なので全オブジェクト拾ってきてinterfaceを対象に初期化していく. return(Object.FindObjectsOfType <GameObject>() .First(_ => _.GetComponent <T>() != null) .GetComponent <T>()); }
public void OnLogin() { if (m_GameLoop == null) { m_GameLoop = new ClientLoop(); } m_GameLoop.Start(); }
public NextTurnCommand(IGameLoop gameLoop, ISectorManager sectorManager, IPlayerState playerState, IDecisionSource decisionSource) : base(gameLoop, sectorManager, playerState) { _decisionSource = decisionSource; }
public UseSelfCommand(IGameLoop gameLoop, ISectorManager sectorManager, IPlayerState playerState, IInventoryState inventoryState) : base(gameLoop, sectorManager, playerState) { _inventoryState = inventoryState; }
public AttackCommand(IGameLoop gameLoop, ISectorManager sectorManager, ISectorUiState playerState, ITacticalActUsageService tacticalActUsageService) : base(gameLoop, sectorManager, playerState) { _tacticalActUsageService = tacticalActUsageService; }
public EquipCommand(IGameLoop gameLoop, ISectorManager sectorManager, ISectorUiState playerState, IInventoryState inventoryState) : base(gameLoop, sectorManager, playerState) { _inventoryState = inventoryState; }
public CockpitPanel(IGameLoop loop) { _loop = loop; _loop.RegisterHandler(LoopUpdate); var container = Resolver.Bootstrap(); FuelSystem = container.Resolve <IFuelSystem>(); Alarms = container.Resolve <IAlarms>(); }
protected GameBase(Options options, IGamePlatformFactory gamePlatformFactory, IGraphicsFactory graphicsFactory, IInputFactory inputFactory) { _options = options; _gamePlatformFactory = gamePlatformFactory; GraphicsFactory = graphicsFactory; _inputFactory = inputFactory; _inputMapper = new InputMapper(_inputFactory); _gameLoop = _gamePlatformFactory.CreateGameLoop(); }
public async void SetLoop(GameLoopType type) { _currentLoop?.LoopOut(); _isUpdatable = false; _currentLoop = _gameLoops[(int)type]; await _currentLoop.LoopIn(); _isUpdatable = true; }
public MoveCommand(IGameLoop gameLoop, ISectorManager sectorManager, ISectorUiState playerState, IActorManager actorManager) : base(gameLoop, sectorManager, playerState) { _actorManager = actorManager; Path = new List <IMapNode>(); }
public Engine( Configuration configuration, IAudioBackend audioBackend, IInputBackend inputBackend, IRenderingBackend renderingBackend, IGame game) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (audioBackend == null) { throw new ArgumentNullException(nameof(audioBackend)); } if (inputBackend == null) { throw new ArgumentNullException(nameof(inputBackend)); } if (renderingBackend == null) { throw new ArgumentNullException(nameof(renderingBackend)); } if (game == null) { throw new ArgumentNullException(nameof(game)); } Log.Info("Initializing engine components."); var containerBuilder = new ContainerBuilder(); CommonModules.RegisterAll(containerBuilder); EngineModules.RegisterAll(containerBuilder); containerBuilder.RegisterInstance(configuration.Core).As <CoreConfiguration>().SingleInstance(); containerBuilder.RegisterInstance(configuration.Physics).As <PhysicsConfiguration>().SingleInstance(); containerBuilder.RegisterInstance(configuration.Rendering).As <RenderingConfiguration>().SingleInstance(); containerBuilder.RegisterInstance(audioBackend).As <IAudioBackend>().SingleInstance(); containerBuilder.RegisterInstance(inputBackend).As <IInputBackend>().SingleInstance(); containerBuilder.RegisterInstance(renderingBackend).As <IRenderingBackend>().SingleInstance(); var componentsRegistry = new ComponentsRegistry(containerBuilder); game.RegisterComponents(componentsRegistry); _container = containerBuilder.Build(); _lifetimeScope = _container.BeginLifetimeScope(); RunStartUpTasks(); _gameLoop = _lifetimeScope.Resolve <IGameLoop>(); _engineManager = _lifetimeScope.Resolve <IEngineManager>(); Log.Info("Engine components initialized."); }
public void PollEvents(IGameLoop gameLoop) { while (SDL.SDL_PollEvent(out var @event) != 0) { OnEvent(@event, gameLoop); if (@event.type == SDL.SDL_EventType.SDL_QUIT) { gameLoop.Stop(); } } }
public GameLoopManager( ILogger <GameLoopManager> logger, ISdl2 sdl, IGameLoop gameLoop) { _logger = logger; _sdl = sdl; _gameLoop = gameLoop; _thread = new Thread(RunGameLoopInBackground); _thread.Start(); }
protected Game(string gameName, IGameLoop gameLoop, IGraphics graphics, IAudio audio, IKeyboard keyboard, IMouse mouse = null, IFileSystem fileSystem = null) { GameName = gameName; this.gameLoop = gameLoop; Graphics = graphics; Audio = audio; Keyboard = keyboard; Mouse = mouse; FileSystem = fileSystem; Sounds = new Dictionary <string, ISource>(); Random = new Random(); Instance = this; }
/// <inheritdoc /> public void MainLoop() { if (_mainLoop == null) { _mainLoop = new GameLoop(_time) { SleepMode = SleepMode.Delay }; } _mainLoop.Tick += (sender, args) => Update(args.DeltaSeconds); // set GameLoop.Running to false to return from this function. _mainLoop.Run(); Cleanup(); }
public FiftyBird(IGameLoop gameLoop, IGraphics graphics, IAudio audio, IKeyboard keyboard, IMouse mouse) : base(nameof(FiftyBird), gameLoop, graphics, audio, keyboard, mouse) { Keyboard = new StatefulKeyboard(keyboard); Mouse = new StatefulMouse(mouse); // initialize state machine with all state - returning functions StateMachine = new StateMachine(new Dictionary <string, State> { ["title"] = new TitleScreenState(), ["countdown"] = new CountdownState(), ["play"] = new PlayState(), ["score"] = new ScoreState() }); Instance = this; }
public void MainLoop(DisplayMode mode) { if (_mainLoop == null) { _mainLoop = new GameLoop(_gameTiming) { SleepMode = mode == DisplayMode.Headless ? SleepMode.Delay : SleepMode.None }; } _mainLoop.Tick += (sender, args) => { if (_mainLoop.Running) { Tick(args); } }; _mainLoop.Render += (sender, args) => { if (_mainLoop.Running) { _gameTiming.CurFrame++; _clyde.Render(); } }; _mainLoop.Input += (sender, args) => { if (_mainLoop.Running) { Input(args); } }; _mainLoop.Update += (sender, args) => { if (_mainLoop.Running) { Update(args); } }; // set GameLoop.Running to false to return from this function. _mainLoop.Run(); Cleanup(); }
public void MainLoop(DisplayMode mode) { if (_mainLoop == null) { _mainLoop = new GameLoop(_gameTiming) { SleepMode = mode == DisplayMode.Headless ? SleepMode.Delay : SleepMode.None }; } _mainLoop.Tick += (sender, args) => { if (_mainLoop.Running) { Update(args.DeltaSeconds); } }; _mainLoop.Render += (sender, args) => { if (_mainLoop.Running) { _gameTiming.CurFrame++; _clyde.Render(new FrameEventArgs(args.DeltaSeconds)); } }; _mainLoop.Input += (sender, args) => { if (_mainLoop.Running) { _clyde.ProcessInput(new FrameEventArgs(args.DeltaSeconds)); } }; _mainLoop.Update += (sender, args) => { if (_mainLoop.Running) { _frameProcessMain(args.DeltaSeconds); } }; // set GameLoop.Running to false to return from this function. _mainLoop.Run(); }
public FuelSystem(IFuelMessaging msg, IGameLoop loop) { _msg = msg; loop.RegisterHandler(IntervalUpdate); LeftTank = new FuelTank(msg, loop) { Capacity = 12, Quantity = 12, Name = "Left" }; RightTank = new FuelTank(msg, loop) { Capacity = 12, Quantity = 12, Name = "Right" }; SelectedTank = Tank.Left; }
public void OnEvent(SDL.SDL_Event @event, IGameLoop gameLoop) { if ([email protected](SDL.SDL_EventType.SDL_KEYDOWN)) { return; } if (@event.key.keysym.sym.Equals(SDL.SDL_Keycode.SDLK_ESCAPE)) { Console.WriteLine("Escape pressed."); gameLoop.Stop(); } float?simulationSpeed = @event.key.keysym.sym switch { SDL.SDL_Keycode.SDLK_BACKQUOTE => 10.0f, SDL.SDL_Keycode.SDLK_1 => 1.0f, SDL.SDL_Keycode.SDLK_2 => 0.5f , SDL.SDL_Keycode.SDLK_3 => 0.25f, SDL.SDL_Keycode.SDLK_4 => 0.125f, SDL.SDL_Keycode.SDLK_5 => 0.01f , SDL.SDL_Keycode.SDLK_6 => 0.0f, _ => null }; if (simulationSpeed.HasValue) { Console.WriteLine($"Set simulation speed to {simulationSpeed.Value}"); gameLoop.SetSimulationSpeed(simulationSpeed.Value); } _cameraX += @event.key.keysym.sym switch { SDL.SDL_Keycode.SDLK_LEFT => 10, SDL.SDL_Keycode.SDLK_RIGHT => - 10, _ => 0 }; _cameraY += @event.key.keysym.sym switch { SDL.SDL_Keycode.SDLK_UP => 10, SDL.SDL_Keycode.SDLK_DOWN => - 10, _ => 0 }; _zoom += @event.key.keysym.sym switch { SDL.SDL_Keycode.SDLK_HOME => 0.25f, SDL.SDL_Keycode.SDLK_END => - 0.25f, _ => 0.0f }; _zoom = Math.Max(_zoom, 0.25f); }
/// <inheritdoc /> public void MainLoop() { if (_mainLoop == null) { _mainLoop = new GameLoop(_time) { SleepMode = SleepMode.Delay, DetectSoftLock = true }; } _mainLoop.Tick += (sender, args) => Update(args); // set GameLoop.Running to false to return from this function. _mainLoop.Run(); _time.InSimulation = true; Cleanup(); }
public RoomTransitionWorkflow(IRoomTransitions transitions, IWindowInfo window, IRendererLoop rendererLoop, Resolver resolver, IGameEvents events, IGameLoop loop, IAGSRenderPipeline pipeline, IGameSettings settings, IAGSGameState state, IDisplayList displayList, IGLUtils glUtils) { _glUtils = glUtils; _dummyWindow = new DummyWindow(); _transitions = transitions; _transitions.Transition = new RoomTransitionInstant(); _window = window; _rendererLoop = rendererLoop; _resolver = resolver; _events = events; _loop = loop; _pipeline = pipeline; _state = state; _displayList = displayList; _settings = settings; _noAspectRatioSettings = new AGSGameSettings(settings.Title, settings.VirtualResolution, preserveAspectRatio: false); state.OnRoomChangeRequired.SubscribeToAsync(onRoomChangeRequired); }
public void MainLoop(GameController.DisplayMode mode) { _mainLoop = new GameLoop(_gameTiming); _mainLoop.Tick += (sender, args) => { if (_mainLoop.Running) { ProcessUpdate(args); } }; _mainLoop.Render += (sender, args) => { if (_mainLoop.Running) { _gameTiming.CurFrame++; _clyde.Render(); } }; _mainLoop.Input += (sender, args) => { if (_mainLoop.Running) { _clyde.ProcessInput(args); } }; _mainLoop.Update += (sender, args) => { if (_mainLoop.Running) { RenderFrameProcess(args); } }; _mainLoop.Run(); }