Exemple #1
0
 public void RotateLeft()
 {
     transform.Rotate(0, 0, -90f);
     Debug.Log("rotation" + transform.rotation.z);
     gravity       = (gravityDirection)((((int)gravity) + 1) % 4);
     gravityVector = new Vector2(gravityVector.y, -gravityVector.x);
 }
Exemple #2
0
    // Use this for initialization
    void Start()
    {
        //Time.timeScale = .25f;
        anim            = GetComponent <Animator>();
        rb              = GetComponent <Rigidbody>();
        cam             = Camera.main;
        speed           = 2;
        moveVertical    = 0;
        moveHorizontal  = 0;
        maxJump         = 8;
        rb.useGravity   = false;
        gravityDir      = gravityDirection.DOWN;
        angle           = 0;
        IPressed        = false;
        JPressed        = false;
        KPressed        = false;
        LPressed        = false;
        sprinting       = false;
        doneJumping     = false;
        gravityRotSpeed = 0.05f;

        cldr      = GetComponent <BoxCollider>();
        jumpAccel = Physics.gravity.magnitude / 2f;
        gravAccel = Physics.gravity.magnitude;
        rock      = Resources.Load <GameObject>("Rock");
        sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
    }
    //Change direction of monsters gravity and its orientation in world space.
    public void SetMonsterGravityDirection(gravityDirection monsterGravityDirection)
    {
        switch (monsterGravityDirection)
        {
        case gravityDirection.Up:
            transform.rotation = Quaternion.Euler(0, 0, 180);
            gravityDirVector   = Vector3.up;
            isMovingInXaxis    = true;
            return;

        case gravityDirection.Down:
            transform.rotation = Quaternion.Euler(0, 0, 0);
            gravityDirVector   = Vector3.down;
            isMovingInXaxis    = true;
            return;

        case gravityDirection.Left:
            transform.rotation = Quaternion.Euler(0, 0, -90);
            gravityDirVector   = Vector3.left;
            isMovingInXaxis    = false;
            return;

        case gravityDirection.Right:
            transform.rotation = Quaternion.Euler(0, 0, 90);
            gravityDirVector   = Vector3.right;
            isMovingInXaxis    = false;
            return;
        }
    }
    public void ChangeGravity(int angle)
    {
        switch (angle)
        {
        case 0:
            Physics2D.gravity = new Vector2(0.0f, -9.81f);
            currentGravity    = gravityDirection.down;
            break;

        case 90:
            Physics2D.gravity = new Vector2(9.81f, 0.0f);
            currentGravity    = gravityDirection.right;
            break;

        case 180:
            Physics2D.gravity = new Vector2(0.0f, 9.81f);
            currentGravity    = gravityDirection.up;
            break;

        case 270:
            Physics2D.gravity = new Vector2(-9.81f, 0);
            currentGravity    = gravityDirection.left;
            break;
        }
    }
Exemple #5
0
    bool isVertical(gravityDirection direction)
    {
        if (direction == gravityDirection.UP || direction == gravityDirection.DOWN)
        {
            return(true);
        }

        return(false);
    }
Exemple #6
0
    bool isHorizontal(gravityDirection direction)
    {
        if (direction == gravityDirection.LEFT || direction == gravityDirection.RIGHT)
        {
            return(true);
        }

        return(false);
    }
Exemple #7
0
    public IEnumerator changeGravityTimer(gravityDirection dir)
    {
        if (isGrounded && dir != gravityDir)
        {
            rb.AddForce(getJumpDirectionVector() * 6, ForceMode.Impulse);
            yield return(new WaitForSeconds(0.5f));

            FindObjectOfType <AudioManager>().Play("warp");
        }
        gravityDir = dir;
    }
Exemple #8
0
    public void switchGravity(gravityDirection newGravity)
    {
        float newRotation = 0;

        transform.localEulerAngles = new Vector3(0, 0, (int)newGravity * -90f);
        gravity = newGravity;

        switch (newGravity)
        {
        case gravityDirection.DOWN:
            gravityVector.x = 0f;
            gravityVector.y = -GRAVITYSPEED;
            newRotation     = 0f;
            break;

        case gravityDirection.LEFT:
            gravityVector.x = -GRAVITYSPEED;
            gravityVector.y = 0f;
            newRotation     = Mathf.PI * 1.5f;
            break;

        case gravityDirection.UP:
            gravityVector.x = 0f;
            gravityVector.y = GRAVITYSPEED;
            newRotation     = Mathf.PI * 1f;
            break;

        case gravityDirection.RIGHT:
            gravityVector.x = GRAVITYSPEED;
            gravityVector.y = 0f;
            newRotation     = Mathf.PI * .5f;
            break;
        }

        collisionDetector.setRotation(newRotation);
    }
Exemple #9
0
    public void doShootCheck(bool fire = false)
    {
        if (Input.GetButtonDown("Fire1") || fire == true)
        {
            float shotXOffset = 0f;
            float shotYOffset = 0f;

            gravityDirection facingDirection = getFacingDirection();
            Vector2          shotVelocity    = new Vector2(0f, 0f);

            // calculate horizontal distance and velocity based on direction character is facing
            switch (facingDirection)
            {
            case gravityDirection.DOWN:
                shotYOffset  = -SHOTHORIZONTALDIST;
                shotVelocity = new Vector2(0f, -SHOTSPEED);
                break;

            case gravityDirection.LEFT:
                shotXOffset  = -SHOTHORIZONTALDIST;
                shotVelocity = new Vector2(-SHOTSPEED, 0f);
                break;

            case gravityDirection.RIGHT:
                shotXOffset  = SHOTHORIZONTALDIST;
                shotVelocity = new Vector2(SHOTSPEED, 0f);
                break;

            case gravityDirection.UP:
                shotYOffset  = SHOTHORIZONTALDIST;
                shotVelocity = new Vector2(0f, SHOTSPEED);
                break;
            }

            // calculate vertical distance based on current gravity
            switch (gravity)
            {
            case gravityDirection.DOWN:
                shotYOffset = -SHOTVERTICALDIST;
                break;

            case gravityDirection.LEFT:
                shotXOffset = -SHOTVERTICALDIST;
                break;

            case gravityDirection.RIGHT:
                shotXOffset = SHOTVERTICALDIST;
                break;

            case gravityDirection.UP:
                shotYOffset = SHOTVERTICALDIST;
                break;
            }

            GameObject shot   = Instantiate(shotPrefab, new Vector3(transform.position.x + shotXOffset, transform.position.y + shotYOffset, 0f), Quaternion.identity) as GameObject;
            Shot       script = (Shot)shot.GetComponent("Shot");
            script.GetComponent <Rigidbody2D>().velocity = shotVelocity;
            SoundManager.playSound("Shoot Sound");
        }

        if (Input.GetButton("Fire1") || fire == true)
        {
            anim.SetBool("Shooting", true);
        }
        else
        {
            anim.SetBool("Shooting", false);
        }
    }