Esempio n. 1
0
        public override void Enter(StateMario previousState)
        {
            base.Enter(previousState);

            this.StateMachine.Mario.SetSheetState(SpriteStates.Sheets.NORMAL);
            this.StateMachine.Mario.SetSpriteState(SpriteStates.Sprites.DEAD);
            this.StateMachine.Mario.Info.velocity = new Vector2(0f, -8f);

            MediaPlayer.Stop();
            SoundEffect dying = SoundFactory.Death();

            SoundFactory.PlaySoundEffect(dying);
            Task.Factory.StartNew(delegate() {
                Console.WriteLine("Waiting {0}ms before resetting", dying.Duration.Milliseconds * 10);
                Thread.Sleep(dying.Duration.Milliseconds * 10);

                this.StateMachine.Mario.lives--;

                if (this.StateMachine.Mario.lives > 0)
                {
                    Console.WriteLine("Resetting after next update loop");
                    this.StateMachine.Mario.SetSpriteState(SpriteStates.Sprites.IDLE);
                    this.StateMachine.Mario.game.RunAfterUpdate = this.StateMachine.Mario.game.Reset;
                }
                //else, mediaplayer remains stopped
            });
        }