示例#1
0
        public void RevealItem()
        {
            if (this.item != null && this.SheetState != SpriteStates.Sheets.USED)
            {
                this.SetSpriteState(SpriteStates.Sprites.IDLE);

                if (!(this.item is SpriteCoin))
                {
                    SoundFactory.PlaySoundEffect(SoundFactory.PowerUpAppear());
                }

                Thread t = new Thread(new ThreadStart(
                                          delegate()
                {
                    this.item.Info.position = this.Info.position;
                    this.itemCount--;
                    (this.item as IRevealable).Reveal();
                    if (this.itemCount <= 0)
                    {
                        this.item = null;
                        this.SetSheetState(SpriteStates.Sheets.USED);
                    }

                    Console.WriteLine("Reveal finished");
                }
                                          ));
                t.IsBackground = true;
                t.Start();
            }
        }
示例#2
0
        public override void Update(GameTime gametime)
        {
            base.Update(gametime);
            if (this.game.Mario.lives == 0 && !this.Sprites.Contains(this.gameOver))
            {
                SoundFactory.PlaySoundEffect(SoundFactory.GameOver());
                this.AddSprite(this.gameOver);
                int dy = 250;
                this.gameOver.Info.bounds = new Rectangle(this.gameOver.Info.x - 2, this.gameOver.Info.y - dy, this.gameOver.Info.spriteWidth + 2, this.gameOver.Info.spriteHeight + dy);
                this.gameOver.SetPosition(this.gameOver.Info.x, this.gameOver.Info.y - dy);
                this.gameOver.Info.acceleration.Y = 0.15f;

                foreach (InputController ic in SpriteLayer.CollisionLayer.InputControllers)
                {
                    ic.Paused = true;
                }
            }
            else if (this.game.Mario.lives > 0 && this.Sprites.Contains(this.gameOver))
            {
                this.RemoveSprite(this.gameOver);
                foreach (InputController ic in SpriteLayer.CollisionLayer.InputControllers)
                {
                    ic.Paused = false;
                }
            }
        }
示例#3
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
            });
        }
        public override void Enter(StatePowerup previousState)
        {
            base.Enter(previousState);

            this.StateMachine.Mario.SetSheetState(SpriteStates.Sheets.SUPER);
            SoundFactory.PlaySoundEffect(SoundFactory.PowerUp());
        }
示例#5
0
        //Gets killed by fireball or shell
        public void Die()
        {
            SoundFactory.PlaySoundEffect(SoundFactory.Kick());

            this.Info.spriteEffects = SpriteEffects.FlipVertically;
            this.Info.bounce        = false;
            this.Info.manual        = true;
            Thread t = new Thread(new ThreadStart(delegate()
            {
                this.Info.velocity.Y = -30;
                Thread.Sleep(200);
                this.Info.velocity.Y = -10;
                Thread.Sleep(50);
                this.Info.velocity.Y = 10;
                Thread.Sleep(50);
                this.Info.velocity.Y = 30;
                Thread.Sleep(200);
                this.Info.velocity.Y = 50;
                Thread.Sleep(1000);
                SpriteLayer.CollisionLayer.RemoveSprite(this);
            }));

            t.IsBackground = true;
            t.Start();
        }
示例#6
0
 public override void Enter(StateMario previousState)
 {
     base.Enter(previousState);
     this.StateMachine.Mario.SetSpriteState(SpriteStates.Sprites.JUMPING);
     this.StateMachine.Mario.Info.velocity.Y = -8.5f;
     SoundFactory.PlaySoundEffect(SoundFactory.Jump());
 }
示例#7
0
        public void LandOnKoopa()
        {
            SoundFactory.PlaySoundEffect(SoundFactory.Kick());

            if (this.SpriteState == SpriteStates.Sprites.JUMPING)
            {
                this.SetSheetState(SpriteStates.Sheets.NORMAL);
                this.SetSpriteState(SpriteStates.Sprites.WALKING);
                this.Move();
            }
            else if (this.SpriteState == SpriteStates.Sprites.WALKING)
            {
                int walkingSpriteHeight = this.Info.spriteHeight;
                this.SetSpriteState(SpriteStates.Sprites.SHELLED);
                this.SetSheetState(SpriteStates.Sheets.SHELL);
                this.Info.velocity.X = 0;
            }
            else
            {
                if (this.Info.velocity.X < 3)
                {
                    this.Info.velocity.X = 3;
                }
                else
                {
                    this.Info.velocity.X = 0;
                }
            }
        }
