diff options
Diffstat (limited to 'V3/Effects')
-rw-r--r-- | V3/Effects/AbstractEffect.cs | 74 | ||||
-rw-r--r-- | V3/Effects/BloodBang.cs | 8 | ||||
-rw-r--r-- | V3/Effects/BloodExplosion.cs | 11 | ||||
-rw-r--r-- | V3/Effects/BloodFountain.cs | 11 | ||||
-rw-r--r-- | V3/Effects/EffectsManager.cs | 54 | ||||
-rw-r--r-- | V3/Effects/Explosion.cs | 14 | ||||
-rw-r--r-- | V3/Effects/HorseEffect.cs | 11 | ||||
-rw-r--r-- | V3/Effects/IEffect.cs | 44 | ||||
-rw-r--r-- | V3/Effects/IEffectsManager.cs | 31 | ||||
-rw-r--r-- | V3/Effects/Quake.cs | 11 | ||||
-rw-r--r-- | V3/Effects/SmokeBig.cs | 10 | ||||
-rw-r--r-- | V3/Effects/SmokeMedium.cs | 13 | ||||
-rw-r--r-- | V3/Effects/SmokeSmall.cs | 10 |
13 files changed, 302 insertions, 0 deletions
diff --git a/V3/Effects/AbstractEffect.cs b/V3/Effects/AbstractEffect.cs new file mode 100644 index 0000000..c3468c0 --- /dev/null +++ b/V3/Effects/AbstractEffect.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Audio; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using V3.Data; + +namespace V3.Effects +{ + public abstract class AbstractEffect : IEffect + { + private Texture2D mTexture; + private int mSpritesPerRow; + private int mTotalSprites; + private int mAnimationState; + private Rectangle mAnimationRectangle; + private SoundEffect mSoundEffect; + private SoundEffectInstance mSoundEffectInstance; + + public bool IsPlaying { get; private set; } + protected virtual UpdatesPerSecond UpdatesPerSecond { get; } = new UpdatesPerSecond(24); + protected abstract string TextureFile { get; } + protected virtual Point SpriteSize { get; } = new Point(128, 128); + protected virtual string SoundFile { get; } = String.Empty; + + public void LoadContent(ContentManager contentManager) + { + mTexture = contentManager.Load<Texture2D>("Effects/" + TextureFile); + mSpritesPerRow = mTexture.Width / SpriteSize.X; + mTotalSprites = mSpritesPerRow * (mTexture.Height / SpriteSize.Y); + if (SoundFile.Length != 0) + { + mSoundEffect = contentManager.Load<SoundEffect>("Sounds/" + SoundFile); + mSoundEffectInstance = mSoundEffect.CreateInstance(); + } + } + + public void PlayOnce(Point position, Point size, IOptionsManager optionsManager) + { + mAnimationRectangle = new Rectangle(position - size / new Point(2, 2), size); + IsPlaying = true; + if (SoundFile.Length != 0) + { + mSoundEffectInstance.Volume = optionsManager.Options.GetEffectiveVolume(); + mSoundEffectInstance.Play(); + } + } + + public void Update(GameTime gameTime) + { + if (!IsPlaying) return; + if (UpdatesPerSecond.IsItTime(gameTime)) + { + if (mAnimationState < mTotalSprites) + { + mAnimationState++; + } + else + { + mAnimationState = 0; + IsPlaying = false; + } + } + } + + public void Draw(SpriteBatch spriteBatch) + { + if (!IsPlaying) return; + spriteBatch.Draw(mTexture, mAnimationRectangle, + new Rectangle(new Point(mAnimationState % mSpritesPerRow * SpriteSize.X, mAnimationState / mSpritesPerRow * SpriteSize.Y), SpriteSize), + Color.White); + } + } +}
\ No newline at end of file diff --git a/V3/Effects/BloodBang.cs b/V3/Effects/BloodBang.cs new file mode 100644 index 0000000..f5e1f3c --- /dev/null +++ b/V3/Effects/BloodBang.cs @@ -0,0 +1,8 @@ +namespace V3.Effects +{ + public class BloodBang : AbstractEffect + { + protected override string TextureFile { get; } = "blood_hit_04"; + protected override string SoundFile { get; } = "impactsplat01"; + } +}
\ No newline at end of file diff --git a/V3/Effects/BloodExplosion.cs b/V3/Effects/BloodExplosion.cs new file mode 100644 index 0000000..baa38d4 --- /dev/null +++ b/V3/Effects/BloodExplosion.cs @@ -0,0 +1,11 @@ +namespace V3.Effects +{ + /// <summary> + /// A round explosion of blood. + /// </summary> + public sealed class BloodExplosion : AbstractEffect + { + protected override string TextureFile { get; } = "blood_hit_08"; + protected override string SoundFile { get; } = "impactsplat01"; + } +}
\ No newline at end of file diff --git a/V3/Effects/BloodFountain.cs b/V3/Effects/BloodFountain.cs new file mode 100644 index 0000000..5684e34 --- /dev/null +++ b/V3/Effects/BloodFountain.cs @@ -0,0 +1,11 @@ +namespace V3.Effects +{ + /// <summary> + /// A small fountain of blood. + /// </summary> + public sealed class BloodFountain : AbstractEffect + { + protected override string TextureFile { get; } = "blood_hit_02"; + protected override string SoundFile { get; } = "impactsplat01"; + } +}
\ No newline at end of file diff --git a/V3/Effects/EffectsManager.cs b/V3/Effects/EffectsManager.cs new file mode 100644 index 0000000..a175e34 --- /dev/null +++ b/V3/Effects/EffectsManager.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using V3.Data; + +namespace V3.Effects +{ + // ReSharper disable once ClassNeverInstantiated.Global + public sealed class EffectsManager : IEffectsManager + { + private readonly ContentManager mContentManager; + private readonly IOptionsManager mOptionsManager; + private readonly List<IEffect> mActiveEffects = new List<IEffect>(); + + public EffectsManager(ContentManager contentManager, IOptionsManager optionsManager) + { + mContentManager = contentManager; + mOptionsManager = optionsManager; + } + + public void Update(GameTime gameTime) + { + var doneEffects = new List<IEffect>(); + foreach (var effect in mActiveEffects) + { + effect.Update(gameTime); + if (!effect.IsPlaying) + { + doneEffects.Add(effect); + } + } + foreach (var doneEffect in doneEffects) + { + mActiveEffects.Remove(doneEffect); + } + } + + public void Draw(SpriteBatch spriteBatch) + { + foreach (var effect in mActiveEffects) + { + effect.Draw(spriteBatch); + } + } + + public void PlayOnce(IEffect effect, Point position, Point size) + { + effect.LoadContent(mContentManager); + mActiveEffects.Add(effect); + effect.PlayOnce(position, size, mOptionsManager); + } + } +}
\ No newline at end of file diff --git a/V3/Effects/Explosion.cs b/V3/Effects/Explosion.cs new file mode 100644 index 0000000..afcfdf4 --- /dev/null +++ b/V3/Effects/Explosion.cs @@ -0,0 +1,14 @@ +using Microsoft.Xna.Framework; + +namespace V3.Effects +{ + /// <summary> + /// A large explosion with sound. + /// </summary> + public class Explosion : AbstractEffect + { + protected override string TextureFile { get; } = "explosion"; + protected override Point SpriteSize { get; } = new Point(320, 240); + protected override string SoundFile { get; } = "explosion1"; + } +}
\ No newline at end of file diff --git a/V3/Effects/HorseEffect.cs b/V3/Effects/HorseEffect.cs new file mode 100644 index 0000000..a09fe60 --- /dev/null +++ b/V3/Effects/HorseEffect.cs @@ -0,0 +1,11 @@ +using Microsoft.Xna.Framework; + +namespace V3.Effects +{ + public sealed class HorseEffect : AbstractEffect + { + protected override string TextureFile { get; } = "quake"; + protected override Point SpriteSize { get; } = new Point(256, 128); + protected override string SoundFile { get; } = "horse"; + } +} diff --git a/V3/Effects/IEffect.cs b/V3/Effects/IEffect.cs new file mode 100644 index 0000000..73cf1ef --- /dev/null +++ b/V3/Effects/IEffect.cs @@ -0,0 +1,44 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using V3.Data; + +namespace V3.Effects +{ + /// <summary> + /// Interface for a single effect. + /// </summary> + public interface IEffect + { + /// <summary> + /// Is the effect playing at the moment? + /// </summary> + bool IsPlaying { get; } + + /// <summary> + /// Play the specific effect once, do not loop. + /// </summary> + /// <param name="position">Position where effect should be played. Points to the middle of the effect animation.</param> + /// <param name="size">Size of the effect.</param> + /// <param name="optionsManager">For checking the volume of the sound if there is one.</param> + void PlayOnce(Point position, Point size, IOptionsManager optionsManager); + + /// <summary> + /// Update the effect. + /// </summary> + /// <param name="gameTime">Game time used for checking animation duration.</param> + void Update(GameTime gameTime); + + /// <summary> + /// Draw the effect. + /// </summary> + /// <param name="spriteBatch">Sprite batch used.</param> + void Draw(SpriteBatch spriteBatch); + + /// <summary> + /// Load graphics and possibly sound for the effect. + /// </summary> + /// <param name="contentManager">Content manager used.</param> + void LoadContent(ContentManager contentManager); + } +}
\ No newline at end of file diff --git a/V3/Effects/IEffectsManager.cs b/V3/Effects/IEffectsManager.cs new file mode 100644 index 0000000..3ea6154 --- /dev/null +++ b/V3/Effects/IEffectsManager.cs @@ -0,0 +1,31 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace V3.Effects +{ + /// <summary> + /// Interface for managing visual effects like explosions and stuff. + /// </summary> + public interface IEffectsManager + { + /// <summary> + /// Update all effects. + /// </summary> + /// <param name="gameTime">Game time used for calculation effects duration.</param> + void Update(GameTime gameTime); + + /// <summary> + /// Draw all effects. + /// </summary> + /// <param name="spriteBatch">Sprite batch used.</param> + void Draw(SpriteBatch spriteBatch); + + /// <summary> + /// Play an effect once, then delete it. + /// </summary> + /// <param name="effect">Which effect to play.</param> + /// <param name="position">Position where effect should be played. Points to the middle of the effect animation.</param> + /// <param name="size">Size of the effect.</param> + void PlayOnce(IEffect effect, Point position, Point size); + } +}
\ No newline at end of file diff --git a/V3/Effects/Quake.cs b/V3/Effects/Quake.cs new file mode 100644 index 0000000..c08825d --- /dev/null +++ b/V3/Effects/Quake.cs @@ -0,0 +1,11 @@ +using Microsoft.Xna.Framework; + +namespace V3.Effects +{ + public class Quake : AbstractEffect + { + protected override string TextureFile { get; } = "quake"; + protected override Point SpriteSize { get; } = new Point(256, 128); + protected override string SoundFile { get; } = "explodemini"; + } +}
\ No newline at end of file diff --git a/V3/Effects/SmokeBig.cs b/V3/Effects/SmokeBig.cs new file mode 100644 index 0000000..3dfce2a --- /dev/null +++ b/V3/Effects/SmokeBig.cs @@ -0,0 +1,10 @@ +namespace V3.Effects +{ + /// <summary> + /// A large ring of smoke, spreading over some area. + /// </summary> + public sealed class SmokeBig : AbstractEffect + { + protected override string TextureFile { get; } = "particlefx_03"; + } +}
\ No newline at end of file diff --git a/V3/Effects/SmokeMedium.cs b/V3/Effects/SmokeMedium.cs new file mode 100644 index 0000000..09447fa --- /dev/null +++ b/V3/Effects/SmokeMedium.cs @@ -0,0 +1,13 @@ +using System.Diagnostics.CodeAnalysis; + +namespace V3.Effects +{ + /// <summary> + /// A medium sized ring of smoke, spreading over some area. + /// </summary> + [SuppressMessage("ReSharper", "UnusedMember.Global")] + public sealed class SmokeMedium : AbstractEffect + { + protected override string TextureFile { get; } = "particlefx_04"; + } +}
\ No newline at end of file diff --git a/V3/Effects/SmokeSmall.cs b/V3/Effects/SmokeSmall.cs new file mode 100644 index 0000000..f2f2dce --- /dev/null +++ b/V3/Effects/SmokeSmall.cs @@ -0,0 +1,10 @@ +namespace V3.Effects +{ + /// <summary> + /// A small ring of smoke, spreading over some area. + /// </summary> + public sealed class SmokeSmall : AbstractEffect + { + protected override string TextureFile { get; } = "particlefx_05"; + } +}
\ No newline at end of file |