示例#1
0
        /// <summary>
        /// Called when [update].
        /// </summary>
        /// <param name="gametime">The gametime.</param>
        protected override void OnUpdate(GameTime gametime)
        {
            base.OnUpdate(gametime);

            // Ensure that the current screen is active and not exiting
            if (!this.IsExiting)
            {
                // Check to see if the player has been spawned
                if (this.Player != null)
                {
                    if (!this.Player.IsAlive || this.Player.ReachedExit)
                    {
                        // The player is dead so exit the level
                        this.ExitScreen();
                    }
                    else
                    {
                        // Perform player and sprite updates
                        foreach (var layer in this._layers)
                        {
                            layer.Update(gametime);
                        }

                        // Check for collisions
                        CollisionManager.Update(gametime);

                        PlayRandomSound(gametime);

                        // Update the camera position based on the player
                        this._camera.LookAt(this.Player.Position);

                        ///////////////////////////////////////////////////////////////////////////////////////
                        // REMOVED BECAUSE THESE ARE OVERWRITING ANY REAL MESSAGE YOU WANT TO WRITE TO THE HUD
                        ///////////////////////////////////////////////////////////////////////////////////////
                        //// Send random messages to the HUD
                        //if (this.Player.TimeToLive < new TimeSpan(0, 1, 30))
                        //{
                        //    this.Hud.Message = "Amy is a goober!";
                        //}
                        //else if (this.Player.TimeToLive < new TimeSpan(0, 1, 50))
                        //{
                        //    this.Hud.Message = "Morton Rules!";
                        //}
                        //else
                        //{
                        //    this.Hud.Message = "Go get to the head shaving event!";
                        //}
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Updates all objects in the world, performs collision between them,
        /// and handles the time limit with scoring.
        /// </summary>
        public void Update(GameTime gameTime, InputState input)
        {
            if (this._player != null)
            {
                // Pause while the player is dead or time is expired.
                if (!this._player.IsAlive || (this._player.TimeToLive == TimeSpan.Zero))
                {
                    // Remove the player from the level
                    this._player = null;
                }
                else
                {
                    // Check for collisions
                    CollisionManager.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

                    // Perform player and sprite updates
                    this._player.Update(gameTime, input);
                    this._sprites.ForEach((sprite) => sprite.Update(gameTime, input));
                }
            }
        }