Example #1
0
 public void zombieMove()
 {
     foreach (string str in DirSave.Instance().Data)
     {
         //向前走
         if (Convert.ToInt32(str) == DirSave.EDIR.eUp.GetHashCode())
         {
             move(dir);
         }
         //backword
         else if (Convert.ToInt32(str) == DirSave.EDIR.eDown.GetHashCode())
         {
             move(new Vector2Int(-dir.x, -dir.y));
         }
         //right
         if (str.Equals(Convert.ToInt32(str) == DirSave.EDIR.eRight.GetHashCode()))
         {
             var d = dir;
             if (dir == new Vector2Int(1, 0))
             {
                 d = new Vector2Int(0, -1);
             }
             if (dir == new Vector2Int(0, 1))
             {
                 d = new Vector2Int(1, 0);
             }
             if (dir == new Vector2Int(-1, 0))
             {
                 d = new Vector2Int(0, 1);
             }
             if (dir == new Vector2Int(0, -1))
             {
                 d = new Vector2Int(-1, 0);
             }
             move(d);
         }
         //left
         if (Convert.ToInt32(str) == DirSave.EDIR.eLeft.GetHashCode())
         {
             var d = dir;
             if (dir == new Vector2Int(1, 0))
             {
                 d = new Vector2Int(0, 1);
             }
             if (dir == new Vector2Int(0, 1))
             {
                 d = new Vector2Int(-1, 0);
             }
             if (dir == new Vector2Int(-1, 0))
             {
                 d = new Vector2Int(0, -1);
             }
             if (dir == new Vector2Int(0, -1))
             {
                 d = new Vector2Int(1, 0);
             }
             move(d);
         }
     }
 }
Example #2
0
    public void move(Vector2Int d)
    {
        player_m.GetComponent <Animator>().SetTrigger("walk");

        //player_m.SetBool("walk", true);
        var des = d + _cube.Pos;

        Debug.Log(des);
        foreach (var item in MapMgr.Instance.CubeList)
        {
            if (item.Pos == des)
            {
                if (item.WalkAble)
                {
                    if (dir == d)
                    {
                        //前
                        DirSave.Instance().SaveDirToFile(DirSave.EDIR.eUp);
                    }
                    else if (dir == new Vector2Int(-d.x, -d.y))
                    {
                        //后
                        DirSave.Instance().SaveDirToFile(DirSave.EDIR.eDown);
                    }
                    else
                    {
                        if (Cross(dir, d) == 1)
                        {
                            //left
                            DirSave.Instance().SaveDirToFile(DirSave.EDIR.eLeft);
                        }

                        else if (Cross(dir, d) == -1)
                        {
                            //right
                            DirSave.Instance().SaveDirToFile(DirSave.EDIR.eRight);
                        }
                        else
                        {
                            //bug
                            DirSave.Instance().SaveDirToFile(DirSave.EDIR.eNone);
                        }
                    }

                    dir            = d;
                    _cube.ObjAbove = null;

                    _cube                   = item;
                    _cube.ObjAbove          = this;
                    this.transform.position = _cube.transform.position;
                    return;
                }
                else
                {
                    //撞墙
                }
            }
        }
        return;
    }
Example #3
0
    // Start is called before the first frame update
    void Start()
    {
        this.gameObject.tag = "Player";
        if (ScenesManager.Instance().isPowerOn)
        {
            this.enabled = false;
            gameObject.GetComponent <Obj_zombie>().enabled = true;
        }

        DirSave.Instance().UpdateFile();
        DirSave.Instance().ClearContent();
    }
Example #4
0
 public void showWay()
 {
     foreach (var item in gameObject.GetComponentsInChildren <Transform>())
     {
         if (item != transform)
         {
             Destroy(item.gameObject);
         }
     }
     indix = zom.indix;
     dir   = zom.dir;
     _cube = zom._cube;
     while (indix < DirSave.Instance().Data.Count)
     {
         zombieMove(indix++);
     }
 }
Example #5
0
    public void zombieMove(int idx)
    {
        bool flag = true;

        if (idx > DirSave.Instance().Data.Count - 1)
        {
            return;
        }

        string str = DirSave.Instance().Data[idx];


        //向前走
        if (Convert.ToInt32(str) == DirSave.EDIR.eUp.GetHashCode())
        {
            flag = move(dir);
        }
        //backword
        else if (Convert.ToInt32(str) == DirSave.EDIR.eDown.GetHashCode())
        {
            flag = move(new Vector2Int(-dir.x, -dir.y));
        }
        //right
        if (Convert.ToInt32(str) == DirSave.EDIR.eRight.GetHashCode())
        {
            var d = dir;
            if (dir == new Vector2Int(1, 0))
            {
                d = new Vector2Int(0, -1);
            }
            if (dir == new Vector2Int(0, 1))
            {
                d = new Vector2Int(1, 0);
            }
            if (dir == new Vector2Int(-1, 0))
            {
                d = new Vector2Int(0, 1);
            }
            if (dir == new Vector2Int(0, -1))
            {
                d = new Vector2Int(-1, 0);
            }
            flag = move(d);
        }
        //left
        if (Convert.ToInt32(str) == DirSave.EDIR.eLeft.GetHashCode())
        {
            var d = dir;
            if (dir == new Vector2Int(1, 0))
            {
                d = new Vector2Int(0, 1);
            }
            if (dir == new Vector2Int(0, 1))
            {
                d = new Vector2Int(-1, 0);
            }
            if (dir == new Vector2Int(-1, 0))
            {
                d = new Vector2Int(0, -1);
            }
            if (dir == new Vector2Int(0, -1))
            {
                d = new Vector2Int(1, 0);
            }
            flag = move(d);
        }
        if (flag == false)
        {
            Debug.LogError("HelpOver");
        }
    }