Exemplo n.º 1
0
 public void SetDirectionFacing(DirectionFacing direction)
 {
     if (GetDirectionFacing() != direction)
     {
         FlipSprite();
     }
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Right"))
        {
            switch (CurrentFacingDirection)
            {
            case DirectionFacing.Up:
                CurrentFacingDirection = DirectionFacing.Right;
                break;

            case DirectionFacing.Down:
                CurrentFacingDirection = DirectionFacing.Left;
                break;

            case DirectionFacing.Left:
                CurrentFacingDirection = DirectionFacing.Up;
                break;

            case DirectionFacing.Right:
                CurrentFacingDirection = DirectionFacing.Down;
                break;
            }
        }
        else if (Input.GetButtonDown("Left"))
        {
        }
        else if (Input.GetButtonDown("Up"))
        {
        }
        else if (Input.GetButtonDown("Down"))
        {
        }
    }
Exemplo n.º 3
0
    IEnumerator MoveFromArrow(DirectionFacing Direction)
    {
        yield return(new WaitForSeconds(1f));

        if (Direction == CurrentFacingDirection)
        {
            MoveForward();
        }
        else if (Direction == DirectionFacing.Up)
        {
            StartCoroutine("FaceUp");
        }
        else if (Direction == DirectionFacing.Down)
        {
            StartCoroutine("FaceDown");
        }
        else if (Direction == DirectionFacing.Right)
        {
            StartCoroutine("FaceRight");
        }
        else if (Direction == DirectionFacing.Left)
        {
            StartCoroutine("FaceLeft");
        }
    }
Exemplo n.º 4
0
    // Checks if the player hits a nearby wall using a linecast and given direction
    public bool CheckIfPlayerHitWall(Vector3 start, DirectionFacing direction)
    {
        Vector3      end = start + GetVectorDirection(direction) * linecastMultiplier;
        RaycastHit2D hit = Physics2D.Linecast(start, end, wallMask);

        return(hit ? true : false);
    }
Exemplo n.º 5
0
    void FaceDown(Cell arrowCell)
    {
        //yield return new WaitForSeconds(.5f);
        CurrentFacingDirection = DirectionFacing.Down;
        animator.SetBool("FacingUp", false);
        animator.SetBool("FacingSide", false);
        animator.SetBool("FacingDown", true);
        Vector3 MoveDirection = Vector3.back;
        bool    Move          = CheckForPillar(MoveDirection);

        if (Move)
        {
            if (arrowCell == null)
            {
                MovePosition = transform.position + (MoveDirection * MoveDistance);
            }
            else
            {
                MovePosition = arrowCell.transform.position + (MoveDirection * MoveDistance);
            }
            moveEndTime   = Time.time + moveDuration;
            moveStartTime = Time.time;
        }
        else
        {
            animator.SetTrigger("TurnDown");
        }
    }
Exemplo n.º 6
0
    public void MoveTowards(DirectionFacing DirectionToMove)
    {
        if (Locked)
        {
            return;
        }
        switch (DirectionToMove)
        {
        case DirectionFacing.Right:
            MoveToMyRight();
            break;

        case DirectionFacing.Left:
            MoveToMyLeft();
            break;

        case DirectionFacing.Up:
            MoveForward(null);
            break;

        case DirectionFacing.Down:
            MoveBackWard();
            break;
        }
    }
Exemplo n.º 7
0
        protected void CalculateDirectionFacing(Vector2 DirectionToFace)
        {
            Vector2 location = CenterofSprite;

            if ((location != null) && (DirectionToFace != null))
            {
                float Angle = (float)Math.Atan2((DirectionToFace.Y), (DirectionToFace.X));

                Angle = MathHelper.ToDegrees(Angle);

                if (Angle > -45 && Angle < 45)
                {
                    directionFacing = DirectionFacing.Left;
                }
                else if (Angle > -135 && Angle < -45)
                {
                    directionFacing = DirectionFacing.Up;
                }
                else if (Angle < 135 && Angle > 45)
                {
                    directionFacing = DirectionFacing.Down;
                }
                else
                {
                    directionFacing = DirectionFacing.Right;
                }
            }
        }
