Пример #1
0
        public override void update()
        {
            //Player movement and controls
            player.Acceleration.X = 0;

            if (FlxG.keys.pressed(Keys.Left))
            {
                player.Acceleration.X = -player.MaxVelocity.X * 4;
            }
            if (FlxG.keys.pressed(Keys.Right))
            {
                player.Acceleration.X = player.MaxVelocity.X * 4;
            }

            if (FlxG.keys.pressed(Keys.Space) && player.isTouching(FlxObject.Floor))
            {
                player.Velocity.Y = -player.MaxVelocity.Y / 2;
            }

            if (FlxG.keys.justPressed(Keys.Escape))
            {
                onQuit();
            }


            //Updates all the objects appropriately
            base.update();

            //Check if player collected a coin or coins this frame
            FlxG.overlap(coins, player, getCoin);

            //Check to see if the player touched the exit door this frame
            FlxG.overlap(exit, player, win);

            FlxG.collide(level, player);

            //Check for player lose conditions
            if (player.Y > FlxG.height)
            {
                FlxG.score = 1;                 //sets status.text to "Aww, you died!"
                FlxG.resetState();
            }
        }
        public override void update()
        {
            /*
             * if(_pad.Visible)
             *      _pad.update();
             */

            //save off the current score and update the game state
            int oldScore = FlxG.score;

            base.update();

            //collisions with environment
            FlxG.collide(_blocks, _objects);
            FlxG.overlap(_hazards, _player, overlapped);
            FlxG.overlap(_bullets, _hazards, overlapped);

            //check to see if the player scored any points this frame
            bool scoreChanged = oldScore != FlxG.score;

            //Jammed message
            if ((FlxG.keys.justPressed(Keys.C) /*|| _pad.buttonB.status == FlxButton.Pressed*/) && _player.flickering)
            {
                _jamTimer       = 1;
                _gunjam.Visible = true;
            }
            if (_jamTimer > 0)
            {
                if (!_player.flickering)
                {
                    _jamTimer = 0;
                }
                _jamTimer -= FlxG.elapsed;
                if (_jamTimer < 0)
                {
                    _gunjam.Visible = false;
                }
            }

            if (!_fading)
            {
                //Score + countdown stuffs
                if (scoreChanged)
                {
                    _scoreTimer = 2;
                }
                _scoreTimer -= FlxG.elapsed;
                if (_scoreTimer < 0)
                {
                    if (FlxG.score > 0)
                    {
                        if (FlxG.score > 100)
                        {
                            FlxG.score -= 100;
                        }
                        else
                        {
                            FlxG.score = 0;
                            _player.kill();
                        }
                        _scoreTimer  = 1;
                        scoreChanged = true;

                        //Play loud beeps if your score is low
                        float volume = 0.35f;
                        if (FlxG.score < 600)
                        {
                            volume = 1.0f;
                        }
                        _sfxCount.Volume = volume;
                        _sfxCount.play(true);
                    }
                }

                //Fade out to victory screen stuffs
                if (_spawners.CountLiving() <= 0)
                {
                    _fading = true;
                    FlxG.fade(Color.Black, 3, onVictory);
                }
            }

            //actually update score text if it changed
            if (scoreChanged)
            {
                if (!_player.Alive)
                {
                    FlxG.score = 0;
                }
                _score.text = "" + FlxG.score;
            }
        }