/// <summary> /// Method that updates the game. /// </summary> /// <param name="input">Input</param> /// <param name="gameTime">GameTime</param> public override void Update(Input input, GameTime gameTime) { base.Update(input, gameTime); Collider collider; var pos = Position; var delta = Forward * Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; Move(delta); bool hitTilemap; // Check if the sleep dart collides with anything if (Collider.CollidesAny(out collider, out hitTilemap, originCollider)) { Position = pos; // Set the speed to 0 Speed = 0.0f; // Check if the sleep dart collides with a guard if (collider != null && collider.Entity.Tag.Equals("Guard")) { var guard = collider.Entity as Guard; guard.Sleep(); var sound = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/DartHit").CreateInstance(); sound.Volume = 1 * SettingsPage.Volume * SettingsPage.EffectVolume; sound.Play(); MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/HurtSound").CreateInstance(); sound.Volume = 1 * SettingsPage.Volume * SettingsPage.EffectVolume; sound.Play(); MonoGearGame.DestroyEntity(this); } // Disable the sleep dart Enabled = false; } }
/// <summary> /// Method that updates the game /// </summary> /// <param name="input">Input</param> /// <param name="gameTime">GameTime</param> public override void Update(Input input, GameTime gameTime) { base.Update(input, gameTime); // Keep moving the missile forward var pos = Position; var delta = Forward * Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; Move(delta); // If not exploded, kee[ counting down if (boemInSec > 0) { boemInSec -= (float)gameTime.ElapsedGameTime.TotalSeconds; } // If we hit anything or the timer runs out, EXPLODE if (Collider.CollidesAny() || boemInSec <= 0) { Position = pos; Speed = 0.0f; MonoGearGame.SpawnLevelEntity(new Explosion() { Position = this.Position }); MonoGearGame.DestroyEntity(this); } }
/// <summary> /// Method that updates the game /// </summary> /// <param name="input">Input</param> /// <param name="gameTime">GameTime</param> public override void Update(Input input, GameTime gameTime) { base.Update(input, gameTime); Collider collider; var pos = Position; var delta = Forward * Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; Move(delta); bool hitTilemap; // Check if the bullet collides with anything if (Collider.CollidesAny(out collider, out hitTilemap, originCollider)) { Position = pos; // Set the speed to 0 Speed = 0.0f; // Check if the bullet collides with a player if (!hitTilemap && collider.Entity.Tag == "Player") { var player = collider.Entity as Player; // Decrease the player's health by 1 player.Health -= 1.0f; } // Find everything that can be destroyed var things = MonoGearGame.FindEntitiesOfType <IDestroyable>(); foreach (var thing in things) { // Damage the thing if it gets hit var dis = thing as WorldEntity; if (!hitTilemap && collider.Entity == dis) { thing.Damage(maxDamage); } } // Destroy if we hit something MonoGearGame.DestroyEntity(this); } }
/// <summary> /// Method that updates the game /// </summary> /// <param name="input">Input</param> /// <param name="gameTime">GameTime</param> public override void Update(Input input, GameTime gameTime) { base.Update(input, gameTime); // Check if the animation is at its first frame if (AnimationCurrentFrame == 1 && !exploded) { if (player.Enabled) { // Calcutate damage based on distance from the explotion var dis = Vector2.Distance(player.Position, Position); if (dis < blastRadius) { player.Health -= maxDamage * (dis / blastRadius); } } // Find everything that can be destroyed var things = MonoGearGame.FindEntitiesOfType <IDestroyable>(); foreach (var thing in things) { // Calcutate damage based on distance from the explotion var dis = Vector2.Distance((thing as WorldEntity).Position, Position); if (dis < blastRadius) { thing.Damage(maxDamage * (dis / blastRadius)); } } // Note that we have exploded exploded = true; } // Destoy the explotion after its done with the animation else if (AnimationCurrentFrame == 14) { MonoGearGame.DestroyEntity(this); } }
/// <summary> /// Method is executed when the guard is killed. /// </summary> public void Destroy() { MonoGearGame.DestroyEntity(this); }