public void Tick() { if (Engine == null) { return; } if (_commands.Count > 0) { _logger.Info("Executing tick with {0} commands.", _commands.Count); } var input = new EngineTickInput(_commands); _commands.Clear(); var tick = Engine.Tick(input); tick.Start(); tick.Wait(); Engine.Synchronize(); foreach (var resultEvent in tick.Result.Events) { EngineEvent?.Invoke(this, new GameEngineEventArgs(resultEvent, Engine)); } }
// method public void Accelerate(int delta) { CurrentSpeed += delta; if (IsEngineDead) { EngineEvent?.Invoke(this, new EngineEventArgs("Engine is dead...")); } else { if (CurrentSpeed > MaxSpeed) { IsEngineDead = true; EngineEvent?.Invoke(this, new EngineEventArgs("Engine is dead...")); } else if (20 >= Math.Abs(MaxSpeed - CurrentSpeed)) { EngineEvent?.Invoke(this, new EngineEventArgs($"be careful bro! CurrentSpeed: {CurrentSpeed}.")); } else { EngineEvent?.Invoke(this, new EngineEventArgs($"faster is better! CurrentSpeed: {CurrentSpeed}.")); } } }
public void PollEvent() { while (SDL_PollEvent(out SDL_Event e) != 0) { switch (e.type) { case SDL_EventType.SDL_WINDOWEVENT: switch (e.window.windowEvent) { case SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE: WindowEvent?.Invoke(new InputCallbackEventArg() { CallbackType = InputCallbackType.WindowClose }); break; case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: WindowEvent?.Invoke(new InputCallbackEventArg() { CallbackType = InputCallbackType.FocusGained }); break; case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: WindowEvent?.Invoke(new InputCallbackEventArg() { CallbackType = InputCallbackType.FocusLost }); break; case SDL_WindowEventID.SDL_WINDOWEVENT_EXPOSED: WindowEvent?.Invoke(new InputCallbackEventArg() { CallbackType = InputCallbackType.WindowExposed }); break; case SDL_WindowEventID.SDL_WINDOWEVENT_SHOWN: WindowEvent?.Invoke(new InputCallbackEventArg() { CallbackType = InputCallbackType.WindowShown }); break; } break; case SDL_EventType.SDL_KEYDOWN: if (_keys.ContainsKey(e.key.keysym.sym)) { _keys[e.key.keysym.sym] = true; } else { _keys.Add(e.key.keysym.sym, true); } break; case SDL_EventType.SDL_KEYUP: if (_keys.ContainsKey(e.key.keysym.sym)) { _keys[e.key.keysym.sym] = false; } else { _keys.Add(e.key.keysym.sym, false); } break; case SDL_EventType.SDL_MOUSEBUTTONDOWN: switch (e.button.button) { case (byte)SDL_BUTTON_LEFT: _leftMB = true; break; case (byte)SDL_BUTTON_RIGHT: _rightMB = true; break; case (byte)SDL_BUTTON_MIDDLE: _middleMB = true; break; } break; case SDL_EventType.SDL_MOUSEBUTTONUP: switch (e.button.button) { case (byte)SDL_BUTTON_LEFT: _leftMB = false; break; case (byte)SDL_BUTTON_RIGHT: _rightMB = false; break; case (byte)SDL_BUTTON_MIDDLE: _middleMB = false; break; } break; case SDL_EventType.SDL_RENDER_DEVICE_RESET: EngineEvent?.Invoke(new InputCallbackEventArg() { CallbackType = InputCallbackType.RenderDeviceReset }); break; } } }