Esempio n. 1
0
        protected override void Update(GameTime gameTime)
        {
            foreach (SpriteLayer layer in this.Layers)
            {
                layer.Update(gameTime);
            }

            pointGenerator.Update(gameTime);

            CollisionHandler.ScanCollisions();

            float vy = this.Mario.Info.velocity.Y;

            if (vy > 1)
            {
                this.Mario.StateMachineAction.CurrentState.ToFall();
            }

            if (this.Mario.Info.position.X > checkpoint + (this.bounds.Width / numberOfCheckpoints))
            {
                checkpoint += this.bounds.Width / numberOfCheckpoints;
            }

            base.Update(gameTime);

            if (this.RunAfterUpdate != null)
            {
                this.RunAfterUpdate();
                this.RunAfterUpdate = null;
            }

            if (this.TimeLeft != 0 && this.Mario.SpriteState != SpriteStates.Sprites.DEAD && !this.Mario.won)
            {
                if (!this.Mario.won)
                {
                    //Console.WriteLine("Mario state: {0}, (dead={1})", this.Mario.SpriteState, SpriteStates.Sprites.DEAD);
                    if (!Layers.TrueForAll(new Predicate <SpriteLayer>(LayersPaused)))
                    {
                        currentTime += gameTime.ElapsedGameTime.TotalSeconds;
                        if (this.currentTime >= 1)
                        {
                            this.currentTime -= 1;
                            this.TimeLeft    -= 1;
                            if (this.TimeLeft == TIME_WARNING)
                            {
                                SoundFactory.PlaySoundEffect(SoundFactory.TimeEnding());
                                MediaPlayer.Stop();
                                MediaPlayer.Play(spedBackgroundSong);
                                MediaPlayer.IsRepeating = true;
                            }
                        }
                    }
                }
            }
            else if (this.Mario.won)
            {
            }
            else
            {
                this.Mario.StateMachineAction.CurrentState.ToDead();
            }
        }