/Engine/Game/World.cs
# · C# · 75 lines · 41 code · 9 blank · 25 comment · 0 complexity · 59b0e14c0055e7239698079a1037e544 MD5 · raw file
- using System.Collections.Generic;
-
- namespace Delta.Engine.Game
- {
- /// <summary>
- /// Basic world class containing a list of actors which can be spawned and
- /// despawned into the world.
- /// </summary>
- public class World
- {
- #region AllActors (Public)
- /// <summary>
- /// Array of all actors in this world.
- /// </summary>
- public Actor[] AllActors
- {
- get
- {
- return actors.ToArray();
- }
- }
- #endregion
-
- #region Private
-
- #region actors (Private)
- /// <summary>
- /// List of all actors in this world.
- /// </summary>
- private readonly List<Actor> actors;
- #endregion
-
- #endregion
-
- #region Constructors
- /// <summary>
- /// Create a new world.
- /// </summary>
- public World()
- {
- actors = new List<Actor>();
- }
- #endregion
-
- #region SpawnActor (Public)
- /// <summary>
- /// Spawn an actor in the world.
- /// </summary>
- /// <param name="newActor">The new actor to spawn.</param>
- public void SpawnActor(Actor newActor)
- {
- // Call the "Spawned" function to let the actor do logic after being
- // spawned.
- newActor.Spawned();
-
- // Add actor to our list of actors
- actors.Add(newActor);
- }
- #endregion
-
- #region DespawnActor (Public)
- /// <summary>
- /// Calls the despawned method of the actor and then removes the actor
- /// from the list of known actors.
- /// </summary>
- /// <param name="actor">The actor to despawn.</param>
- public void DespawnActor(Actor actor)
- {
- actor.Despawned();
-
- actors.Remove(actor);
- }
- #endregion
- }
- }