/
DDState.cs
91 lines (82 loc) · 2.52 KB
/
DDState.cs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
namespace DDEngine
{
public class DDState
{
protected ContentManager Content;
/// <summary>
/// Gets the members.
/// </summary>
/// <value>The members.</value>
public List<DDObject> Members { get; private set; }
/// <summary>
/// Camera.
/// </summary>
public DDCamera Camera { get; private set; }
/// <summary>
/// Initialize this state.
/// </summary>
public virtual void Initialize()
{
Members = new List<DDObject>();
Camera = new DDCamera();
Camera.Initialize();
}
/// <summary>
/// Create a Content Manager for the state then pass the content manager to every member.
/// </summary>
public virtual void LoadContent()
{
Content = new ContentManager(DDGame.Instance.Content.ServiceProvider, "Content");
foreach (DDObject o in Members)
{
o.LoadContent(Content);
}
}
/// <summary>
/// Unloads the content.
/// </summary>
public virtual void UnloadContent()
{
Content.Unload();
}
/// <summary>
/// Update the specified gameTime and update for every member.
/// </summary>
/// <returns>The update.</returns>
/// <param name="gameTime">Game time.</param>
public virtual void Update(GameTime gameTime)
{
foreach (DDObject o in Members)
{
if (o.Active) o.Update(gameTime);
}
}
/// <summary>
/// Draw the specified spriteBatch and draw every member.
/// </summary>
/// <returns>The draw.</returns>
/// <param name="spriteBatch">Sprite batch.</param>
public virtual void Draw(SpriteBatch spriteBatch)
{
foreach (DDObject o in Members)
{
if (o.Active) o.Draw(spriteBatch);
}
}
/// <summary>
/// Add the specified item to this state.
/// </summary>
/// <returns>The add.</returns>
/// <param name="item">Item.</param>
public DDObject Add(DDObject item)
{
Members.Add(item);
return item;
}
}
}