/// <summary>
        /// Add all the objects in ObjectsToAdd to ActiveObjects, then update ActiveObjects before deleting objects in ObjectsToRemove
        /// </summary>
        /// <param name="elapsedGameTime">The seconds that have elapsed since the last update loop</param>
        public override void Update(float elapsedGameTime)
        {
            // Always call the super class' function - it will deal with whether it should run it itself
            base.Update(elapsedGameTime);

            // Add the objects and then clear the list - it is only a temporary holder
            ActiveObjects.AddRange(ObjectsToAdd);
            ObjectsToAdd.Clear();

            // Loop through the active object
            foreach (T obj in ActiveObjects)
            {
                if (obj.ShouldUpdate)
                {
                    // Update the object
                    obj.Update(elapsedGameTime);
                }
            }

            // Remove all the objects that are no longer alive
            ActiveObjects.RemoveAll(x => x.IsAlive == false);

            // Remove all the objects we have marked to remove
            foreach (T obj in ObjectsToRemove)
            {
                ActiveObjects.Remove(obj);
            }
            ObjectsToRemove.Clear();    // Clear the list - it is only a temporary holder
        }
Example #2
0
 public void Initialize()
 {
     ActiveObjects.Add(new Player(PlayerStart));
     ActiveObjects.AddRange(StaticObjects);
     ActiveObjects.AddRange(EnemyDots);
     ActiveObjects.AddRange(Coins);
     ActiveObjects.Add(Goal);
 }
Example #3
0
        public void Reset()
        {
            (Globals.ActiveScene.ActiveObjects.First(x => x is Player) as Player).Reset(PlayerStart);
            AquiredCoins = 0;
            ActiveObjects.ForEach(x =>
                                      {
                                          if (!(x is Coin))
                                              return;

                                          ActiveObjects.Remove(x);
                                      });
            ActiveObjects.AddRange(GetCoins());
        }
        /// <summary>
        /// Because we add objects in the update loop, the current objects we need to load are in ObjectsToAdd.
        /// Iterate through them, call Initialise on each of them and add to our ActiveObjects
        /// </summary>
        public override void Initialise()
        {
            // Check to see whether we have already called Initialise
            CheckShouldInitialise();

            foreach (T obj in ObjectsToAdd.FindAll(x => x.ShouldInitialise))
            {
                // Call initialise on all objects which have not already been initialised
                obj.Initialise();
            }

            ActiveObjects.AddRange(ObjectsToAdd);
            ObjectsToAdd.Clear();

            base.Initialise();
        }
        /// <summary>
        /// Iterate through all the objects in ActiveObjects and call Begin
        /// </summary>
        public override void Begin()
        {
            base.Begin();

            // Do not need to check whether begun has already been called - this is guaranteed

            // Do another pass on our ObjectsToAdd to add any stragglers
            ActiveObjects.AddRange(ObjectsToAdd);
            ObjectsToAdd.Clear();

            foreach (T obj in ActiveObjects.FindAll(x => !x.IsBegun))
            {
                // Call begin on any object which has not already begun
                obj.Begin();
            }
        }