Exemplo n.º 1
0
 private void Jump(WallMap wallMap)
 {
     if (velocity.Y > 0)
     {
         PlayerState = State.fall;
     }
     isJumping = false;
     if (playerLeft == true)
     {
         MoveLeft();
         objectAnimated.Effect = SpriteEffects.FlipHorizontally;
     }
     if (playerRight == true)
     {
         MoveRight();
         objectAnimated.Effect = SpriteEffects.None;
     }
     //wall jump
     if (playerJump && CanWallJump(wallMap) != Rectangle.Empty)
     {
         wallDir     = (int)direction.X;
         PlayerState = State.wallJump;
         velocity.Y  = 0;
     }
 }
Exemplo n.º 2
0
        public override void Update(List <GameObject> objects, WallMap wallMap, GameTime gametime)
        {
            if (HUD.canMove == true)
            {
                UpdateMovement(objects, wallMap);
            }

            //are we on the ground
            var testRect = OnGround(wallMap);

            if (testRect != Rectangle.Empty)
            {
                isOnGround = true;
            }
            else
            {
                isOnGround = false;
            }

            //reset jumping bool
            if (OnGround(wallMap) != Rectangle.Empty)
            {
                isJumping = false;
            }
            base.Update(objects, wallMap, gametime);

            pastBoundingBoxBottom = BoundingBox.Bottom;
        }
Exemplo n.º 3
0
        private void Attack(List <GameObject> objects, WallMap wallMap)
        {
            if (attackTimer > maxTimer * (3 / 4) || attackTimer <= 0)
            {
                damageObject.StartTimer();
                damageObject.active = true;
                attackTimer         = maxTimer;
            }

            damageObject.position = position + (new Vector2(18 + (Math.Abs(velocity.X) * 2), 0) * direction);

            if (!isOnGround && !isOnStairs && !isWallJumping)
            {
                if (playerLeft == true)
                {
                    MoveLeft();
                    objectAnimated.Effect = SpriteEffects.FlipHorizontally;
                }
                if (playerRight == true)
                {
                    MoveRight();
                    objectAnimated.Effect = SpriteEffects.None;
                }
            }
            else if (isOnGround)
            {
                velocity.X = TendToZero(velocity.X, friction);
            }
        }
Exemplo n.º 4
0
        private void UpdateMovement(List <GameObject> objects, WallMap wallMap)
        {
            if (canCollide == true && (velocity.X != 0) && collision.CheckCollisions(this, wallMap, objects, true) == true)
            {
                velocity.X = 0;
            }
            position.X += velocity.X;

            if (canCollide == true && (velocity.Y != 0) && collision.CheckCollisions(this, wallMap, objects, false) == true)
            {
                velocity.Y = 0;
            }
            position.Y += velocity.Y;

            //check if should apply gravity
            if (applyGravity == true)
            {
                ApplyGravity(wallMap);
            }

            // friction on Y if not using gravity
            if (applyGravity == false)
            {
                velocity.Y = TendToZero(velocity.Y, friction);
            }
        }
Exemplo n.º 5
0
        private void Walk(WallMap wallMap)
        {
            //stop moving
            velocity.X = TendToZero(velocity.X, friction);
            velocity.Y = TendToZero(velocity.X, friction);

            if (playerLeft == true)
            {
                MoveLeft();
                objectAnimated.Effect = SpriteEffects.FlipHorizontally;
            }
            if (playerRight == true)
            {
                MoveRight();
                objectAnimated.Effect = SpriteEffects.None;
            }
            if (playerUp == true)
            {
                MoveUp();
                objectAnimated.Effect = SpriteEffects.None;
            }
            if (playerDown == true)
            {
                MoveDown();
                objectAnimated.Effect = SpriteEffects.None;
            }
            if (!playerLeft && !playerRight && !playerUp && !playerDown)
            {
                PlayerState = State.idle;
            }
        }
Exemplo n.º 6
0
        private void Idle(WallMap wallMap)
        {
            //stop moving
            velocity.X = TendToZero(velocity.X, friction);
            velocity.Y = TendToZero(velocity.X, friction);

            //switch to walk
        }
