Esempio n. 1
0
    public void setGravityDirection(PlayerMovement.Direction a_direction)
    {
        float   gravityValue = Mathf.Max(Mathf.Abs(Physics.gravity.x), Mathf.Max(Mathf.Abs(Physics.gravity.y), Mathf.Abs(Physics.gravity.z)));
        Vector3 gravity      = Vector3.zero;

        switch (a_direction)
        {
        case PlayerMovement.Direction.KDown:
            gravity.y = -gravityValue;
            break;

        case PlayerMovement.Direction.KUp:
            gravity.y = gravityValue;
            break;

        case PlayerMovement.Direction.KLeft:
            gravity.x = -gravityValue;
            break;

        case PlayerMovement.Direction.KRight:
            gravity.x = gravityValue;
            break;
        }
        Physics.gravity = gravity;
    }
Esempio n. 2
0
 // Start is called before the first frame update
 void Awake()
 {
     animator  = GetComponent <Animator>();
     render    = GetComponent <SpriteRenderer>();
     direction = PlayerMovement.Direction.Down;
     pickup    = GetComponent <ItemPickup>();
 }
Esempio n. 3
0
    void Update()
    {
        var xInput = Input.GetAxisRaw("Horizontal");
        var yInput = Input.GetAxisRaw("Vertical");

        moving = xInput != 0f || yInput != 0f;
        if (movementLocked || moving)
        {
            var inputVector      = new Vector2(xInput, yInput);
            var movementAngle    = MathHelper.trueMod(inputVector.getAngle(), 360f);
            var calculationAngle = MathHelper.trueMod(movementAngle + 45f, 360f);                 // Used to split movement into 4 quadrants

            if (calculationAngle % 90f == 0f &&                                                   // If right on the cusp of two directions, keep current direction
                Mathf.Abs(Mathf.DeltaAngle(movementAngle, (float)currentDirection * 90f)) <= 91f) // Unless we've turned too much
            {
                if (diagonalPriority == SpritePriority.Vertical)
                {
                    currentDirection = movementAngle < 180f ? PlayerMovement.Direction.Up : PlayerMovement.Direction.Down;
                }
                else if (diagonalPriority == SpritePriority.Horizontal)
                {
                    currentDirection = (movementAngle > 90f && movementAngle < 270f) ? PlayerMovement.Direction.Up : PlayerMovement.Direction.Down;
                }
            }
            else
            {
                currentDirection = (PlayerMovement.Direction)(((int)calculationAngle) / 90);
            }

            transform.localScale = new Vector3(
                Mathf.Abs(transform.localScale.x) * (currentDirection == PlayerMovement.Direction.Right ? -1f : 1f),
                transform.localScale.y,
                transform.localScale.z);

            if (movementLocked)
            {
                moving           = true;
                currentDirection = PlayerMovement.Direction.Up;
            }

            var spriteSet = movementSprites[(int)currentDirection].GetSprites();
            frameIndex += frameSpeed * Time.deltaTime;
            while (frameIndex >= spriteSet.Length)
            {
                frameIndex -= spriteSet.Length;
            }
            spriteRenderer.sprite = spriteSet[Mathf.FloorToInt(frameIndex)];
        }
        else
        {
            spriteRenderer.sprite = idleSprites[(int)currentDirection];
        }
    }
Esempio n. 4
0
 void CheckShoot()
 {
     if (Input.GetKey(KeyCode.Space))
     {
         GameObject b = BulletManager.instance.RequestBullet();
         b.transform.position = this.transform.position;
         //Probably here is also where we assign the current direction of the player to the bullet
         PlayerMovement.Direction d = GetComponent <PlayerMovement>().GetCurrentDirection();
         b.GetComponent <BulletMovement>().SetDirection(d);
         fireCounter = 0;
         AudioManager.instance.PlaySoundEffect("Shoot");
     }
 }
Esempio n. 5
0
    private IEnumerator DoBlink(Vector2 destination, PlayerMovement.Direction dir)
    {
        blinking = true;
        SetBlinkAnim(dir);
        movement.StopVelocity();
        movement.enabled = false;
        yield return(new WaitForSeconds(.2f));

        Position = destination;
        yield return(new WaitForSeconds(.1f));

        movement.enabled = true;
        blinking         = false;
        canBlinkTime     = Time.time + blinkCooldown;
    }
Esempio n. 6
0
 //We call this when we create the bullet to set its direction
 public void SetDirection(PlayerMovement.Direction direction)
 {
     StartCoroutine(ProjectileDuration());
     //Change bulletDirection
     if (direction == PlayerMovement.Direction.UP)
     {
         bulletDirection = new Vector3(0, 0.25f, 0);
     }
     else if (direction == PlayerMovement.Direction.DOWN)
     {
         bulletDirection = new Vector3(0, -0.25f, 0);
     }
     else if (direction == PlayerMovement.Direction.LEFT)
     {
         bulletDirection = new Vector3(-0.25f, 0, 0);
     }
     else if (direction == PlayerMovement.Direction.RIGHT)
     {
         bulletDirection = new Vector3(0.25f, 0, 0);
     }
 }
 public void BePushed(PlayerMovement.Direction pushingD)
 {
     if (canBePushed)
     {
         blockRB.isKinematic = false;
         if (pushingD == PlayerMovement.Direction.Up)
         {
             blockRB.AddForce(new Vector3(speed, 0, 0), ForceMode.VelocityChange);
         }
         else if (pushingD == PlayerMovement.Direction.Down)
         {
             blockRB.AddForce(new Vector3(-speed, 0, 0), ForceMode.VelocityChange);
         }
         else if (pushingD == PlayerMovement.Direction.Left)
         {
             blockRB.AddForce(new Vector3(0, 0, speed), ForceMode.VelocityChange);
         }
         else if (pushingD == PlayerMovement.Direction.Right)
         {
             blockRB.AddForce(new Vector3(0, 0, -speed), ForceMode.VelocityChange);
         }
         beingPushed = true;
     }
 }
Esempio n. 8
0
    private void SetBlinkAnim(PlayerMovement.Direction dir)
    {
        switch (dir)
        {
        case PlayerMovement.Direction.Up:
            movement.animationPlayer.Play("TeleportUp");
            break;

        case PlayerMovement.Direction.Down:
            movement.animationPlayer.Play("TeleportDown");
            break;

        case PlayerMovement.Direction.Left:
            movement.animationPlayer.Play("TeleportLeft");
            break;

        case PlayerMovement.Direction.Right:
            movement.animationPlayer.Play("TeleportRight");
            break;

        default:
            throw new ArgumentOutOfRangeException(nameof(dir), dir, null);
        }
    }
Esempio n. 9
0
 void Start()
 {
     spriteRenderer   = GetComponent <SpriteRenderer>();
     currentDirection = PlayerMovement.Direction.Up;
     moving           = true;
 }