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)
        {
            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;
        }