示例#8
0
 public override void ReceiveMushroom()
 {
     SoundFactory.PlaySoundEffect(SoundFactory.PowerUp());
     if (this.PreviousState is StatePowerupNormal)
     {
         this.StateMachine.Mario.SetSheetState(SpriteStates.Sheets.STAR_SUPER);
         this.PreviousState = this.StateMachine.Super;
     }
 }
        public override void Handle()
        {
            if (SpriteLayer.CollisionLayer.Sprites.Contains(this))
            {
                if (this.item == null && this.game.Mario.Info.spriteHeight > (16 * this.game.Mario.Info.scale))
                {
                    if (this.SheetState != SpriteStates.Sheets.USED)
                    {
                        Console.WriteLine("no item and mario isn't little. Breaking brick");

                        SpriteBrokenBrick brokenBrick  = new SpriteBrokenBrick(game, 0);
                        SpriteBrokenBrick brokenBrick2 = new SpriteBrokenBrick(game, 1);
                        SpriteBrokenBrick brokenBrick3 = new SpriteBrokenBrick(game, 2);
                        SpriteBrokenBrick brokenBrick4 = new SpriteBrokenBrick(game, 3);

                        SoundFactory.PlaySoundEffect(SoundFactory.BrickBreak());

                        brokenBrick.Info.position.X = this.Info.position.X;
                        brokenBrick.Info.position.Y = this.Info.position.Y;

                        brokenBrick2.Info.position.X = this.Info.position.X;
                        brokenBrick2.Info.position.Y = this.Info.position.Y;

                        brokenBrick3.Info.position.X = this.Info.position.X;
                        brokenBrick3.Info.position.Y = this.Info.position.Y;

                        brokenBrick4.Info.position.X = this.Info.position.X;
                        brokenBrick4.Info.position.Y = this.Info.position.Y;


                        SpriteLayer.CollisionLayer.AddSprite(brokenBrick);
                        SpriteLayer.CollisionLayer.AddSprite(brokenBrick2);
                        SpriteLayer.CollisionLayer.AddSprite(brokenBrick3);
                        SpriteLayer.CollisionLayer.AddSprite(brokenBrick4);

                        SpriteLayer.CollisionLayer.RemoveSprite(this);
                    }
                    else
                    {
                        this.Bump();
                    }
                }
                else
                {
                    this.Bump();

                    Console.WriteLine("Either there's an item, or mario is little.");
                    if (this.item != null)
                    {
                        this.RevealItem();
                    }
                }
            }
        }
示例#10
0
        public void Die()
        {
            SoundFactory.PlaySoundEffect(SoundFactory.Kick());

            Thread t = new Thread(new ThreadStart(delegate()
            {
                this.Info.velocity.Y = -6;
                Thread.Sleep(1000);
                SpriteLayer.CollisionLayer.RemoveSprite(this);
            }));

            t.IsBackground = true;
            t.Start();
        }
示例#11
0
        //Jumped on by Mario.
        public void GetStomped()
        {
            SoundFactory.PlaySoundEffect(SoundFactory.Kick());

            Console.WriteLine("Killing Goomba");
            this.SetSheetState(SpriteStates.Sheets.NORMAL);
            this.SetSpriteState(SpriteStates.Sprites.DEAD);
            this.Info.velocity.X = 0;
            Thread t = new Thread(new ThreadStart(delegate()
            {
                Thread.Sleep(1000);
                SpriteLayer.CollisionLayer.RemoveSprite(this);
            }));

            t.IsBackground = true;
            t.Start();
        }
