public void Update() { //update the desired stage when requested if (this._nextStage != null) { this._currentStage = this._nextStage; this._currentStage.OnLoad(this._composition); } //wipes out the composition target this._composition.Clear(); //compose the graphic scene this._nextStage = this._currentStage.OnCompose(this._composition); //dumps the composition to the physical device this._renderer.Dump(this._composition); }
public override GameStageBase OnCompose(CompositionTargetBase target) { GameStageBase result = null; if (this._pausedClock == 0) { //here is the normal flow during the playable game this.ShiftAliens = (this.Context.Clock & this._clockMask) == 0; //update objects this.Ship.Update(this); this.Missile.Update(this); this.Saucer.Update(this); for (int i = 0; i < AliensPerRow; i++) { this.SmallAliens[i].Update(this); this.LargeAliens[i].Update(this); } for (int i = 0; i < BombsCount; i++) { this.Bombs[i].Update(this); } //check collisions if (this.Ship.DetectCollision(this)) { } if (this.Saucer.DetectCollision(this)) { } for (int i = 0; i < AliensPerRow; i++) { if (this.SmallAliens[i].DetectCollision(this)) { break; } if (this.LargeAliens[i].DetectCollision(this)) { break; } } for (int i = 0; i < BarriersCount; i++) { if (this.Barriers[i].DetectCollision(this)) { break; } } //update context for next frame this.CurrentAlienDir = this.NextAlienDir; if (this.CurrentAlienDir == AlienDirection.GroundReached) { //aliens grounded: the game is over! this._pausedClock = PausedTimeLong; this._pauseStage = PauseStage.GameOver; } } //this happens when some event has paused the game else if (--this._pausedClock == 0) { //finalize the paused stage switch (this._pauseStage) { case PauseStage.ShipsLeft: //resume the game where was broken this.ResumeLevel(); break; case PauseStage.GameOver: //back to the intro stage result = new GameStageIntro(this.Context); this.Context.Status = GameStatus.Registering; break; } this._pauseStage = PauseStage.None; } //render the renderables for (int i = 0; i < RenderableCount; i++) { this._renderables[i].OnRender(target); } //when paused, compose the required stage if (this._pauseStage != PauseStage.None) { this._pauseStageHandlers[(int)this._pauseStage](target); } return(result); }
public override GameStageBase OnCompose(CompositionTargetBase target) { GameStageBase result = null; //the game begins on any button pressed if (this.Context.FireButton || this.Context.RightButton || this.Context.LeftButton) { if (this.Context.Status == GameStatus.Idle) { result = new GameStagePlay(this.Context); } } else if (this.Context.Status == GameStatus.RegComplete) { //this prevents the game to begin when //a button is still pressed since a prev stage this.Context.Status = GameStatus.Idle; } bool flasher = (this.Context.Clock & 8) != 0; if (this._frame == 0) { this._posT0 = new Point(34, 4); this._posT1 = new Point(40, 4); this._posAlien = new Point(-25, 4); } if (this._frame < 24) { target.DrawString("O", AlienFont.Instance, Brushes.Lime, _posT0); target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1); _posT0.X--; _posT1.X--; } else if (this._frame < 24) { target.DrawString("O", AlienFont.Instance, Brushes.Lime, _posT0); target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1); } else if (this._frame < 24 + 8) { target.DrawString("O", AlienFont.Instance, Brushes.Lime, _posT0); target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1); _posT0.X++; _posT1.X++; } else if (this._frame < 32 + 34) { string alien = string.Empty + (char)(0x50 + (this._frame & 1)); target.DrawString(alien, AlienFont.Instance, Brushes.Yellow, _posAlien); target.DrawString("O", AlienFont.Instance, Brushes.Lime, _posT0); target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1); _posAlien.X++; } else if (this._frame < 66 + 34) { string alien = string.Empty + (char)(0x50 + (this._frame & 1)); target.DrawString(alien, AlienFont.Instance, Brushes.Yellow, _posAlien); target.DrawString("O", AlienFont.Instance, Brushes.Lime, _posT0); target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1); _posAlien.X--; _posT0.X--; } else if (this._frame < 100 + 34) { string alien = string.Empty + (char)(0x50 + (this._frame & 1)); target.DrawString(alien, AlienFont.Instance, Brushes.Yellow, _posAlien); target.DrawString("N", AlienFont.Instance, Brushes.Lime, _posT0); target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1); _posAlien.X++; _posT0.X++; } else if (this._frame < 134 + 100) { string alien = string.Empty + (char)(0x50 + (this._frame & 1)); target.DrawString(alien, AlienFont.Instance, Brushes.Yellow, _posAlien); target.DrawString("N", AlienFont.Instance, Brushes.Lime, _posT0); target.DrawString(Title1, Fonts.Fixed5x7, Brushes.Lime, _posT1); _posAlien.X--; _posT0.X--; _posT1.X--; } else if (this._frame < 234 + 60) { if (this._frame == 234) { this._posT0.X = 15; this._posT0.Y = 0; this._posT1.X = -15; this._posT1.Y = 8; } //alien #2 is wider and yields less points string alien2 = flasher ? "RS" : "TU"; target.DrawString(alien2, AlienFont.Instance, Brushes.Yellow, this._posT0); target.DrawString(AlienLarge.Score + "p", Fonts.Fixed5x7, Brushes.Lime, this._posT0.X + 12, this._posT0.Y); //alien #1 worth more string alien1 = flasher ? "P" : "Q"; target.DrawString(alien1, AlienFont.Instance, Brushes.Yellow, this._posT1.X + 19, this._posT1.Y); target.DrawString(AlienSmall.Score + "p", Fonts.Fixed5x7, Brushes.Lime, this._posT1.X, this._posT1.Y + 1); if (this.Context.IsEvenClock) { this._posT0.X--; this._posT1.X++; } } else if (this._frame < 294 + 80) { if (flasher) { target.DrawString("In ert", Fonts.Fixed5x7, Brushes.Lime, new Point(-1, 0)); target.DrawString("$", Fonts.Fixed5x7, Brushes.Red, new Point(11, 0)); target.DrawString("coin", Fonts.Fixed5x7, Brushes.Yellow, new Point(4, 9)); } } else { this._frame = -1; } this._frame++; return(result); }