Exemplo n.º 7
0
        private void Walk(WallMap wallMap)
        {
            if (playerLeft == true)
            {
                MoveLeft();
                objectAnimated.Effect = SpriteEffects.FlipHorizontally;
            }
            if (playerRight == true)
            {
                MoveRight();
                objectAnimated.Effect = SpriteEffects.None;
            }
            //switch to jump
            if (playerJump == true && isJumping == false)
            {
                velocity.Y -= jumpHeight;
                PlayerState = State.jump;
                isJumping   = true;
            }
            if (isOnGround == false)
            {
                PlayerState = State.fall;
            }


            //check to see if we are moving
            if (playerLeft == false && playerRight == false)
            {
                PlayerState = State.idle;
            }

            if (playerJump == true && isJumping == false)
            {
                velocity.Y -= jumpHeight;
                PlayerState = State.jump;
            }

            // climb stairs if contacting
            if (playerUp == true)
            {
                var stairTest = AtBottomOfStairs(wallMap);
                if (stairTest != Rectangle.Empty)
                {
                    isOnStairs  = true;
                    PlayerState = State.stairs;
                }
            }
            if (playerDown == true)
            {
                var stairTest = AtTopOfStairs(wallMap);
                if ((stairTest != Rectangle.Empty) && (isOnGround))
                {
                    isOnStairs  = true;
                    PlayerState = State.stairs;
                }
            }
        }
Exemplo n.º 8
0
 public override void Update(List <GameObject> _objects, WallMap wallMap, GameTime gameTime)
 {
     if (rupeeCount >= 100)
     {
         rupeeCount -= 100;
     }
     RupeeAddition();
     //textBox.Update(_objects, wallMap, gameTime);
     base.Update(_objects, wallMap, gameTime);
 }
Exemplo n.º 9
0
 private void Duck(WallMap wallMap)
 {
     velocity.X         = TendToZero(velocity.X, friction);
     boundingBoxTopLeft = duckBoundingBox;
     if (playerDown == false)
     {
         boundingBoxTopLeft = standingBoundingBox;
         PlayerState        = State.idle;
     }
 }
Exemplo n.º 10
0
        protected Rectangle OnGround(WallMap wallMap)
        {
            Rectangle futureBoundingBox = new Rectangle((int)((BoundingBox.X)),
                                                        (int)((BoundingBox.Y) + (1)),
                                                        (int)(BoundingBox.Width),
                                                        (int)(BoundingBox.Height));


            return(wallMap.CheckCollision(futureBoundingBox));
        }
Exemplo n.º 11
0
        protected Rectangle AtTopOfStairs(WallMap wallMap)
        {
            Rectangle futureBoundingBox = new Rectangle((int)((BoundingBox.X)),
                                                        (int)((BoundingBox.Y) + BoundingBox.Height + 1),
                                                        (int)(BoundingBox.Width),
                                                        (int)(2));


            return(wallMap.StairCollision(futureBoundingBox));
        }
Exemplo n.º 12
0
 private void DuckAttack(List <GameObject> objects, WallMap wallMap)
 {
     if (attackTimer <= 0)
     {
         damageObject.position = position + new Vector2(0, 6) + (new Vector2(18, 0) * direction);
         damageObject.StartTimer();
         damageObject.active = true;
         attackTimer         = maxTimer;
     }
 }
Exemplo n.º 13
0
        protected Rectangle CanWallJump(WallMap wallMap)
        {
            Rectangle futureBoundingBox = new Rectangle((int)(BoundingBox.X + (1 * direction.X)),
                                                        (int)(BoundingBox.Y + 4),
                                                        (int)(BoundingBox.Width),
                                                        (int)(BoundingBox.Height - 14));


            return(wallMap.CheckCollision(futureBoundingBox));
        }
Exemplo n.º 14
0
        protected Rectangle InDoor(WallMap wallMap)
        {
            Rectangle futureBoundingBox = new Rectangle((int)((BoundingBox.X)),
                                                        (int)((BoundingBox.Y)),
                                                        (int)(BoundingBox.Width),
                                                        (int)(BoundingBox.Height));


            return(wallMap.CheckForDoor(futureBoundingBox));
        }
Exemplo n.º 15
0
        protected Rectangle AtBottomOfStairs(WallMap wallMap)
        {
            Rectangle futureBoundingBox = new Rectangle((int)((BoundingBox.X)),
                                                        (int)((BoundingBox.Y + 20)),
                                                        (int)(BoundingBox.Width),
                                                        (int)(BoundingBox.Height - 20));


            return(wallMap.StairCollision(futureBoundingBox));
        }