Exemplo n.º 8
0
 // Start is called before the first frame update
 void Awake()
 {
     animator         = GetComponent <Animator>();
     currentDirection = DirectionFacing.DOWN;
     startScale       = transform.localScale;
     isAnimating      = true;
 }
Exemplo n.º 9
0
        public bool TryHangingInput(out Climb nextClimb)
        {
            DirectionFacing direction = AddNextClimbs();

            nextClimb = Climb.Down;

            if (_climbHandler.NextClimbs.Any())
            {
                Climb switchedClimb = _climbHandler.SwitchClimbingState(direction, _climbHandler.CurrentClimbingState.PivotCollider != null && _climbHandler.CurrentClimbingState.IsUpright == false);

                if (switchedClimb == Climb.None)
                {
                    return(false);
                }

                if (_climbHandler.CurrentClimbingState.PivotCollider == null || switchedClimb == Climb.Down)
                {
                    MovementState.UnsetPivot();
                    nextClimb = Climb.None;
                }
                else
                {
                    nextClimb = switchedClimb;
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 10
0
        private RaycastHit2D CheckInteractableInFront(DirectionFacing direction)
        {
            const float checkLength = 2f;

            Vector2 castDirection = MovementState.GetSurfaceDirection(direction == DirectionFacing.Left ? DirectionTravelling.Left : DirectionTravelling.Right);

            return(Physics2D.BoxCast(Collider.bounds.center, new Vector2(0.1f, Collider.bounds.size.y), 0, castDirection, checkLength, 1 << LayerMask.NameToLayer(Layers.Interactable)));
        }
Exemplo n.º 11
0
        public DirectionFacing GetDirectionFacing()
        {
            DirectionFacing directionFacing = Transform.localScale.x > 0f
                                ? DirectionFacing.Right
                                : DirectionFacing.Left;

            return(directionFacing);
        }
Exemplo n.º 12
0
    protected override void Start()
    {
        base.Start();

        spriteRend = GetComponent <SpriteRenderer> ();

        attackDamage     = 2;
        blastRadius      = 4.5F;
        startingPosition = transform.position;
        thisObjectFacing = _gameManager.Player.directionFacing;
    }
Exemplo n.º 13
0
 /**
  * Place the robot on the grid.
  */
 public bool PlaceRobot(int x, int y, DirectionFacing facing)
 {
     if (validateRobotPlacement (x, y, "place"))
     {
         _xPosition = x;
         _yPosition = y;
         _directionFacing = facing;
         return true;
     }
     return false;
 }
Exemplo n.º 14
0
    // Use this for initialization
    void Start()
    {
        playerObject             = GameObject.FindGameObjectWithTag("Player");
        myCooldownHandler        = playerObject.GetComponent <CooldownFromAbilitiesHandler> ();
        myPlayerMovement         = playerObject.GetComponent <Movement> ();
        myPlayerDirection        = playerObject.GetComponent <DirectionFacing> ();
        myPlayerCollisionHandler = playerObject.GetComponentInChildren <MCCollisionNew> ();
        myPlayerEnabledAbilities = playerObject.GetComponent <EnabledAbilities> ();

        currentlyRolling = false;
    }
Exemplo n.º 15
0
        public static ClimbingState GetClimbingState(Climb climb, Collider2D climbCollider, Collider2D playerCollider, bool shouldHang = false)
        {
            if (climb == Climb.None)
            {
                return(new ClimbingState());
            }

            float           climbingSpeed   = 1;
            float           animSpeed       = 1;
            DirectionFacing direction       = GetClimbingSide(climbCollider);
            Climb           transitionClimb = Climb.None;

            switch (climb)
            {
            case Climb.Up:
            case Climb.Flip:
                Hanging(direction);
                transitionClimb = Climb.Down;
                climbingSpeed   = ConstantVariables.MoveToEdgeSpeed;
                animSpeed       = GetAnimationSpeed(playerCollider, climbCollider, climbingSpeed);
                break;

            case Climb.Mantle:
                Mantle(direction);
                transitionClimb = Climb.Up;
                climbingSpeed   = ConstantVariables.AcrossSpeed;
                animSpeed       = GetAnimationSpeed(playerCollider, climbCollider, climbingSpeed);
                break;

            case Climb.Down:
                OffEdge(direction);
                transitionClimb = Climb.Down;
                break;

            case Climb.AcrossLeft:
            case Climb.AcrossRight:
                if (shouldHang)
                {
                    Hanging(direction);
                    transitionClimb = Climb.Down;
                }
                else
                {
                    OffEdge(direction);
                    transitionClimb = Climb.Up;
                }
                climbingSpeed = 0.2f;
                animSpeed     = GetAnimationSpeed(playerCollider, climbCollider, climbingSpeed);
                break;
            }
            return(new ClimbingState(transitionClimb, climbCollider, climbingSpeed, animSpeed, _target, _player, direction));
        }
Exemplo n.º 16
0
 private static void Hanging(DirectionFacing direction)
 {
     if (direction == DirectionFacing.Right)
     {
         _target = ColliderPoint.TopRight;
         _player = ColliderPoint.TopLeft;
     }
     else
     {
         _target = ColliderPoint.TopLeft;
         _player = ColliderPoint.TopRight;
     }
 }
Exemplo n.º 17
0
 public ClimbingState(Climb climb, Collider2D col, float movementSpeed, float animationSpeed, ColliderPoint pivot, ColliderPoint player, DirectionFacing climbSide)
 {
     Climb          = climb;
     PivotCollider  = col;
     MovementSpeed  = movementSpeed;
     AnimationSpeed = animationSpeed;
     PivotPosition  = pivot;
     PlayerPosition = player;
     ClimbSide      = climbSide;
     IsUpright      = col.IsUpright();
     IsCorner       = col.IsCorner();
     CanClimbDown   = col.CanClimbDown();
 }
Exemplo n.º 18
0
 private static void OffEdge(DirectionFacing direction)
 {
     if (direction == DirectionFacing.Right)
     {
         _target = ColliderPoint.TopRight;
         _player = ColliderPoint.BottomLeft;
     }
     else
     {
         _target = ColliderPoint.TopLeft;
         _player = ColliderPoint.BottomRight;
     }
 }
Exemplo n.º 19
0
        private bool JumpInPlace(DirectionFacing direction, bool canDrop, out string animation)
        {
            if (CheckLedgeAcross(direction) || canDrop)
            {
                animation            = Animations.DiveAcross;
                _exception           = null;
                CurrentClimbingState = GetStaticClimbingState();
                return(true);
            }

            animation = "";
            return(false);
        }
Exemplo n.º 20
0
 private static void Mantle(DirectionFacing direction)
 {
     if (direction == DirectionFacing.Right)
     {
         _target = ColliderPoint.TopRight;
         _player = ColliderPoint.LeftFace;
     }
     else
     {
         _target = ColliderPoint.TopLeft;
         _player = ColliderPoint.RightFace;
     }
 }
Exemplo n.º 21
0
    // Use this for initialization
    void Start()
    {
        myDirectionScript = GetComponent <DirectionFacing> ();
        myRigidbody       = GetComponent <Rigidbody> ();
        //myBoxCollider = GetComponent<BoxCollider2D> ();
        //playerspeed = 75.0f;
        //jumpForce = 80000.0f;
        canJump = true;

        isPlayerVelocitySet = false;

        singleJumpCountdown      = 0f;
        myEnabledAbilitiesScript = GetComponent <EnabledAbilities> ();
    }
Exemplo n.º 22
0
    // Change the direction and flip the sprite
    public void SwitchDirection()
    {
        bool willTurnLeft = directionFacing == DirectionFacing.RIGHT;

        if (willTurnLeft)
        {
            directionFacing       = DirectionFacing.LEFT;
            transform.eulerAngles = new Vector3(0, 180, 0);
        }
        else
        {
            directionFacing       = DirectionFacing.RIGHT;
            transform.eulerAngles = new Vector3(0, 0, 0);
        }
    }
Exemplo n.º 23
0
    IEnumerator FaceDown()
    {
        yield return(new WaitForSeconds(.5f));

        CurrentFacingDirection = DirectionFacing.Down;
        animator.SetBool("FacingUp", false);
        animator.SetBool("FacingSide", false);
        animator.SetBool("FacingDown", true);
        Vector3 MoveDirection = Vector3.back;
        bool    Move          = CheckForPillar(MoveDirection);

        if (Move)
        {
            MovePosition = transform.position + (MoveDirection * MoveDistance);
        }
    }
Exemplo n.º 24
0
        public void Update(GameTime gameTime)
        {
            var keyboardState = Keyboard.GetState();

            playerPosition.X = bounds.X;
            playerPosition.Y = bounds.Y;

            if (keyboardState.IsKeyDown(Keys.Up))
            {
                dirFacing = DirectionFacing.Up;
                bounds.Y -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            }
            if (keyboardState.IsKeyDown(Keys.Down))
            {
                dirFacing = DirectionFacing.Down;
                bounds.Y += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            }
            if (keyboardState.IsKeyDown(Keys.Left))
            {
                dirFacing = DirectionFacing.Left;
                bounds.X -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            }
            if (keyboardState.IsKeyDown(Keys.Right))
            {
                dirFacing = DirectionFacing.Right;
                bounds.X += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            }



            if (bounds.Y < 0)
            {
                bounds.Y = 0;
            }
            if (bounds.Y > game.GraphicsDevice.Viewport.Height - bounds.Height)
            {
                bounds.Y = game.GraphicsDevice.Viewport.Height - bounds.Height;
            }
            if (bounds.X < 0)
            {
                bounds.X = 0;
            }
            if (bounds.X > game.GraphicsDevice.Viewport.Width - bounds.Width)
            {
                bounds.X = game.GraphicsDevice.Viewport.Width - bounds.Width;
            }
        }
Exemplo n.º 25
0
    IEnumerator FaceUp()
    {
        yield return(new WaitForSeconds(.5f));

        CurrentFacingDirection = DirectionFacing.Up;
        // MySprite.sprite = Sprites[1];
        animator.SetBool("FacingDown", false);
        animator.SetBool("FacingSide", false);
        animator.SetBool("FacingUp", true);
        Vector3 MoveDirection = Vector3.forward;
        bool    Move          = CheckForPillar(MoveDirection);

        if (Move)
        {
            MovePosition = transform.position + (MoveDirection * MoveDistance);
        }
    }
Exemplo n.º 26
0
    public void ChangeDirection(DirectionFacing newDirection)
    {
        if (newDirection == currentDirection)
        {
            return;
        }

        switch (currentDirection)
        {
        case DirectionFacing.UP:
            animator.ResetTrigger("Up");
            break;

        case DirectionFacing.LEFT:
            animator.ResetTrigger("Left");
            break;

        case DirectionFacing.RIGHT:
            animator.ResetTrigger("Right");
            break;

        default:
            animator.ResetTrigger("Down");
            break;
        }

        switch (newDirection)
        {
        case DirectionFacing.UP:
            OnFaceUp();
            break;

        case DirectionFacing.LEFT:
            OnFaceLeft();
            break;

        case DirectionFacing.RIGHT:
            OnFaceRight();
            break;

        default:
            OnFaceDown();
            break;
        }
    }
Exemplo n.º 27
0
        private void TryGrab()
        {
            bool            grabbing        = false;
            DirectionFacing directionFacing = GetDirectionFacing();

            if (KeyBindings.GetKey(Controls.Left))
            {
                Anim.SetBool(PlayerAnimBool.IsGrabbing, true);
                Anim.SetBool(PlayerAnimBool.Inverted, directionFacing != DirectionFacing.Left);
                if (_climbHandler.CheckGrab(DirectionFacing.Left))
                {
                    MovementState.IsGrounded = true;
                    MovementAllowed          = true;
                    grabbing = true;
                }
            }
            else if (KeyBindings.GetKey(Controls.Right))
            {
                Anim.SetBool(PlayerAnimBool.IsGrabbing, true);
                Anim.SetBool(PlayerAnimBool.Inverted, directionFacing != DirectionFacing.Right);
                if (_climbHandler.CheckGrab(DirectionFacing.Right))
                {
                    MovementState.IsGrounded = true;
                    MovementAllowed          = true;
                    grabbing = true;
                }
            }
            else
            {
                if (_climbHandler.CheckGrab(holdingUp: KeyBindings.GetKey(Controls.Up)))
                {
                    MovementState.IsGrounded = true;
                    MovementAllowed          = true;
                    Anim.SetBool(PlayerAnimBool.IsGrabbing, true);
                    Anim.SetBool(PlayerAnimBool.Inverted, (_climbHandler.CurrentClimbingState.PivotCollider.gameObject.layer == LayerMask.NameToLayer(Layers.RightClimbSpot)) == (directionFacing == DirectionFacing.Right));
                    grabbing = true;
                }
            }
            Anim.SetBool(PlayerAnimBool.IsGrabbing, grabbing);
            _wasGrounded = grabbing;
            if (grabbing)
            {
                SetMotorToClimbState();
            }
        }
Exemplo n.º 28
0
 public Player(Vector2 startPos, string asset, Map map) : base(startPos, asset)
 {
     currentDirection = DirectionFacing.Up;
     strength         = 1;
     exp        = 0;
     maxHealth  = 100;
     health     = maxHealth;
     expToLevel = 30;
     level      = 1;
     playerTurn = true;
     canMove    = true;
     this.map   = map;
     damage     = 10;
     healthPot  = 3;
     score      = 0;
     defense    = 10;
     boostRand  = new Random();
 }
Exemplo n.º 29
0
    // Use this for initialization
    void Start()
    {
        amIbeingHeld = false;

        horizontalDistance = 40f;
        topDistance        = 15f;
        bottomDistance     = -15f;

        offsetWhenHeldX = 0f;
        offsetWhenHeldY = 30f;

        mainCharacterObject    = GameObject.FindGameObjectWithTag("Player");
        mainCharacterTransform = mainCharacterObject.GetComponent <Transform> ();
        mainCharacterData      = mainCharacterObject.GetComponent <GrabPlayerData> ();
        mainCharacterDirection = mainCharacterObject.GetComponent <DirectionFacing> ();

        myTransform = this.GetComponent <Transform> ();
        myCollider  = this.GetComponent <BoxCollider> ();
        myRigidbody = this.GetComponent <Rigidbody> ();
    }
Exemplo n.º 30
0
        public bool CheckGrab(DirectionFacing direction = DirectionFacing.None, bool holdingUp = false)
        {
            Bounds bounds      = _motor.Collider.bounds;
            float  checkLength = ConstantVariables.GrabDistance;

            var   origin   = new Vector2(bounds.center.x, bounds.max.y - 0.5f);
            float distance = bounds.size.x + checkLength * 2;

            RaycastHit2D[] hits = Physics2D.BoxCastAll(origin, new Vector2(distance, 0.1f), 0, Vector2.down, 0.2f, GetClimbMask());

            if (hits.Any())
            {
                Debug.Log("grab");
            }

            int layer = 0;

            if (direction == DirectionFacing.Left)
            {
                layer = _rightClimbLayer;
            }
            else if (direction == DirectionFacing.Right)
            {
                layer = _leftClimbLayer;
            }

            RaycastHit2D hit = hits.FirstOrDefault(h => (holdingUp || (h.collider.CanClimbDown() == false || h.collider.gameObject.layer == layer)) && EdgeValidator.CanJumpToHang(h.collider, bounds.center, _motor.StandingCollider));

            if (hit)
            {
                CurrentClimbingState = GetClimbingState(
                    hit.collider.gameObject.layer == _leftClimbLayer ? Climb.AcrossRight : Climb.AcrossLeft,
                    hit.collider,
                    true);
                _motor.Anim.SetAcrossTrigger();
            }
            return(hit);
        }
    public void SetDirectionFacing(DirectionFacing direction_)
    {
        switch (direction_)
        {
        //If we look up, we see the character from the back
        case DirectionFacing.Up:
            this.backViewParent.SetActive(true);
            this.rightSideViewParent.SetActive(false);
            this.leftSideViewParent.SetActive(false);
            this.forwardViewParent.SetActive(false);
            break;

        //If we look down, we see the character from the front
        case DirectionFacing.Down:
            this.backViewParent.SetActive(false);
            this.rightSideViewParent.SetActive(false);
            this.leftSideViewParent.SetActive(false);
            this.forwardViewParent.SetActive(true);
            break;

        //If we look left, we see the character from the left
        case DirectionFacing.Left:
            this.backViewParent.SetActive(false);
            this.rightSideViewParent.SetActive(false);
            this.leftSideViewParent.SetActive(true);
            this.forwardViewParent.SetActive(false);
            break;

        //If we look right, we see the character from the right
        case DirectionFacing.Right:
            this.backViewParent.SetActive(false);
            this.rightSideViewParent.SetActive(true);
            this.leftSideViewParent.SetActive(false);
            this.forwardViewParent.SetActive(false);
            break;
        }
    }
 private bool TryGetFacingDirection(string direction, out DirectionFacing facing)
 {
     return Enum.TryParse<DirectionFacing>(direction, true, out facing);
 }
Exemplo n.º 33
0
 /**
  *Turn the robot in the given direction
  */
 private bool Turn(Direction direction)
 {
     if (IsRobotActionValid ("turn"))
     {
         var facingDirctionValue = (int)_directionFacing;
         facingDirctionValue += 1 * (direction == Direction.Right ? 1 : -1);
         if (facingDirctionValue == 5) facingDirctionValue = 1;
         if (facingDirctionValue == 0) facingDirctionValue = 4;
         _directionFacing = (DirectionFacing)facingDirctionValue;
         return true;
     }
     return false;
 }
Exemplo n.º 34
0
        protected void CalculateDirectionFacing(Vector2 DirectionToFace)
        {
            Vector2 location = CenterofSprite;

            if ((location != null) && (DirectionToFace != null))
            {
                float Angle = (float)Math.Atan2(( DirectionToFace.Y- location.Y ), (DirectionToFace.X-location.X ));

                Angle = MathHelper.ToDegrees(Angle);

                if (InputHandler.KeyDown(Keys.Space)) {
                    Console.WriteLine(Angle);
                    Console.WriteLine(location);

                }

                if (Angle > -45 && Angle < 0)
                {
                    if (Angle < -22.5)
                    {
                        directionFacing = DirectionFacing.UpLeft;
                    }
                    else
                    {
                        directionFacing = DirectionFacing.Left;
                    }

                }
                else if (Angle > -90 && Angle < -45)
                {
                    if (Angle < -67.5)
                    {
                        directionFacing = DirectionFacing.Up;
                    }
                    else
                    {
                        directionFacing = DirectionFacing.UpLeft;
                    }
                }
                else if (Angle > -135 && Angle < -90)
                {
                    if (Angle < -112.5)
                    {
                        directionFacing = DirectionFacing.UpRight;
                    }
                    else
                    {
                        directionFacing = DirectionFacing.Up;
                    }

                }
                else if (Angle > -180 && Angle < -135)
                {

                    if (Angle < -157.5)
                    {
                        directionFacing = DirectionFacing.Right;
                    }
                    else
                    {
                        directionFacing = DirectionFacing.UpRight;
                    }
                }

                else if (Angle > 135 && Angle < 180)
                {
                    if (Angle > 157.5)
                    {
                        directionFacing = DirectionFacing.Right;
                    }
                    else
                    {
                        directionFacing = DirectionFacing.DownRight;
                    }
                }
                else if (Angle > 90 && Angle < 135)
                {
                    if (Angle > 112.5)
                    {
                        directionFacing = DirectionFacing.DownRight;
                    }
                    else
                    {
                        directionFacing = DirectionFacing.Down;
                    }
                }
                else if (Angle > 45 && Angle < 90)
                {
                    if (Angle > 67.5)
                    {
                        directionFacing = DirectionFacing.Down;
                    }
                    else
                    {
                        directionFacing = DirectionFacing.DownLeft;
                    }

                }
                else if (Angle > 0 && Angle < 45)
                {

                    if (Angle > 22.5)
                    {
                        directionFacing = DirectionFacing.DownLeft;
                    }
                    else
                    {
                        directionFacing = DirectionFacing.Left;
                    }
                }
            }
        }