Ejemplo n.º 1
0
        public void Update(KeyboardState keyboardState, GameTime gameTime)
        {
            playerForm prevForm = playerForm;

            if (keyboardState.IsKeyDown(Keys.Z) && playerForm != playerForm.NORMAL)
            {
                playerForm = playerForm.NORMAL;
                playerTexture = normalTexture;
                morphCount++;
            }
            else if (keyboardState.IsKeyDown(Keys.X) && playerForm != playerForm.SQUARE)
            {
                playerForm = playerForm.SQUARE;
                playerTexture = squareTexture;
                morphCount++;
            }
            else if (keyboardState.IsKeyDown(Keys.C) && playerForm != playerForm.BALL)
            {
                playerForm = playerForm.BALL;
                playerTexture = ballTexture;
                morphCount++;
            }
            else if (playerForm == playerForm.NORMAL && keyboardState.IsKeyDown(Keys.Right))
            {
                movement = 1.0f;
                direction = 1;
            }
            else if (playerForm == playerForm.NORMAL && keyboardState.IsKeyDown(Keys.Left))
            {
                movement = -1.0f;
                direction = -1;
            }

            isJumping = (!wasJumping &&  (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.Space)));

            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            Vector2 prevPos = position;

            if (playerForm == playerForm.NORMAL)
            {
                velocity = DoWalk(velocity,gameTime);

                velocity.Y = DoJump(velocity.Y, gameTime);

            } else if (playerForm == playerForm.BALL)
            {

                velocity = DoRoll(velocity, gameTime, prevForm);
            }
            else if (playerForm == playerForm.SQUARE)
            {
                velocity.Y = MathHelper.Clamp(velocity.Y + gravityAcceleration * elapsed, -maxFallSpeed, maxFallSpeed);
            }

            if (IsOnGround)
                velocity.X *= groundDragFactor;
            else
                velocity.X *= airDragFactor;

            velocity.X = MathHelper.Clamp(velocity.X, -maxMoveSpeed, maxMoveSpeed);

            position += velocity * elapsed;
            position = new Vector2((float)Math.Round(position.X), (float)Math.Round(position.Y));

            HandleCollisions();

            if (position.X == prevPos.X)
                velocity.X = 0;

            if (position.Y == prevPos.Y)
            {
                wasJumping = false;
                velocity.Y = 0;
            }

            if (animationSet[action].Active == false)
            {
                if (action == "c2b")
                {
                    action = "ball";
                }
                if (action == "b2c")
                {
                    action = "char";
                }

                if (action == "c2s")
                {
                    action = "square";
                }
                if (action == "s2c")
                {
                    action = "char";
                }

                if (action == "b2s")
                {
                    action = "square";
                }
                if (action == "s2b")
                {
                    action = "ball";
                }
            }

            if (playerForm == playerForm.NORMAL)
            {
                if (action == "ball")
                {
                    action = "b2c";
                    activate();
                } else if (action == "square")
                {
                    action = "s2c";
                    activate();
                } else if (action == "b2c")
                {
                    action = "b2c";
                } else if (action == "s2c")
                {
                    action = "s2c";
                } else if (movement > 0.5f || movement < -0.5f)
                {
                    action = "walk";
                } else if (isJumping)
                {
                    action = "jump";
                } else
                {
                    action = "char";
                }
            }

            if (playerForm == playerForm.BALL)
            {
                if (action == "char")
                {
                    action = "c2b";
                    activate();
                }
                if (action == "square")
                {
                    action = "s2b";
                    activate();
                }
            }

            if (playerForm == playerForm.SQUARE)
            {
                if (action == "char")
                {
                    action = "c2s";
                    activate();
                }
                if (action == "ball")
                {
                    action = "b2s";
                    activate();
                }
            }

            flipped = direction == 1 ? false : true;

            animationSet[action].Position = position;

            animationSet[action].Update(gameTime);

            movement = 0.0f;
            isJumping = false;
        }
Ejemplo n.º 2
0
        //
        /////////////////////////////////////////////////////////////////////////
        public void Initialize(Texture2D normalTexture,Texture2D squareTexture,Texture2D ballTexture, Vector2 pPosition, Rectangle winRect, Level pLevel)
        {
            playerTexture = normalTexture;

            this.normalTexture = normalTexture;
            this.squareTexture = squareTexture;
            this.ballTexture = ballTexture;

            playerForm = playerForm.NORMAL;

            rectangle = winRect;

            position = pPosition;

            velocity = Vector2.Zero;

            active = true;

            health = 100;

            level = pLevel;

            direction = 1;

            jumpSound = level.content.Load<SoundEffect>("Sound\\PlayerJump");

            action = "char";

            scale = new Vector2(0.08333f,0.06667f);

            loadAnimationSet();
            //
            ///////////////
        }
Ejemplo n.º 3
0
        public void Reset(Vector2 position)
        {
            this.position = position;

            isOnGround = false;
            wasJumping = false;
            isJumping = false;
            reachedExit = false;
            isOnMovingPlatform = false;
            wasOnMovingPlatform = false;

            playerForm = playerForm.NORMAL;
            playerTexture = normalTexture;

            jumpTime = 0.0f;
            rollingTime = 0.0f;

            prevBottom = 999 ;
            prevTop = -1;
            prevLeft = -1;
            prevRight = 999;

            morphCount = 0;
        }
Ejemplo n.º 4
0
        public Vector2 DoRoll(Vector2 velocity, GameTime gameTime, playerForm prevForm)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (prevForm != playerForm)
                rollingTime = 0.0f;

            if (isOnIncline != 0 && velocity.X == 0)
            {
                velocity.X += isOnIncline * ballMoveAcceleration * elapsed;
                direction = isOnIncline;
            }
            else if (isOnIncline != 0 && velocity.X != 0)
            {
                if (prevForm != playerForm)
                {
                    velocity.X += isOnIncline * ballMoveAcceleration * elapsed;
                    direction = isOnIncline;
                }
                else
                {
                    if (rollingTime == 0.0)
                        groundVelocity = velocity.X * 2.0f;

                    rollingTime += elapsed;

                    if (0.0f < rollingTime && rollingTime <= maxGroundRollingTime)
                        velocity.X = groundVelocity * (1.0f - (rollingTime / maxGroundRollingTime));

                }
            }
            else if (isOnGround && velocity.X != 0)
            {
                //if (prevForm == playerForm)
                //    velocity.X += direction * ballMoveAcceleration * elapsed;

                if (rollingTime == 0.0)
                    groundVelocity = velocity.X * 1.5f;

                rollingTime += elapsed;

                if (0.0f < rollingTime && rollingTime <= maxGroundRollingTime)
                    velocity.X = groundVelocity * (1.0f - (rollingTime / maxGroundRollingTime));
            }

            if (isOnIncline != 0)
            {
                if (isOnIncline == direction)
                    velocity.X *= inclineCalcFactorDown;
                else
                    velocity.X *= inclineCalcFactorUp;
            }

            velocity.Y = MathHelper.Clamp(velocity.Y + gravityAcceleration * elapsed, -maxFallSpeed, maxFallSpeed);

            return velocity;
        }