Exemplo n.º 16
0
        public void ApplyGravity(WallMap wallMap)
        {
            if (isJumping == true || (OnGround(wallMap) == Rectangle.Empty && isJumping == false))
            {
                velocity.Y += gravity;

                if (velocity.Y > terminalVelocity)
                {
                    velocity.Y = terminalVelocity;
                }
            }
        }
Exemplo n.º 17
0
        private void Idle(WallMap wallMap)
        {
            //stop moving
            velocity.X = TendToZero(velocity.X, friction);
            velocity.Y = TendToZero(velocity.X, friction);

            //switch to walk
            if (playerLeft || playerRight || playerUp || playerDown)
            {
                PlayerState = State.walk;
            }
        }
Exemplo n.º 18
0
 public override void Update(List <GameObject> objects, WallMap wallMap, GameTime gametime)
 {
     if (timer > 0 && active == true)
     {
         timer--;
         CheckCollision(objects, wallMap);
     }
     else
     {
         active = false;
     }
     damageBoundingBox.X = (int)position.X;
     damageBoundingBox.Y = (int)position.Y;
     base.Update(objects, wallMap, gametime);
 }
Exemplo n.º 19
0
        private void Walk(WallMap wallMap)
        {
            //stop moving
            if (direction.X == 1)
            {
                MoveRight();
                objectAnimated.Effect = SpriteEffects.None;
            }
            else
            {
                MoveLeft();
                objectAnimated.Effect = SpriteEffects.FlipHorizontally;
            }

            velocity.X = TendToZero(velocity.X, friction);
        }
Exemplo n.º 20
0
        private void StateMachine(State playerState, List <GameObject> objects, WallMap wallMap)
        {
            switch (playerState)
            {
            case State.idle:
                Idle(wallMap);
                objectAnimated.Play("idle");
                break;

            case State.walk:
                Walk(wallMap);
                objectAnimated.Play("walk");
                break;

            default:
                PlayerState = State.idle;
                break;
            }
        }
Exemplo n.º 21
0
 protected Rectangle OneEdgeOfGround(WallMap wallMap)
 {
     if (direction.X == 1)
     {
         Rectangle futureBoundingBox = new Rectangle((int)((BoundingBox.X + BoundingBox.Width)),
                                                     (int)((BoundingBox.Y + 1)),
                                                     (int)(BoundingBox.Width),
                                                     (int)(BoundingBox.Height));
         return(wallMap.CheckCollision(futureBoundingBox));
     }
     else
     {
         Rectangle futureBoundingBox = new Rectangle((int)((BoundingBox.X - BoundingBox.Width)),
                                                     (int)((BoundingBox.Y) + (1)),
                                                     (int)(BoundingBox.Width),
                                                     (int)(BoundingBox.Height));
         return(wallMap.CheckCollision(futureBoundingBox));
     }
 }
Exemplo n.º 22
0
        private void WallAttack(List <GameObject> objects, WallMap wallMap)
        {
            velocity.Y -= 0.28f;

            if (attackTimer <= 0)
            {
                damageObject.position = position + new Vector2(0, 6) + (new Vector2(18, 0) * direction);
                damageObject.StartTimer();
                damageObject.active = true;
                attackTimer         = maxTimer;
            }

            damageObject.position = position + (new Vector2(18 + (Math.Abs(velocity.X) * 2), 0) * direction);

            if (isOnGround)
            {
                PlayerState   = State.wallJump;
                isWallJumping = false;
            }
        }
Exemplo n.º 23
0
 private void CheckCollision(List <GameObject> objects, WallMap wallMap)
 {
     for (int i = 0; i < objects.Count; i++)
     {
         if (objects[i].objectType == "Enemy" && objects[i].CheckCollision(damageBoundingBox) == true)
         {
             if (objects[0].position.X > objects[i].BoundingBox.X)
             {
                 objects[0].knockbackDir.X = 1;
             }
             else
             {
                 objects[0].knockbackDir.X = -1;
             }
             active = false;
             objects[0].velocity.X = 0;
             objects[0].velocity   = objects[i].knockback * objects[0].knockbackDir;
             objects[i].isHurt     = true;
         }
     }
 }
