void bw_DoWork(object sender, DoWorkEventArgs e) { int lastElapsed = frameDelay; while (isRunning) { long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; delta = elapsedMilliseconds / 1000.0; stopwatch.Reset(); stopwatch.Start(); InputContainer.getInstance().Execute(); MoveContainer.getInstance().Move(delta); CollisionContainer.getInstance().CheckCollision(); bw.ReportProgress(1); int elapsed = (int)Math.Ceiling((decimal)elapsedMilliseconds); //The time the thread sleeps should be less if the tick took longer to run int sleepTime = Math.Min(frameDelay, frameDelay - (lastElapsed - frameDelay)); //Can't wait less then 0 time if (sleepTime < 0) { sleepTime = 0; } lastElapsed = elapsed; Thread.Sleep(sleepTime); } }
public void start() { game.currentRound = this; new TimedTextDisplay(270, 150, name, Colors.Yellow, 30, 3); passedTime = 0; state = game.stateFactory.create("round-notactive"); MoveContainer.getInstance().Add(this); }
public void die(Unit unit) { MoveContainer.getInstance().Remove(unit); CollisionContainer.getInstance().Remove(unit); DrawContainer.getInstance().Remove(unit); UnitContainer.getInstance().Remove(unit); unit._currentRound.removeUnit(unit); }
public void subscribe() //Singleton anti-pattern :( { state = UnitStateFactory.Instance.create("unit-alive"); DrawContainer.getInstance().Add(this); MoveContainer.getInstance().Add(this); CollisionContainer.getInstance().Add(this); UnitContainer.getInstance().Add(this); _currentRound.registerUnit(this); }
internal void Visit(TimedTextDisplay timedTextDisplay, double delta) { timedTextDisplay.eleapsedTime += delta; if (timedTextDisplay.eleapsedTime >= timedTextDisplay.maxTime) { DrawContainer.getInstance().Remove(timedTextDisplay); MoveContainer.getInstance().Remove(timedTextDisplay); } }
public TimedTextDisplay(int x, int y, String text, Color c, int size, int seconds) : base(x, y, text, c, size) { eleapsedTime = 0; maxTime = seconds; MoveContainer.getInstance().Add(this); }