Exemple #1
0
    // 载入裂缝
    public GameObject LoadSkill(dDirection dir, dCellType _t)
    {
        GameObject tem;

        if (_t == dCellType.dCrack_1)
        {
            tem = (GameObject)Resources.Load("Prefabs/crackPrefab");
            tem.GetComponent <Skill>().currentDir = dir;
            tem.GetComponent <SpriteRenderer>().sortingLayerName = "bg";
            return(tem);
        }
        else if (_t == dCellType.dCrack_2)
        {
            tem = (GameObject)Resources.Load("Prefabs/crackPrefab_2");
            tem.GetComponent <Skill>().currentDir = dir;
            tem.GetComponent <SpriteRenderer>().sortingLayerName = "bg";
            return(tem);
        }
        else if (_t == dCellType.dBlock)
        {
            tem = (GameObject)Resources.Load("Prefabs/crackPrefab_3");
            tem.GetComponent <Skill>().currentDir = dir;
            tem.GetComponent <SpriteRenderer>().sortingLayerName = "bg";
            return(tem);
        }
        else
        {
            return(null);
        }
    }
    // 生成裂缝
    #region
    public void GenerateCrack(Transform _pos, dDirection _dir)
    {
        //int cellSize = CommonFunction.Instance.cellSize;
        //int offset = (int)cellSize / 2;
        //int posX = (int)_pos.position.x;
        //int posY = (int)_pos.position.y - offset;
        //int x = posX / cellSize, y = posY / cellSize;

        StartCoroutine(WaitForGenerate(_pos, _dir));
    }
Exemple #3
0
 public Sprite LoadSprite(dDirection dir)
 {
     if (dir == dDirection.dNone)
     {
         return(Resources.Load("Character/Idle/hero_idle_left", typeof(Sprite)) as Sprite);
     }
     else if (dir == dDirection.dUp_Up)
     {
         return(Resources.Load("Character/Idle/hero_idle_back", typeof(Sprite)) as Sprite);
     }
     else if (dir == dDirection.dDown_Down)
     {
         return(Resources.Load("Character/Idle/hero_idle_front", typeof(Sprite)) as Sprite);
     }
     else if (dir == dDirection.dLeft_Left)
     {
         return(Resources.Load("Character/Idle/hero_idle_left", typeof(Sprite)) as Sprite);
     }
     else if (dir == dDirection.dRight_Right)
     {
         return(Resources.Load("Character/Idle/hero_idle_left", typeof(Sprite)) as Sprite);
     }
     else if (dir == dDirection.dUp_Left)
     {
         return(Resources.Load("Character/Idle/hero_idle_topleft", typeof(Sprite)) as Sprite);
     }
     else if (dir == dDirection.dUp_Right)
     {
         return(Resources.Load("Character/Idle/hero_idle_topleft", typeof(Sprite)) as Sprite);
     }
     else if (dir == dDirection.dDown_Left)
     {
         return(Resources.Load("Character/Idle/hero_idle_bottomleft", typeof(Sprite)) as Sprite);
     }
     else if (dir == dDirection.dDown_Right)
     {
         return(Resources.Load("Character/Idle/hero_idle_bottomleft", typeof(Sprite)) as Sprite);
     }
     return(null);
 }
    private void AttackB(dDirection dir)
    {
        if (Input.GetKeyDown(KeyCode.J))
        {
            AnimatorStateInfo animStateInfo = anim.GetCurrentAnimatorStateInfo(0);
            if (animStateInfo.IsName("Run"))
            {
                anim.SetFloat("Speed", 1.0f);
            }
            else if (animStateInfo.IsName("Idle"))
            {
                anim.SetFloat("Speed", 0.0f);
            }

            anim.SetTrigger("Attack");
            Vector2 v = new Vector2(0, 0);
            this.Move(v, this.speed);
            this.isAttack = true;
            //this.GenerateCrack(this.transform, this.currentDir);
            return;
        }
    }
