/// <summary> /// A new instance of GameEngine. /// </summary> public GameEngine() { GameStates = new Stack<GameState>(); InputMgr = new InputManager(this); DeltaTime = new GameTime(); Window = new RenderWindow(new VideoMode(1280, 720), "Jeden"); }
public override void Update(GameTime gameTime) { if (CurrentHealth <= 0) { Parent.HandleMessage(new InvalidateMessage(this)); } if (CurrentHealth > MaxHealth) { CurrentHealth = MaxHealth; } }
/// <summary> /// Update all GameObjects attached to this GameState /// </summary> /// <param name="gameTime">The time difference to the last frame.</param> public virtual void Update(GameTime gameTime) { for(int i = 0; i < GameObjects.Count; i++) { GameObjects[i].Update(gameTime); } }
/// <summary> /// Updates the GameEngine. /// </summary> /// <param name="gameTime">The time difference to the last frame.</param> void Update(GameTime gameTime) { InputMgr.Update(this); GameStates.Peek().Update(gameTime); }
/// <summary> /// Runs the GameEngine. /// </summary> public void Run() { Stopwatch stopwatch = new Stopwatch(); Window.Closed += Window_Closed; stopwatch.Start(); double TotalTime = 0; GameTime step = new GameTime(); while (Window.IsOpen()) { Window.DispatchEvents(); DeltaTime.ElapsedGameTime = stopwatch.Elapsed - DeltaTime.TotalGameTime; DeltaTime.TotalGameTime = stopwatch.Elapsed; AccumulatedTime += DeltaTime.ElapsedGameTime.TotalSeconds; while (AccumulatedTime > TimeStep) { TotalTime += TimeStep; step.ElapsedGameTime = new TimeSpan((long)(TimeStep * TimeSpan.TicksPerSecond)); step.TotalGameTime = new TimeSpan((long)(TotalTime * TimeSpan.TicksPerSecond)); Update(step); Draw(); AccumulatedTime -= TimeStep; } } stopwatch.Stop(); }