示例#12
0
 public void OnCollision(Direction direction, SpriteCollection other, Rectangle intersection)
 {
     if (other is SpriteMario)
     {
         SpriteMario mario = other as SpriteMario;
         SpriteLayer.CollisionLayer.RemoveSprite(this);
         if (this.oneUp)
         {
             mario.lives++;
             SoundFactory.PlaySoundEffect(SoundFactory.OneUp());
         }
         else
         {
             mario.StateMachinePowerup.CurrentState.ReceiveMushroom();
             mario.points += 1000;
             this.game.pointGenerator.Add(1000, mario);
         }
     }
 }
示例#13
0
        public void OnCollision(Direction direction, SpriteCollection other, Rectangle intersection)
        {
            if (other is SpriteMario)
            {
                SpriteMario mario = other as SpriteMario;
                if (SpriteLayer.CollisionLayer.Sprites.Contains(this))
                {
                    mario.coins++;
                    mario.points += 200;
                    this.game.pointGenerator.Add(200, this);

                    if (mario.coins / mario.nextLife == 100)
                    {
                        mario.lives++;
                        mario.nextLife++;
                    }

                    SoundFactory.PlaySoundEffect(SoundFactory.Coin());
                }
                SpriteLayer.CollisionLayer.RemoveSprite(this);
            }
        }
示例#14
0
        public static void Win()
        {
            Console.WriteLine("We won!");
            MediaPlayer.Stop();

            SoundFactory.PlaySoundEffect(SoundFactory.YouWin());

            Task.Factory.StartNew(delegate()
            {
                Thread.Sleep(7200);
                SpriteLayer.YouWinLayer.AddSprite(SpriteLayer.YouWinLayer.youWin);
                int dy = 250;
                SpriteLayer.YouWinLayer.youWin.Info.bounds = new Rectangle(SpriteLayer.YouWinLayer.youWin.Info.x - 2, SpriteLayer.YouWinLayer.youWin.Info.y - dy, SpriteLayer.YouWinLayer.youWin.Info.spriteWidth + 2, SpriteLayer.YouWinLayer.youWin.Info.spriteHeight + dy);
                SpriteLayer.YouWinLayer.youWin.SetPosition(SpriteLayer.YouWinLayer.youWin.Info.x, SpriteLayer.YouWinLayer.youWin.Info.y - dy);
                SpriteLayer.YouWinLayer.youWin.Info.acceleration.Y = 0.15f;

                foreach (InputController ic in SpriteLayer.CollisionLayer.InputControllers)
                {
                    ic.Paused = true;
                }
            });
        }
示例#15
0
        public override void OnPress(int key)
        {
            SoundFactory.PlaySoundEffect(SoundFactory.Pause());

            if (MediaPlayer.State == MediaState.Playing)
            {
                MediaPlayer.Pause();
            }
            else
            {
                MediaPlayer.Resume();
            }

            foreach (SpriteLayer layer in this.game.Layers)
            {
                layer.Paused = !layer.Paused;
            }

            foreach (InputController ic in this.toPause)
            {
                ic.Paused = !ic.Paused;
            }
        }
示例#16
0
        public void Bump()
        {
            if (this.SheetState == SpriteStates.Sheets.USED)
            {
                return;
            }
            if (!this.Bumping)
            {
                Console.WriteLine("Bumping the block.");
                this.Bumping = true;

                SoundFactory.PlaySoundEffect(SoundFactory.BlockBump());

                if (this.SheetState == SpriteStates.Sheets.HIDDEN)
                {
                    this.SetSheetState(SpriteStates.Sheets.QUESTION);
                }

                new Thread(new ThreadStart(delegate()
                {
                    Console.WriteLine("Starting bump, current spriteState: {0}", this.SpriteState);
                    int startY           = this.Info.y;
                    this.Info.velocity.Y = -1;
                    Thread.Sleep(100);
                    this.Info.velocity.Y = 1;
                    Thread.Sleep(100);
                    this.Info.velocity.Y = 0;
                    this.Info.velocity.X = 0;
                    this.Bumping         = false;
                    this.Info.position.Y = startY;
                })).Start();
            }
            else
            {
                Console.WriteLine("Bump is busy!");
            }
        }
示例#17
0
 public override void TakeDamage()
 {
     this.StateMachine.Normal.Enter(this);
     SoundFactory.PlaySoundEffect(SoundFactory.PowerDown());
 }
示例#18
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();
            }
        }