public void OnCollision(Direction direction, SpriteCollection other, Rectangle intersection) { if (direction == Direction.TOP && other is SpriteMario) { SpriteMario mario = (SpriteMario)other; mario.Bounce(); mario.points += 100; this.game.pointGenerator.Add(200, this); this.LandOnKoopa(); } else if (other is SpriteMario) { SpriteMario mario = (SpriteMario)other; if (mario.StateMachinePowerup.CurrentState is StatePowerupStar) { if (!dead) { dead = true; this.Die(); } } else { mario.StateMachinePowerup.CurrentState.TakeDamage(); } } }
public void OnCollision(Direction direction, SpriteCollection other, Rectangle intersection) { if (other is SpriteMario) { SpriteMario mario = other as SpriteMario; SpriteLayer.CollisionLayer.RemoveSprite(this); mario.StateMachinePowerup.CurrentState.ReceiveFireFlower(); mario.points += 1000; this.game.pointGenerator.Add(1000, this); } }
public void OnCollision(Direction direction, SpriteCollection other, Rectangle intersection) { if (other is SpriteMario) { SpriteMario mario = other as SpriteMario; SpriteLayer.CollisionLayer.RemoveSprite(this); if (this.oneUp) { mario.lives++; SoundFactory.PlaySoundEffect(SoundFactory.OneUp()); } else { mario.StateMachinePowerup.CurrentState.ReceiveMushroom(); mario.points += 1000; this.game.pointGenerator.Add(1000, mario); } } }
public void OnCollision(Direction direction, SpriteCollection other, Rectangle intersection) { if (other is SpriteMario) { SpriteMario mario = other as SpriteMario; if (SpriteLayer.CollisionLayer.Sprites.Contains(this)) { mario.coins++; mario.points += 200; this.game.pointGenerator.Add(200, this); if (mario.coins / mario.nextLife == 100) { mario.lives++; mario.nextLife++; } SoundFactory.PlaySoundEffect(SoundFactory.Coin()); } SpriteLayer.CollisionLayer.RemoveSprite(this); } }
public void OnCollision(Direction direction, SpriteCollection other, Rectangle intersection) { if (this.SpriteState != SpriteStates.Sprites.DEAD) { if (other is SpriteMario) { if (other.SpriteState != SpriteStates.Sprites.DEAD) { if (direction == Direction.TOP) { Console.WriteLine("Goomba collided with Mario. Mario on TOP"); SpriteMario mario = (SpriteMario)other; if (mario.SpriteState != SpriteStates.Sprites.DEAD) { Console.WriteLine("Killing Goomba!"); this.GetStomped(); mario.Bounce(); mario.points += 100; this.game.pointGenerator.Add(100, this); } else { Console.WriteLine("[Err] Goomba collision on TOP by Mario, but Mario is dead."); } } else { SpriteMario mario = (SpriteMario)other; if (mario.StateMachinePowerup.CurrentState == mario.StateMachinePowerup.Star) { this.Die(); } else { mario.StateMachinePowerup.CurrentState.TakeDamage(); } //Reason for this is we get a bounce effect. //If we don't have a timer, the collision will happen repeatedly //and goomba will "stick" to mario if (dirChangeTimer < DateTime.Now.Ticks) { //if mario is not dead and they're both not traveling same direction. Goomba should //change directions upon collision. if (this.Info.velocity.X * mario.Info.velocity.X <= 0) { this.Info.velocity.X *= -1; } dirChangeTimer = DateTime.Now.Ticks + 15000000; } } } } else if (other is SpriteBlock && (other as SpriteBlock).Bumping) { if (direction == Direction.BOTTOM) { this.Die(); } } } else { Console.WriteLine("Goomba is already dead!"); } }