Exemplo n.º 1
0
    void Update()
    {
        Vector2 mousePos = OffsetCalculator.GetMousePos();

        this.transform.position = mousePos;

        if (CanBuildHere())
        {
            spriteRenderer.color = new Color(0, 1, 0.29f, 0.30f);
        }
        else
        {
            spriteRenderer.color = new Color(1, 0, 0, 0.30f);
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (player != null)
        {
            //this.transform.position = new Vector3(player.transform.position.x,this.transform.position.y,-10);
            //TODO: make it less terrible
            if (player.GetComponent <MainScriptPlayer>().isAiming&& zoomEnabled)
            {
                Vector3 plypos   = player.transform.position;
                Vector3 mousePos = OffsetCalculator.GetMousePos();
                float   angle    = Vector2.Angle(Vector2.right, mousePos - plypos);
                Vector3 aimPos   = OffsetCalculator.GetOffsetPosition(plypos.y < mousePos.y, plypos, angle, zoomSize, zoomSize);

                Debug.DrawRay(plypos, mousePos - plypos, Color.cyan);

                this.transform.position = new Vector3(aimPos.x, aimPos.y, -10);
            }
            else
            {
                this.transform.position = new Vector3(player.transform.position.x, player.transform.position.y, -10);
            }
        }
    }
Exemplo n.º 3
0
    void Update()
    {
        //TODO: remove, this is just testing. Implement better
        var theBarRectTransform = innerHealthBar.transform as RectTransform;
        //var newWidth = Remap(theBarRectTransform.sizeDelta.x,0,100,0,hp.HealthCurrent );
        float newWidth = map(100, 180, hp.HealthCurrent);

        if (newWidth >= 0 && newWidth <= 180)
        {
            theBarRectTransform.sizeDelta = new Vector2(newWidth, theBarRectTransform.sizeDelta.y);
        }

        inmune--;

        if (inmune > 0)
        {
            playerTorso.GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 0.5f);
            playerLegs.GetComponent <SpriteRenderer>().color  = new Color(1f, 1f, 1f, 0.5f);
        }
        else
        {
            playerTorso.GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f);
            playerLegs.GetComponent <SpriteRenderer>().color  = new Color(1f, 1f, 1f, 1f);
        }

        switch (state)
        {
        case (int)st.normal:                                                                    ///NORMAL STATE NOTE:

            //Aim
            if (inputer.mouseRButton)
            {
                isAiming = true;
            }
            else
            {
                isAiming = false;
            }

            //Movement
            if (isAiming)
            {
                spd = moveSpeed - moveAim;
            }
            else
            {
                spd = moveSpeed;
            }

            if (jumpTimes <= 0)
            {
                if (inputer.keyHoldD)
                {
                    rb.velocity = new Vector2(spd, rb.velocity.y);
                    facingRight = true;
                }
                else if (inputer.keyHoldA)
                {
                    rb.velocity = new Vector2(-spd, rb.velocity.y);
                    facingRight = false;
                }

                if (inputer.keyPressSpace)
                {
                    rb.velocity = new Vector2(rb.velocity.x, jumpForce);
                    //jumpTimes++;
                }
            }

            //Animation
            if (Mathf.Abs(rb.velocity.x) != 0)
            {
                legsAnimator.SetBool("aWalking", true);
            }
            else
            {
                legsAnimator.SetBool("aWalking", false);
            }

            if (isAiming)
            {
                //temporal
                playerTorso.GetComponent <SpriteRenderer>().sprite = sprAimingKira;

                Vector3 aimDirection;
                RotateTorso(out aimDirection);
                if (inputer.mouseLButtonPress)
                {
                    Shoot(aimDirection);                                                    //Gun is single fire.
                }
                legsAnimator.speed = 0.5f;
            }
            else
            {
                //temporal
                playerTorso.GetComponent <SpriteRenderer>().sprite = sprNormalKira;

                //Reset the Torso sprite to have no rotation
                if (!isPlayerDead)
                {
                    RotateTorsoReset();
                }

                legsAnimator.speed = 1f;
            }

            //Face correct direction
            playerTorso.GetComponent <SpriteRenderer>().flipX = !facingRight;
            playerLegs.GetComponent <SpriteRenderer>().flipX  = !facingRight;

            //Debug FPS
            //toDisplay = ("fps " + Mathf.Floor(1.0f / Time.deltaTime) );
            //GameObject.Find("Text").GetComponent<Text>().text = toDisplay;

            if (inputer.keyPressQ)
            {
                state      = (int)st.build;
                isBuilding = true;
            }
            break;



        case (int)st.none:                                                                      ///NONE STATE NOTE:
            state = (int)st.normal;
            break;

        case (int)st.build:                                                                     ///BUILD STATE NOTE:

            Vector2 mousePos = OffsetCalculator.GetMousePos();

            //Building
            if (GameObject.Find("ToBuildGhost(Clone)") == null)
            {
                toCreate = Instantiate(emptyBuild, mousePos, Quaternion.identity);
            }

            if (inputer.mouseLButtonPress)
            {
                toCreate.GetComponent <DefenseGhost>().Create();
            }

            //Movement & Jumping
            if (jumpTimes <= 0)
            {
                if (inputer.keyHoldD)
                {
                    rb.velocity = new Vector2(moveSpeed, rb.velocity.y);
                    facingRight = true;
                }
                else if (inputer.keyHoldA)
                {
                    rb.velocity = new Vector2(-moveSpeed, rb.velocity.y);
                    facingRight = false;
                }

                if (inputer.keyPressSpace)
                {
                    rb.velocity = new Vector2(rb.velocity.x, jumpForce);
                    //jumpTimes++;
                }
            }

            //Animation
            if (Mathf.Abs(rb.velocity.x) != 0)
            {
                legsAnimator.SetBool("aWalking", true);
            }
            else
            {
                legsAnimator.SetBool("aWalking", false);
            }

            playerLegs.transform.position = playerTorso.transform.position + new Vector3(0, 0, 1);

            //temporal
            playerTorso.GetComponent <SpriteRenderer>().sprite = sprNormalKira;

            //Reset the Torso sprite to have no rotation
            if (!isPlayerDead)
            {
                RotateTorsoReset();
            }
            legsAnimator.speed = 1f;

            //Face correct direction
            playerTorso.GetComponent <SpriteRenderer>().flipX = !facingRight;
            playerLegs.GetComponent <SpriteRenderer>().flipX  = !facingRight;

            if (inputer.keyPressQ)
            {
                isBuilding = false;
                DestroyImmediate(toCreate);
            }

            if (!isBuilding)                      //exit state
            {
                state = (int)st.normal;
            }

            break;
        }
    }