blob: a175e342c6097cde02bb0de1277b961180658424 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
}
}
}
|