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 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; } }