-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameScene.cs
94 lines (89 loc) · 2.88 KB
/
GameScene.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
92
93
94
/* GameScene.cs
* Final project
* Revision History
* Zhiyuan Wu, 2023.12.06: Created
* Zhiyuan Wu, 2023.12.06: Added code
* Zhiyuan Wu, 2023.12.10: Debugging complete
* Zhiyuan Wu, 2023.12.10: Comments added
*
*/
using CoolGame.Sprites;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoolGame
{
/// <summary>
/// Represents a base class for different scenes in the game, such as menus or levels.
/// </summary>
public abstract class GameScene : DrawableGameComponent
{
private List<GameComponent> components;
/// <summary>
/// Gets or sets the components of the game scene.
/// </summary>
public List<GameComponent> Components { get => components; set => components = value; }
/// <summary>
/// Shows the game scene, making it visible and active.
/// </summary>
public virtual void show()
{
this.Enabled = true;
this.Visible = true;
}
/// <summary>
/// Hides the game scene, making it invisible and inactive.
/// </summary>
public virtual void hide()
{
this.Enabled = false;
this.Visible = false;
}
/// <summary>
/// Initializes a new instance of the GameScene class.
/// </summary>
/// <param name="game">The game object this scene is associated with.</param>
protected GameScene(Game game) : base(game)
{
components = new List<GameComponent>();
hide();
}
/// <summary>
/// Updates the game scene and its components.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(GameTime gameTime)
{
foreach (GameComponent item in components)
{
if (item.Enabled)
{
item.Update(gameTime);
}
}
base.Update(gameTime);
}
/// <summary>
/// Draws the game scene and its drawable components.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values, used for frame-based animation.</param>
public override void Draw(GameTime gameTime)
{
foreach (GameComponent item in components)
{
if (item is DrawableGameComponent)
{
DrawableGameComponent comp = (DrawableGameComponent)item;
if (comp.Visible )
{
comp.Draw(gameTime);
}
}
}
base.Draw(gameTime);
}
}
}