Exemple #5
0
    public Vector2 TranslateDirection(dDirection dir)
    {
        Vector2 v = new Vector2();

        if (dir == dDirection.dDown_Down)
        {
            v = new Vector2(0.0f, -1.0f);
        }
        else if (dir == dDirection.dDown_Left)
        {
            v = new Vector2(-1.0f, -1.0f);
        }
        else if (dir == dDirection.dLeft_Left)
        {
            v = new Vector2(-1.0f, 0.0f);
        }
        else if (dir == dDirection.dUp_Left)
        {
            v = new Vector2(-1.0f, 1.0f);
        }
        else if (dir == dDirection.dUp_Up)
        {
            v = new Vector2(0.0f, 1.0f);
        }
        else if (dir == dDirection.dUp_Right)
        {
            v = new Vector2(1.0f, 1.0f);
        }
        else if (dir == dDirection.dRight_Right)
        {
            v = new Vector2(1.0f, 0.0f);
        }
        else if (dir == dDirection.dDown_Right)
        {
            v = new Vector2(1.0f, -1.0f);
        }
        return(v.normalized);
    }
    //生成箱子
    #region
    public void GenerateBox(Transform _pos, dDirection _dir)
    {
        int cellSize = CommonFunction.Instance.cellSize;
        int offset   = (int)cellSize / 2;
        int x        = (int)_pos.position.x / cellSize;
        int y        = (int)(_pos.position.y - offset) / cellSize;


        switch (_dir)
        {
        case dDirection.dUp_Up:
            y++; break;

        case dDirection.dUp_Left:
            x--; y++; break;

        case dDirection.dUp_Right:
            x++; y++; break;

        case dDirection.dDown_Down:
            y--; break;

        case dDirection.dDown_Left:
            x--; y--; break;

        case dDirection.dDown_Right:
            x++; y--; break;

        case dDirection.dLeft_Left:
            x--; break;

        case dDirection.dRight_Right:
            x++; break;

        default:
            Debug.Log("Crack with No Dir!");
            break;
        }

        Debug.Log("pass");
        Debug.Log("Cell: " + x + ", " + y);
        if (x < 0 || y < 0 || x >= CommonFunction.Instance.MapWidth || y >= CommonFunction.Instance.MapHeight)
        {
            return;
        }

        //Debug.Log(x + ", " + y);
        dCellType[,] tMap     = GameObject.Find("GameManager").GetComponent <GameManager>().map;
        GameObject[,] objects = GameObject.Find("GameManager").GetComponent <GameManager>().obj;

        if (tMap[x, y] == dCellType.dCrack_2)
        {
            tMap[x, y] = dCellType.dBlock;
            Destroy(objects[x, y]);
            GameObject fill = GameObject.Instantiate(CommonFunction.Instance.LoadSkill(_dir, tMap[x, y]));
            fill.transform.position = new Vector3(x * cellSize + offset, y * cellSize + offset, 0);
        }
        else if (tMap[x, y] == dCellType.dNone)
        {
            tMap[x, y] = dCellType.dItem;
            GameObject tObj = GameObject.Instantiate((GameObject)(Resources.Load("Prefabs/ItemPrefab")));
            if (objects[x, y] == null)
            {
                objects[x, y] = tObj;
            }
            tObj.transform.position = new Vector3(x * cellSize + cellSize / 2, y * cellSize + cellSize / 2, 0);
        }

        //GameObject crack = GameObject.Instantiate(CommonFunction.Instance.LoadSkill(_dir, tMap[x, y]));
        //crack.transform.position = new Vector3(x * cellSize + offset, y * cellSize + offset, 0);

        #endregion
    }
    IEnumerator WaitForGenerate(Transform _pos, dDirection _dir)
    {
        int cellSize = CommonFunction.Instance.cellSize;
        int offset   = (int)cellSize / 2;
        int x        = (int)_pos.position.x / cellSize;
        int y        = (int)(_pos.position.y - offset) / cellSize;

        for (int i = 0; i < 3; i++)
        {
            switch (_dir)
            {
            case dDirection.dUp_Up:
                y++; break;

            case dDirection.dUp_Left:
                x--; y++; break;

            case dDirection.dUp_Right:
                x++; y++; break;

            case dDirection.dDown_Down:
                y--; break;

            case dDirection.dDown_Left:
                x--; y--; break;

            case dDirection.dDown_Right:
                x++; y--; break;

            case dDirection.dLeft_Left:
                x--; break;

            case dDirection.dRight_Right:
                x++; break;

            default:
                Debug.Log("Crack with No Dir!");
                break;
            }

            Debug.Log("pass");
            Debug.Log("Cell: " + x + ", " + y);
            if (x < 0 || y < 0 || x >= CommonFunction.Instance.MapWidth || y >= CommonFunction.Instance.MapHeight)
            {
                break;
            }

            //Debug.Log(x + ", " + y);
            dCellType[,] tMap     = GameObject.Find("GameManager").GetComponent <GameManager>().map;
            GameObject[,] objects = GameObject.Find("GameManager").GetComponent <GameManager>().obj;

            if (tMap[x, y] != dCellType.dCrack_2)
            {
                if (tMap[x, y] == dCellType.dCrack_1 || tMap[x, y] == dCellType.dNone)
                {
                    tMap[x, y]++;
                }
                else
                {
                    tMap[x, y] = dCellType.dCrack_1;
                }
            }
            GameObject crack = GameObject.Instantiate(CommonFunction.Instance.LoadSkill(_dir, tMap[x, y]));
            crack.transform.position = new Vector3(x * cellSize + offset, y * cellSize + offset, 0);

            //crack.GetComponent<Skill>().cellType = tMap[x, y];
            if (objects[x, y] == null)
            {
                objects[x, y] = crack;
            }
            else
            {
                Destroy(objects[x, y]);
                objects[x, y] = crack;
            }

            yield return(new WaitForSeconds(CommonFunction.Instance.crackInterval));
        }
    }
    //角色位移动画
    private void AnimSetUp(dDirection dir)
    {
        if (dir == dDirection.dUp_Up)
        {
            this.animOverride["Idle"]   = this.animListIdle[0];
            this.animOverride["Run"]    = this.animListRun[0];
            this.animOverride["Attack"] = this.animListAttack[0];
            this.animOverride["Fall"]   = this.animListFall[0];
            this.animOverride["Put"]    = this.animListPut[0];
            this.animOverride["Die"]    = this.animListDie[0];
            this.transform.localScale   = new Vector3(1.0f, 1.0f, 1.0f);
        }
        else if (dir == dDirection.dUp_Left)
        {
            this.animOverride["Idle"]   = this.animListIdle[1];
            this.animOverride["Run"]    = this.animListRun[1];
            this.animOverride["Attack"] = this.animListAttack[1];
            this.animOverride["Fall"]   = this.animListFall[1];
            this.animOverride["Put"]    = this.animListPut[1];
            this.animOverride["Die"]    = this.animListDie[1];
            this.transform.localScale   = new Vector3(1.0f, 1.0f, 1.0f);
        }
        else if (dir == dDirection.dLeft_Left)
        {
            this.animOverride["Idle"]   = this.animListIdle[2];
            this.animOverride["Run"]    = this.animListRun[2];
            this.animOverride["Attack"] = this.animListAttack[2];
            this.animOverride["Fall"]   = this.animListFall[2];
            this.animOverride["Put"]    = this.animListPut[2];
            this.animOverride["Die"]    = this.animListDie[2];
            this.transform.localScale   = new Vector3(1.0f, 1.0f, 1.0f);
        }
        else if (dir == dDirection.dDown_Left)
        {
            this.animOverride["Idle"]   = this.animListIdle[3];
            this.animOverride["Run"]    = this.animListRun[3];
            this.animOverride["Attack"] = this.animListAttack[3];
            this.animOverride["Fall"]   = this.animListFall[3];
            this.animOverride["Put"]    = this.animListPut[3];
            this.animOverride["Die"]    = this.animListDie[3];
            this.transform.localScale   = new Vector3(1.0f, 1.0f, 1.0f);
        }
        else if (dir == dDirection.dDown_Down)
        {
            this.animOverride["Idle"]   = this.animListIdle[4];
            this.animOverride["Run"]    = this.animListRun[4];
            this.animOverride["Attack"] = this.animListAttack[4];
            this.animOverride["Fall"]   = this.animListFall[4];
            this.animOverride["Put"]    = this.animListPut[4];
            this.animOverride["Die"]    = this.animListDie[4];
            this.transform.localScale   = new Vector3(1.0f, 1.0f, 1.0f);
        }
        else if (dir == dDirection.dDown_Right)
        {
            this.animOverride["Idle"]   = this.animListIdle[3];
            this.animOverride["Run"]    = this.animListRun[3];
            this.animOverride["Attack"] = this.animListAttack[3];
            this.animOverride["Fall"]   = this.animListFall[3];
            this.animOverride["Put"]    = this.animListPut[3];
            this.animOverride["Die"]    = this.animListDie[3];
            this.transform.localScale   = new Vector3(-1.0f, 1.0f, 1.0f);
        }
        else if (dir == dDirection.dRight_Right)
        {
            this.animOverride["Idle"]   = this.animListIdle[2];
            this.animOverride["Run"]    = this.animListRun[2];
            this.animOverride["Attack"] = this.animListAttack[2];
            this.animOverride["Fall"]   = this.animListFall[2];
            this.animOverride["Put"]    = this.animListPut[2];
            this.animOverride["Die"]    = this.animListDie[2];
            this.transform.localScale   = new Vector3(-1.0f, 1.0f, 1.0f);
        }
        else if (dir == dDirection.dUp_Right)
        {
            this.animOverride["Idle"]   = this.animListIdle[1];
            this.animOverride["Run"]    = this.animListRun[1];
            this.animOverride["Attack"] = this.animListAttack[1];
            this.animOverride["Fall"]   = this.animListFall[1];
            this.animOverride["Put"]    = this.animListPut[1];
            this.animOverride["Die"]    = this.animListDie[1];
            this.transform.localScale   = new Vector3(-1.0f, 1.0f, 1.0f);
        }

        this.anim.runtimeAnimatorController = animOverride;
    }
    private void InputB()
    {
        Vector2 v = new Vector2();

        if (Input.GetKey(KeyCode.J) || Input.GetKeyDown(KeyCode.J))
        {
            this.AttackB(this.currentDir);
        }
        else if (Input.GetKey(KeyCode.K) || Input.GetKeyDown(KeyCode.K))
        {
            this.PutB();
        }
        else
        {
            if (Input.GetKey(KeyCode.UpArrow) && !(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow)))//向直上
            {
                this.currentDir = dDirection.dUp_Up;
                v = new Vector2(0.0f, 1.0f);
            }
            else if (Input.GetKey(KeyCode.DownArrow) && !(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow)))//向直下
            {
                this.currentDir = dDirection.dDown_Down;
                v = new Vector2(0.0f, -1.0f);
            }
            else if (Input.GetKey(KeyCode.LeftArrow) && !(Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.UpArrow)))//向直左
            {
                this.currentDir = dDirection.dLeft_Left;
                v = new Vector2(-1.0f, 0.0f);
            }
            else if (Input.GetKey(KeyCode.RightArrow) && !(Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.UpArrow)))//向直右
            {
                this.currentDir = dDirection.dRight_Right;
                v = new Vector2(1.0f, 0.0f);
            }
            else if (Input.GetKey(KeyCode.LeftArrow) && Input.GetKey(KeyCode.UpArrow))//向左上
            {
                this.currentDir = dDirection.dUp_Left;
                v = new Vector2(-1.0f, 1.0f);
            }
            else if (Input.GetKey(KeyCode.RightArrow) && Input.GetKey(KeyCode.UpArrow))//向右上
            {
                this.currentDir = dDirection.dUp_Right;
                v = new Vector2(1.0f, 1.0f);
            }
            else if (Input.GetKey(KeyCode.LeftArrow) && Input.GetKey(KeyCode.DownArrow))//向左下
            {
                this.currentDir = dDirection.dDown_Left;
                v = new Vector2(-1.0f, -1.0f);
            }
            else if (Input.GetKey(KeyCode.RightArrow) && Input.GetKey(KeyCode.DownArrow))//向右下
            {
                this.currentDir = dDirection.dDown_Right;
                v = new Vector2(1.0f, -1.0f);
            }
            else
            {
                v = new Vector2(0.0f, 0.0f);
            }
            this.Move(v, this.speed);
            anim.SetFloat("Speed", v.magnitude);
        }

        if (this.fall)
        {
            anim.SetTrigger("Fall");
            this.fall = false;
        }
        if (this.die)
        {
            this.anim.SetBool("Die", true);
        }
    }