示例#1
0
文件: Player.cs 项目: trnktms/ScarFly
        public void Update(Game1 game, ref bool firstEntry)
        {
            if (this.isDead)
            {
                this.Overlayer = new Color(255, 105, 97);
                //Score.GameScore--;
                if (Consts.IsVibrate)
                {
                    this.vibrateController.Start(TimeSpan.FromMilliseconds(50));
                }

                game.gameState = GameState.InEndGameMenu;
                Transitions.ChangeGameState(ref firstEntry);
            }
            else if (this.isEatMoney)
            {
                this.Score.GameScore += 10;
            }

            if (this.isEnd)
            {
                this.Position = new Vector2(this.Position.X + this.Velocity, this.Position.Y);
            }

            TouchCollection touches = TouchPanel.GetState();

            foreach (var touch in touches)
            {
                if (touch.State == TouchLocationState.Pressed)
                {
                    this.PlayerState = PlayerStates.Flying;
                }
                else if (touch.State == TouchLocationState.Released)
                {
                    this.PlayerState = PlayerStates.Falling;
                }
            }

            this.Distance += this.Velocity;
        }
示例#2
0
文件: Game1.cs 项目: trnktms/ScarFly
        protected override void Update(GameTime gameTime)
        {
            switch (gameState)
            {
            //NOTE: LOAD LEVEL
            case GameState.LoadLevel:
                if (firstEntry)
                {
                    player.RePosition();
                    firstEntry = false;
                    Thread loadThread = new Thread(() =>
                    {
                        foreach (PlayerBackground item in backgroundList)
                        {
                            item.RePosition();
                        }
                        string level = LevelHelper.SelectLevel();
                        barriers     = new Barriers(level, 4);
                        barriers.Load(this);
                        moneys = new Moneys(level, 4);
                        moneys.Load(this);
                        modifiers = new Modifiers(level, 4);
                        modifiers.Load(this);

                        collosion = new Collosion(barriers, player, moneys, modifiers, backgroundList);
                        collosion.Load(this);
                        gameState = GameState.Gaming;
                        //Transitions.ChangeGameState(ref firstEntry);
                    });
                    loadThread.Start();
                }
                player.Update(this, ref firstEntry);
                backBackground.Scroll(this);
                foreBackground.Scroll(this);
                walkPlace.Scroll(this);
                break;

            //NOTE: GAMING
            case GameState.Gaming:
                if (firstEntry)
                {
                    firstEntry = false;
                }
                else
                {
                    if (LevelHelper.IsLevelEnd(moneys))
                    {
                        player.isEnd = true;
                        if (player.Position.X >= Consts.PhoneWidth)
                        {
                            Transitions.ChangeGameState(ref firstEntry);
                            gameState = GameState.InEndGameMenu;
                        }
                    }
                    player.Update(this, ref firstEntry);
                    backBackground.Scroll(this);
                    foreBackground.Scroll(this);
                    walkPlace.Scroll(this);
                    barriers.Scroll(this);
                    moneys.Scroll(this);
                    modifiers.Scroll(this);
                    collosion.Update();
                    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                    {
                        gameState  = GameState.InPauseMenu;
                        firstEntry = true;
                    }
                }
                break;

            //NOTE: MAIN MENU
            case GameState.InMainMenu:
                if (firstEntry)
                {
                    player.Score.LoadTotalScore();
                    player.Score.LoadHighScore();
                    mainMenu             = new Menu(mainButtons);
                    player.isDead        = false;
                    player.isEatMoney    = false;
                    player.isEatModifier = false;
                    backBackground.RePosition();
                    foreBackground.RePosition();
                    walkPlace.RePosition();
                    collosion.Reset();
                    firstEntry = false;
                }
                backBackground.Scroll(this);
                foreBackground.Scroll(this);
                walkPlace.Scroll(this);
                gameState = mainMenu.IsTouched(this, TouchPanel.GetState(), gameState, ref firstEntry);
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    this.Exit();
                }
                break;

            //NOTE: PAUSE MENU
            case GameState.InPauseMenu:
                if (firstEntry)
                {
                    pauseMenu  = new Menu(pauseButtons);
                    firstEntry = false;
                }
                gameState = pauseMenu.IsTouched(this, TouchPanel.GetState(), gameState, ref firstEntry);
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    Transitions.ChangeGameState(ref firstEntry);
                    player.Score.GameScore = 0;
                    gameState = GameState.InMainMenu;
                }
                break;

            //NOTE: TUTORIAL
            case GameState.InTutorial:
                backBackground.Scroll(this);
                foreBackground.Scroll(this);
                walkPlace.Scroll(this);
                gameState = tutorialMenu.IsTouched(this, TouchPanel.GetState(), gameState, ref firstEntry);
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    Transitions.ChangeGameState(ref firstEntry);
                    gameState = GameState.InMainMenu;
                }
                break;

            //NOTE: ABOUT
            case GameState.About:
                backBackground.Scroll(this);
                foreBackground.Scroll(this);
                walkPlace.Scroll(this);
                gameState = aboutMenu.IsTouched(this, TouchPanel.GetState(), gameState, ref firstEntry);
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    Transitions.ChangeGameState(ref firstEntry);
                    gameState = GameState.InMainMenu;
                }
                break;

            //NOTE: ENDGAME MENU
            case GameState.InEndGameMenu:
                player.Score.SaveTotalScore();
                player.Score.SaveHighScore();
                gameState = GameState.InMainMenu;
                break;

            default:
                break;
            }

            base.Update(gameTime);
        }