public bool DetectCollision(GameStagePlay stage) { if (this.Status == SaucerStatus.Active) { Missile missile = stage.Missile; if (missile.IsActive && missile.YCenter >= this.YCenter && missile.YCenter <= this.YCenter + 1 && missile.XCenter >= this.XCenter - 1 && missile.XCenter <= this.XCenter + 2) { //got it! this.Status = SaucerStatus.StartExplosion; missile.IsActive = false; //decide score, then accumulate it this.PromisedScore = 10 * (1 + stage.Context.Rnd.Next(9)); stage.Context.CurrentScore += this.PromisedScore; return(true); } } return(false); }
public bool DetectCollision(GameStagePlay stage) { int xoffs, yoffs; //check missile collision Missile missile = stage.Missile; if (missile.IsActive && (xoffs = (missile.XCenter - this.XLeft)) >= 0 && xoffs < BarrierWidth && (yoffs = (missile.YCenter - this.YTop)) >= 0 && yoffs < BarrierHeight) { int mask = 1 << (yoffs * BarrierWidth + xoffs); if ((this.BricksAlive & mask) != 0) { //got it! this.ExplodeBricksAroundPoint(xoffs, yoffs); this.ExplodeBricksAroundPoint(xoffs - 1, yoffs); this.ExplodeBricksAroundPoint(xoffs + 1, yoffs); this.ExplodeBricksAroundPoint(xoffs, yoffs - 1); this.ExplodeBricksAroundPoint(xoffs, yoffs + 1); missile.IsActive = false; return(true); } } //check bombs collision for (int i = stage.Bombs.Length - 1; i >= 0; i--) { Bomb bomb; if ((bomb = stage.Bombs[i]).IsActive && (xoffs = (bomb.XCenter - this.XLeft)) >= 0 && xoffs < BarrierWidth && (yoffs = (bomb.YCenter - this.YTop)) >= 0 && yoffs < BarrierHeight) { int mask = 1 << (yoffs * BarrierWidth + xoffs); if ((this.BricksAlive & mask) != 0) { //got it! this.ExplodeBricksAroundPoint(xoffs, yoffs); this.ExplodeBricksAroundPoint(xoffs - 1, yoffs); this.ExplodeBricksAroundPoint(xoffs + 1, yoffs); this.ExplodeBricksAroundPoint(xoffs, yoffs - 1); this.ExplodeBricksAroundPoint(xoffs, yoffs + 1); bomb.IsActive = false; return(true); } } } return(false); }
public void Update(GameStagePlay stage) { if (this.IsActive) { this.YCenter--; if (YCenter < 0) { //failed this.IsActive = false; } } }
public void Update(GameStagePlay stage) { if (this.IsActive && stage.Context.IsEvenClock) { this.YCenter++; if (YCenter > stage.ViewportBottom) { //failed this.IsActive = false; } } }
public override bool DetectCollision(GameStagePlay stage) { if (this.IsAlive) { Missile missile = stage.Missile; if (missile.IsActive) { switch (this.Status) { case AlienStatus.Walk1: if (missile.YCenter <= this.YCenter && missile.YCenter >= this.YCenter - 1 && missile.XCenter >= this.XCenter - 1 && missile.XCenter <= this.XCenter + 1) { //got it! this.IsAlive = false; this.Status = AlienStatus.StartExplosion; missile.IsActive = false; stage.Context.CurrentScore += Score; return(true); } break; case AlienStatus.Walk2: if (missile.YCenter <= this.YCenter && missile.YCenter >= this.YCenter - 1 && missile.XCenter == this.XCenter) { //got it! this.IsAlive = false; this.Status = AlienStatus.StartExplosion; missile.IsActive = false; stage.Context.CurrentScore += Score; return(true); } break; } } } return(false); }
public bool DetectCollision(GameStagePlay stage) { if (this.IsAlive) { foreach (Bomb bomb in stage.Bombs) { if (bomb.IsActive && bomb.YCenter <= this.YCenter && bomb.YCenter >= this.YCenter - 1 && bomb.XCenter >= this.XCenter - 1 && bomb.XCenter <= this.XCenter + 1) { //got it! this.IsAlive = false; this.Status = ShipStatus.StartExplosion; bomb.IsActive = false; return(true); } } } return(false); }
public override bool DetectCollision(GameStagePlay stage) { if (this.IsAlive) { Missile missile = stage.Missile; if (missile.IsActive && missile.YCenter <= this.YCenter && missile.YCenter >= this.YCenter - 1 && missile.XCenter >= this.XCenter - 1 && missile.XCenter <= this.XCenter + 2) { //got it! this.IsAlive = false; this.Status = AlienStatus.StartExplosion; missile.IsActive = false; stage.Context.CurrentScore += Score; return true; } } return false; }
public void Update(GameStagePlay stage) { switch (this.Status) { case SaucerStatus.Inactive: double hash; if ((hash = stage.Context.Rnd.NextDouble()) < Probability) { if (hash < Probability / 2) { //will flight from left to right this.XCenter = -8; this._xLimit = stage.ViewportRight + 4; } else { //will flight from right to left this.XCenter = stage.ViewportRight + 4; this._xLimit = -8; } this.Status = SaucerStatus.Active; } break; case SaucerStatus.Active: if (stage.Context.IsEvenClock) { if (this.XCenter < this._xLimit) { this.XCenter++; } else { this.XCenter--; } if (this.XCenter == this._xLimit) { //sauce gone off screen being not hit this.Status = SaucerStatus.Inactive; } else { //play releated sound stage.Context.PlaySound(stage.Context.SoundSaucer); } } break; case SaucerStatus.StartExplosion: this.Status = SaucerStatus.ExplodeExpand; this._explosionClock = ExplosionTime; //play related sound stage.Context.PlaySound(stage.Context.SoundShipDestroyed); break; case SaucerStatus.ExplodeExpand: if (--this._explosionClock == 0) { this.Status = SaucerStatus.ExplodeMax; this._explosionClock = ExplosionTime; } break; case SaucerStatus.ExplodeMax: if (--this._explosionClock == 0) { this.Status = SaucerStatus.ExplodeCollapse; this._explosionClock = ExplosionTime; } break; case SaucerStatus.ExplodeCollapse: if (--this._explosionClock == 0) { this.Status = SaucerStatus.Inactive; stage.ShowSaucerWorth(); } break; } }
public void Update(GameStagePlay stage) { if (this.IsAlive) { //time to move aliens? if (stage.ShiftAliens) { //manage position switch (stage.CurrentAlienDir) { case AlienDirection.Rightward: this.XCenter++; if (this.XCenter == (stage.ViewportRight - 2)) { stage.NextAlienDir = AlienDirection.RightEdge; } break; case AlienDirection.RightEdge: this.YCenter++; stage.NextAlienDir = (this.YCenter == stage.ViewportBottom) ? AlienDirection.GroundReached : AlienDirection.Leftward; break; case AlienDirection.Leftward: this.XCenter--; if (this.XCenter == 1) { stage.NextAlienDir = AlienDirection.LeftEdge; } break; case AlienDirection.LeftEdge: this.YCenter++; stage.NextAlienDir = (this.YCenter == stage.ViewportBottom) ? AlienDirection.GroundReached : AlienDirection.Rightward; break; } //update status this.Status = this.Status == AlienStatus.Walk1 ? AlienStatus.Walk2 : AlienStatus.Walk1; //may drop a bomb? if (this.AlienBelow == null || this.AlienBelow.Status == AlienStatus.Dead) { //consider dropping one Bomb bomb; if (stage.Context.Rnd.NextDouble() > 0.8 && (bomb = stage.GetBombSlot()) != null) { //drop it! bomb.XCenter = this.XCenter; bomb.YCenter = this.YCenter; bomb.IsActive = true; } } } } else if (this.Status != AlienStatus.Dead) { switch (this.Status) { case AlienStatus.StartExplosion: this.Status = AlienStatus.ExplodeExpand; this._explosionClock = ExplosionTime; //play related sound stage.Context.PlaySound(stage.Context.SoundAlienDestroyed); break; case AlienStatus.ExplodeExpand: if (--this._explosionClock == 0) { this.Status = AlienStatus.ExplodeMax; this._explosionClock = ExplosionTime; } break; case AlienStatus.ExplodeMax: if (--this._explosionClock == 0) { this.Status = AlienStatus.ExplodeCollapse; this._explosionClock = ExplosionTime; } break; case AlienStatus.ExplodeCollapse: if (--this._explosionClock == 0) { stage.DecreaseAliens(); this.Status = AlienStatus.Dead; } break; } } }
public abstract bool DetectCollision(GameStagePlay stage);
public void Update(GameStagePlay stage) { var context = stage.Context; if (this.IsAlive) { if (context.IsEvenClock) { if (context.LeftButton) { if (this.XCenter > 1) { this.XCenter--; } } else if (context.RightButton) { if (this.XCenter < (stage.ViewportRight - 1)) { this.XCenter++; } } else if (context.FireButton) { //check missile availability if (stage.Missile.IsActive == false) { //fire it! stage.Missile.XCenter = this.XCenter; stage.Missile.YCenter = this.YCenter - 1; stage.Missile.IsActive = true; } } } } else if (this.Status != ShipStatus.Dead) { switch (this.Status) { case ShipStatus.StartExplosion: this.Status = ShipStatus.ExplodeExpand; this._explosionClock = ExplosionTime; //play related sound context.PlaySound(context.SoundShipDestroyed); break; case ShipStatus.ExplodeExpand: if (--this._explosionClock == 0) { this.Status = ShipStatus.ExplodeMax; this._explosionClock = ExplosionTime; } break; case ShipStatus.ExplodeMax: if (--this._explosionClock == 0) { this.Status = ShipStatus.ExplodeCollapse; this._explosionClock = ExplosionTime; } break; case ShipStatus.ExplodeCollapse: if (--this._explosionClock == 0) { this.IsAlive = stage.DecreaseShips(); this.Status = this.IsAlive ? ShipStatus.Alive : ShipStatus.Dead; } break; } } }
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); }