Ejemplo n.º 1
0
    public Tile Get(Utils.Dir d)
    {
        Vector2 v = Utils.Dir2Vec()[d];

        try
        {
            return(Camera.main.GetComponent <Grid>().Get(Pos.x + v.x, Pos.y + v.y));
        }
        catch
        {
            return(null);
        }
    }
Ejemplo n.º 2
0
    void Room(int x, int y, int xSize, int ySize, string biome, string entry = "S")
    {
        List <RoomInfo> validRooms = roomInfos.rooms.Where(r => r.dimensions[0] == xSize &&
                                                           r.dimensions[1] == ySize &&
                                                           r.entry == entry &&
                                                           r.biomes.ToList()
                                                           .Contains(biome)).ToList();

        Room     room = gameObject.AddComponent <Room>();
        RoomInfo info = validRooms[Random.Range(0, validRooms.Count())];

        info.xPos = x;
        info.yPos = y;

        info.df.ForEach(l =>
        {
            l.ForEach(i =>
            {
                if (i == "E")
                {
                    info.doorPosX = info.df.IndexOf(l);
                    info.doorPosY = l.IndexOf(i);
                    Debug.Log(info.df.IndexOf(l) + "_" + l.IndexOf(i));
                    x = x - info.doorPosX;
                    y = y - info.doorPosY;
                }
            });
        });

        //Dictionary<int, List<Tile>> tiles = new Dictionary<int, List<Tile>>();
        List <List <Tile> > tiles = new List <List <Tile> >();


        for (int i = 0; i < info.df.Count(); i++)
        {
            List <Tile> l = new List <Tile>();

            for (int j = 0; j < ySize; j++)
            {
                TileInfo tileInfo = tileInfos.Tiles.Where(t => t.MapKey == info.df[i][j]
                                                          ).ToArray()[0];
                var  _x   = (x + i); // - xSize / 2;
                var  _y   = (y + j); // - ySize / 2;
                Tile tile = Get(_x, _y);
                tile.Room     = room;
                tile.roomInfo = info;
                tile.Set(tileInfo);
                l.Add(tile);
            }
            tiles.Add(l);
            info.Tiles.Add(l);
        }

        TileInfo wallInfo = tileInfos.Get(key: "1", biome: biome);



        int _xSize = 4;
        int _ySize = 4;

        tiles.ForEach(i =>
        {
            i.ForEach(t =>
            {
                Utils.Dir edge = t.Edge();

                if (Utils.nDirs.Contains(edge))
                {
                    t.Get(Utils.Dir.N).Set(wallInfo);
                }

                if (t.Info().MapKey == "d")
                {
                    Debug.Log(edge);
                    if (edge == Utils.Dir.E)
                    {
                        Room(t.PosX() + 1, t.PosY(), _xSize, _ySize, biome, entry: "W");
                    }
                    if (edge == Utils.Dir.S)
                    {
                        Room(t.PosX(), t.PosY() - 1, _xSize, _ySize, biome, entry: "N");
                    }
                    if (edge == Utils.Dir.W)
                    {
                        Room(t.PosX() - 1, t.PosY(), _xSize, _ySize, biome, entry: "E");
                    }
                    if (edge == Utils.Dir.N)
                    {
                        Room(t.PosX(), t.PosY() + 1, _xSize, _ySize, biome, entry: "S");
                    }
                }
            });
        });
    }
Ejemplo n.º 3
0
    public Utils.Dir Edge()
    {
        Utils.Dir dir = Utils.Direction()[Vector2.zero];
        var       vec = Vector2.zero;

        //Debug.Log(Room.transform == Get(Utils.Dir.N).Room.transform);
        if (!Match(Get(Utils.Dir.N)))
        {
            dir = Utils.Dir.N;
            if (!Match(Get(Utils.Dir.W)))
            {
                dir = Utils.Dir.NW;
                info.traversableTop
                Sprite(sprites[info.LeftWall]);
            }
            if (!Match(Get(Utils.Dir.E)))
            {
                dir = Utils.Dir.NE;
                Sprite(sprites[info.RightWall]);
            }
            return(dir);
        }
        if (!Match(Get(Utils.Dir.S)))
        {
            dir = Utils.Dir.S;
            Sprite(sprites[info.LowerWall]);

            if (!Match(Get(Utils.Dir.W)))
            {
                dir = Utils.Dir.SW;
                Sprite(sprites[info.RightLowerWall]);
            }
            if (!Match(Get(Utils.Dir.E)))
            {
                dir = Utils.Dir.SE;
                Sprite(sprites[info.LeftLowerWall]);
            }
            return(dir);
        }

        if (!Match(Get(Utils.Dir.W)))
        {
            dir = Utils.Dir.W;
            Sprite(sprites[info.LeftWall]);
        }

        if (!Match(Get(Utils.Dir.E)))
        {
            dir = Utils.Dir.E;
            Sprite(sprites[info.RightWall]);
        }

        //Utils.VecDirections(cardinal:true).ForEach(x =>
        //{
        //    if (Get(x).Room != Room)
        //    {
        //        vec += x;
        //        Debug.Log(vec);
        //    }
        //    else
        //    {
        //    }
        //});
        //dir = Utils.Direction()[vec];

        return(dir);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Sets the new direction based on the current velocity
    /// </summary>
    /// <param name="newVel"></param>
    private void setDirection(Vector2 newVel)
    {
        Utils.Dir newDir = Utils.getDirection(newVel);
        if (Utils.Dir.NULL.Equals(newDir))
        {
            return;
        }

        // Change hand position based on direction
        if (!newDir.Equals(curDir))
        {
            curDir = newDir;

            // Initialize to right
            hand.localScale = Vector2.one;
            hand.localEulerAngles = Vector3.one;

            if (curDir == Utils.Dir.UP)
            {
                hand.localScale = new Vector2(-1, 1);
                hand.localEulerAngles = new Vector3(0, 0, 270f);
            }
            else if (curDir == Utils.Dir.DOWN)
            {
                hand.localScale = new Vector2(-1, 1);
                hand.localEulerAngles = new Vector3(0, 0, 90f);
            }
            else if (curDir == Utils.Dir.LEFT)
            {
                hand.localScale = new Vector2(-1, 1);
            }

            hand.localPosition = handPositions[(int)curDir];
        }
    }