/// <summary> /// Kills this object, in response to the given GameplayObject. /// </summary> /// <param name="source">The GameplayObject responsible for the kill.</param> /// <param name="cleanupOnly"> /// If true, the object dies without any further effects. /// </param> public override void Die(GameplayObject source, bool cleanupOnly) { if (active) { if (!cleanupOnly) { // play the explosion sound AudioManager.PlaySoundEffect("explosion_medium"); // display the rocket explosion if (ParticleEffectManager != null) { ParticleEffectManager.SpawnEffect( ParticleEffectType.RocketExplosion, Position); } } // stop the rocket-flying sound effect if (rocketSound != null) { rocketSound.Stop(true); rocketSound.Dispose(); rocketSound = null; } // stop the rocket-trail effect if (rocketTrailEffect != null) { rocketTrailEffect.Stop(false); } } base.Die(source, cleanupOnly); }
/// <summary> /// Kills this ship, in response to the given GameplayObject. /// </summary> /// <param name="source">The GameplayObject responsible for the kill.</param> /// <param name="cleanupOnly"> /// If true, the object dies without any further effects. /// </param> public override void Die(GameplayObject source, bool cleanupOnly) { if (active) { if (!cleanupOnly) { // update the score Ship ship = source as Ship; if (ship == null) { Projectile projectile = source as Projectile; if (projectile != null) { ship = projectile.Owner; } } if (ship != null) { if (ship == this) { // reduce the score, since i blew myself up ship.Score--; } else { // add score to the ship who shot this object ship.Score++; } } else { // if it wasn't a ship, then this object loses score this.Score--; } // play the player-death sound AudioManager.PlaySoundEffect("explosion_shockwave"); AudioManager.PlaySoundEffect("explosion_large"); // display the ship explosion if (ParticleEffectManager != null) { ParticleEffectManager.SpawnEffect( ParticleEffectType.ShipExplosion, Position); } } // clear out the projectiles list foreach (Projectile projectile in projectiles) { projectile.Die(null, true); } projectiles.Clear(); // set the respawn timer respawnTimer = respawnTimerOnDeath; } base.Die(source, cleanupOnly); }
/// <summary> /// Initialize a ship to its default gameplay states. /// </summary> public override void Initialize() { if (!active) { // set the initial gameplay data values shipInput = ShipInput.Empty; rotation = 0f; velocity = Vector2.Zero; life = lifeMaximum; shield = shieldMaximum; shieldRechargeTimer = 0f; safeTimer = safeTimerMaximum; weapon = new LaserWeapon(this); mineWeapon = new MineWeapon(this); // play the player-spawn sound AudioManager.PlaySoundEffect("player_spawn"); // add the ship-spawn particle effect if (ParticleEffectManager != null) { ParticleEffectManager.SpawnEffect(ParticleEffectType.ShipSpawn, this); } // clear out the projectiles list projectiles.Clear(); } base.Initialize(); }
/// <summary> /// Defines the interaction between the asteroid and a target GameplayObject /// when they touch. /// </summary> /// <param name="target">The GameplayObject that is touching this one.</param> /// <returns>True if the objects meaningfully interacted.</returns> public override bool Touch(GameplayObject target) { // if the asteroid has touched a player, then damage it Ship player = target as Ship; if (player != null) { // calculate damage as a function of how much the two GameplayObject's // velocities were going towards one another Vector2 playerAsteroidVector = Position - player.Position; if (playerAsteroidVector.LengthSquared() > 0) { playerAsteroidVector.Normalize(); float rammingSpeed = Vector2.Dot(playerAsteroidVector, player.Velocity) - Vector2.Dot(playerAsteroidVector, Velocity); float momentum = Mass * rammingSpeed; player.Damage(this, momentum * momentumToDamageScalar); } } // if the asteroid didn't hit a projectile, play the asteroid-touch sound effect if ((target is Projectile) == false) { AudioManager.PlaySoundEffect("asteroid_touch"); } return(true); }
/// <summary> /// Initialize the power-up to it's default gameplay states. /// </summary> public override void Initialize() { if (!active) { // play the spawn sound effect AudioManager.PlaySoundEffect("powerup_spawn"); } base.Initialize(); }
/// <summary> /// Initialize the rocket projectile to it's default gameplay states. /// </summary> public override void Initialize() { if (!active) { // get and play the rocket-flying sound effect AudioManager.PlaySoundEffect("rocket", true, out rocketSound); // start the rocket-trail effect if (ParticleEffectManager != null) { rocketTrailEffect = ParticleEffectManager.SpawnEffect( ParticleEffectType.RocketTrail, this); } } base.Initialize(); }
/// <summary> /// Defines the interaction between this power-up and a target GameplayObject /// when they touch. /// </summary> /// <param name="target">The GameplayObject that is touching this one.</param> /// <returns>True if the objects meaningfully interacted.</returns> public override bool Touch(GameplayObject target) { // if it touched a ship, then create a particle system and play a sound Ship ship = target as Ship; if (ship != null) { // play the "power-up picked up" sound effect AudioManager.PlaySoundEffect("powerup_touch"); // kill the power-up Die(target, false); // the ship keeps going as if it didn't hit anything return(false); } return(base.Touch(target)); }
/// <summary> /// Kills this object, in response to the given GameplayObject. /// </summary> /// <param name="source">The GameplayObject responsible for the kill.</param> /// <param name="cleanupOnly"> /// If true, the object dies without any further effects. /// </param> public override void Die(GameplayObject source, bool cleanupOnly) { if (active) { if (!cleanupOnly) { // play the explosion sound effect AudioManager.PlaySoundEffect("explosion_large"); // play the mine particle-effect if (ParticleEffectManager != null) { ParticleEffectManager.SpawnEffect( ParticleEffectType.MineExplosion, Position); } } } base.Die(source, cleanupOnly); }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(InputState input) { // Move to the previous menu entry? if (input.MenuUp) { selectedEntry--; if (selectedEntry < 0) { selectedEntry = menuEntries.Count - 1; } AudioManager.PlaySoundEffect("menu_scroll"); } // Move to the next menu entry? if (input.MenuDown) { selectedEntry++; if (selectedEntry >= menuEntries.Count) { selectedEntry = 0; } AudioManager.PlaySoundEffect("menu_scroll"); } // Accept or cancel the menu? if (input.MenuSelect) { AudioManager.PlaySoundEffect("menu_select"); OnSelectEntry(selectedEntry); } else if (input.MenuCancel) { OnCancel(); } }
/// <summary> /// Fire the weapon in the direction given. /// </summary> /// <param name="direction">The direction that the weapon is firing in.</param> public virtual void Fire(Vector2 direction) { // if we can't fire yet, then we're done if (timeToNextFire > 0f) { return; } // the owner is no longer safe from damage owner.Safe = false; // set the timer timeToNextFire = fireDelay; // create and spawn the projectile CreateProjectiles(direction); // play the sound effect for firing if (String.IsNullOrEmpty(fireSoundEffect) == false) { AudioManager.PlaySoundEffect(fireSoundEffect); } }