Esempio n. 1
0
    public void OverWorldSprite()
    {
        var map    = GameManager.Map;
        var h      = Input.GetAxisRaw("Horizontal");
        var v      = Input.GetAxisRaw("Vertical");
        var inputs = (Mathf.Abs(h) > 0.2f || Mathf.Abs(v) > 0.2f);

        if (inputs && inputtimer > .1f && GameManager.GM.CanInteract)
        {
            var u = new Vector(h, v);

            var i = GameManager.Protags[0].TilePosition + u;
            var q = new Vector(Mathf.Clamp(i.x, 0, map.Width - 1), Mathf.Clamp(i.y, 0, map.Length - 1));

            GameManager.Protags[0].Move(map.AtPos(q));


            tileInFront = map.AtPos(new Vector(Mathf.Clamp(i.x, 0, map.Width - 1), Mathf.Clamp(i.y, 0, map.Length - 1)));



            inputtimer = 0;
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (tileInFront != null)
            {
                print(tileInFront);
                tileInFront.OnPressed(actor);
            }
            map.AtPos(actor.TilePosition).OnPressed(actor);
        }
        var e  = new Vector3Int((int)actor.TilePosition.x, (int)actor.TilePosition.y, 0);
        var cp = GameManager.GM.Main.GetCellCenterWorld(e);

        DistanceToPos = Vector3.Distance(transform.position, (Vector2)cp + offset);

        var t = transform.position.x - ((Vector2)cp + offset).x;

        if (!InverseSprite)
        {
            if (t > 0)
            {
                transform.rotation = Quaternion.Euler(new Vector3(0, 180, 0));
            }
            else if (t < 0)
            {
                transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
            }
        }
        else
        {
            if (t > 0)
            {
                transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
            }
            else if (t < 0)
            {
                transform.rotation = Quaternion.Euler(new Vector3(0, 180, 0));
            }
        }

        sprity[0].sortingOrder = 2 + (int)actor.TilePosition.y;
        Position = new Vector2(actor.TilePosition.x, actor.TilePosition.y);

        var g = transform.position.x - e.x;

        var walking = DistanceToPos > 0f;

        foreach (var item in anim)
        {
            item.SetBool("Walking", walking);
        }

        anim[0].SetBool("Defend", actor.Defending);

        for (int i = 0; i < sprity.Length; i++)
        {
            var item = sprity[i];

            if (i > 0)
            {
                item.sprite = sprity[0].sprite;
                item.flipX  = sprity[0].flipX;
            }
        }
        this.transform.position = Vector3.Lerp(transform.position, (Vector2)cp + offset, Speed * Time.smoothDeltaTime / (DistanceToPos + .1f));
        if (DistanceToPos <= .06f)
        {
            OverWorldOnEnterTile();
        }

        //  this.transform.position = Vector3.Lerp(transform.position, (Vector2)tilepos + offset, Speed * Time.fixedDeltaTime);
    }