Ejemplo n.º 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState state     = Keyboard.GetState();
            var           padState  = GamePad.GetState(PlayerIndex.One);
            var           collision = new Collision(_tileArray);
            var           colCheck  = collision.CheckCollision(_player, _world);

            _tileArray = _world._activeRoom;
            var playerMoving = _player.Input(state, padState, colCheck);

            // TODO: Add your update logic here
            _world.WorldUpdate();
            score++;
            if (playerMoving)
            {
                _player.animatedSprite.Update();
            }
            if (_itemDrop != null)
            {
                _itemDrop.animatedSprite.Update();
            }
            //_enemy.animatedSprite.Update();
            base.Update(gameTime);

            //var inDistance = checkDistance(_enemy.position, _player.position);
            //_enemy.Walk(_player.position, inDistance);
            if (_itemDrop != null)
            {
                var inDistance = checkDistance(_itemDrop.position, _player.position);
                var pickUp     = _itemDrop.PickUp(_player, inDistance);
                if (pickUp)
                {
                    _itemDrop = null;
                }
            }

            _camera.Update(_player.position);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            state = Keyboard.GetState();

            if (state.IsKeyDown(Keys.O))
            {
                penumbra.AmbientColor = new Color(penumbra.AmbientColor.R + 1, penumbra.AmbientColor.G + 1, penumbra.AmbientColor.B + 1);
            }
            if (state.IsKeyDown(Keys.I))
            {
                penumbra.AmbientColor = new Color(penumbra.AmbientColor.R - 1, penumbra.AmbientColor.G - 1, penumbra.AmbientColor.B - 1);
            }

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here

            if (Keyboard.GetState().IsKeyDown(Keys.T) && !prevState.IsKeyDown(Keys.T) && !EditorGui.saveText.isActive)
            {
                running = !running;
            }



            if (!running)
            {
                EditorGui.Update(GraphicsDevice);
            }
            if (running)
            {
                WorldInfo.updateGravity();
                if (WorldInfo.angle == 0)
                {
                    if (WorldInfo.angle == 0)
                    {
                        world.frameInit();

                        //if (!TextDialog.isInDialog)
                        player.Input((float)gameTime.ElapsedGameTime.TotalSeconds);


                        //if (!TextDialog.isInDialog)

                        if (!TextDialog.isInDialog)
                        {
                            world.update(GraphicsDevice);
                        }
                        FreeGravityBox.setAllSpeedChains();

                        world.checkForWalls();
                        player.update(0);
                        if (!TextDialog.isInDialog)
                        {
                            world.applyChanges(GraphicsDevice);
                        }


                        world.correctDownCollisions();
                        world.correctRightCollisions();
                        world.correctLeftCollisions();



                        //if(Math.Abs(player.fallSpeed) >= Math.Abs(player.speed)) {

                        player.correctUpCollision();
                        player.correctDownCollision();
                        player.correctRightCollision();
                        player.correctLeftCollision();

                        /* if (player.collidesLeft(true) && player.isGrounded().collided)
                         *   player.decideCollisionCorrection(true);
                         * else if (player.collidesRight(true) && player.isGrounded().collided)
                         *   player.decideCollisionCorrection(false);
                         *
                         * if (player.collidesRight(true))
                         *   player.correctRightCollision();
                         * else if (player.collidesLeft(true))
                         *   player.correctLeftCollision();
                         * if (player.isGrounded().collided)
                         *   player.correctDownCollision();
                         * if (player.collidesUp().collided)
                         *   player.correctUpCollision();*/
                        //player.correctDownCollision();
                        //  player.correctRightCollision();
                        //player.correctLeftCollision();
                        //} else

                        /*{
                         *  player.correctRightCollision();
                         *  player.correctLeftCollision();
                         *
                         *  player.correctUpCollision();
                         *  player.correctDownCollision();
                         *
                         *
                         * }*/
                        if (!TextDialog.isInDialog)
                        {
                            player.inputGravityChange();
                        }
                    }
                }
            }

            world.cleanDestroyedItems();

            ExplosionHandler.update();


            if (state.IsKeyDown(Keys.Z) && prevState.IsKeyUp(Keys.Z))
            {
                penumbra.Visible = !penumbra.Visible;
            }

            if (state.IsKeyDown(Keys.Y) && prevState.IsKeyUp(Keys.Y))
            {
                bloomEnabled = !bloomEnabled;
            }

            cam.update();
            base.Update(gameTime);

            prevState = state;
        }