Exemplo n.º 24
0
        // individual player states:

        private void Idle(WallMap wallMap)
        {
            //switch to walk
            if (playerLeft == true || playerRight == true)
            {
                PlayerState = State.walk;
            }
            //switch to jump
            if (playerJump == true && isJumping == false)
            {
                velocity.Y -= jumpHeight;
                PlayerState = State.jump;
                isJumping   = true;
            }
            //switch to duck
            if (playerDown == true)
            {
                PlayerState = State.duck;
            }

            // climb stairs if contacting
            if (playerUp == true)
            {
                var stairTest = AtBottomOfStairs(wallMap);
                if (stairTest != Rectangle.Empty)
                {
                    isOnStairs  = true;
                    PlayerState = State.stairs;
                }
            }
            if (playerDown == true)
            {
                var stairTest = AtTopOfStairs(wallMap);
                if ((stairTest != Rectangle.Empty) && (isOnGround))
                {
                    isOnStairs  = true;
                    PlayerState = State.stairs;
                }
            }
        }
Exemplo n.º 25
0
        public override void Update(List <GameObject> objects, WallMap wallMap, GameTime gametime)
        {
            if (HUD.canMove)
            {
                //Check Input
                PlayerInput();

                //FSM Check
                StateMachine(PlayerState, objects, wallMap);

                base.Update(objects, wallMap, gametime);

                //are we in a door

                var testRectDoor = InDoor(wallMap);
                if (testRectDoor != Rectangle.Empty)
                {
                    applyGravity = false;
                }
            }
            objectSprite.Position = position;
            objectAnimated.Update(gametime);
        }
Exemplo n.º 26
0
        private void Stairs(WallMap wallMap)
        {
            StairMaster(wallMap);

            if (direction.X < 0)
            {
                objectAnimated.Effect = SpriteEffects.FlipHorizontally;
            }
            else
            {
                objectAnimated.Effect = SpriteEffects.None;
            }

            //stop animating if not moving
            if (!playerUp && !playerDown && !playerLeft && !playerRight)
            {
                stopAnimating = true;
            }
            else
            {
                stopAnimating = false;
            }
        }
Exemplo n.º 27
0
        private void WallJump(WallMap wallMap)
        {
            //applyGravity = false;
            isWallJumping = false;
            velocity.Y   -= 0.28f;
            isJumping     = false;

            if (playerJump)
            {
                velocity.Y  = 0;
                velocity.Y -= 5f;
                velocity.X -= jumpHeight / 4 * direction.X;
                PlayerState = State.jump;
                direction   = -direction;
                isJumping   = true;
            }
            // adjust facing direction
            if (playerLeft)
            {
                direction.X           = -1;
                objectAnimated.Effect = SpriteEffects.FlipHorizontally;
            }
            if (playerRight)
            {
                direction.X           = 1;
                objectAnimated.Effect = SpriteEffects.None;
            }

            if ((!playerRight && !playerLeft) || (CanWallJump(wallMap) == Rectangle.Empty) || (wallDir != (int)direction.X))
            {
                PlayerState = State.fall;
            }
            if (isOnGround)
            {
                PlayerState = State.idle;
            }
        }
Exemplo n.º 28
0
        private void Fall(WallMap wallMap)
        {
            if (isOnGround == true)
            {
                isJumping   = false;
                PlayerState = State.idle;
            }

            if (playerLeft == true)
            {
                MoveLeft();
            }
            if (playerRight == true)
            {
                MoveRight();
            }
            //walljump
            if (CanWallJump(wallMap) != Rectangle.Empty && (playerLeft || playerRight))
            {
                wallDir     = (int)direction.X;
                PlayerState = State.wallJump;
                velocity.Y  = 0;
            }

            // climb stairs if contacting
            if (playerUp == true)
            {
                var stairTest = AtBottomOfStairs(wallMap);
                if (stairTest != Rectangle.Empty)
                {
                    isOnStairs   = true;
                    jumpOnStairs = true;
                    PlayerState  = State.stairs;
                }
            }
        }
Exemplo n.º 29
0
        public override void Update(List <GameObject> objects, WallMap wallMap, GameTime gametime)
        {
            if (HUD.canMove)
            {
                //FSM Check
                StateMachine(EnemyState, objects, wallMap);

                base.Update(objects, wallMap, gametime);

                if (OneEdgeOfGround(wallMap) == Rectangle.Empty || position.X == previousX)
                {
                    velocity.X = 0f;
                    direction  = -direction;
                }

                if (health <= 0)
                {
                    objects.Remove(this);
                }
            }
            objectSprite.Position = position;
            objectAnimated.Update(gametime);
            previousX = position.X;
        }
Exemplo n.º 30
0
 public virtual void Update(List <GameObject> objects, WallMap wallMap, GameTime gametime)
 {
 }