コード例 #1
0
ファイル: MapGenerator.cs プロジェクト: Devnithz/RPG-1
 void loadMap(TileMapItem[,] map, int w, int h)
 {
     for (int i = 0; i < w; i++)
     {
         for (int j = 0; j < h; j++)
         {
             GenerateTile(map[j, i], i, j);
         }
     }
 }
コード例 #2
0
    void GenerateTile(TileMapItem itm, int _x, int _y)
    {
        if (itm.layer1 >= 0)
        {
            Vector3     pos  = new Vector3(_x * 16, _y * 16, 1);
            Quaternion  qrt  = Quaternion.identity;
            GameObject  inst = Instantiate(tile, pos, qrt) as GameObject;
            TileChanges tc   = inst.GetComponent <TileChanges>();

            tc.changeTile(itm.layer1);
            tc.updateCollision(false);

            _mapTiles.Add(inst);
        }
        if (itm.layer2 >= 0)
        {
            Vector3     pos  = new Vector3(_x * 16, _y * 16, 0);
            Quaternion  qrt  = Quaternion.identity;
            GameObject  inst = Instantiate(tile, pos, qrt) as GameObject;
            TileChanges tc   = inst.GetComponent <TileChanges>();

            if (itm.action != ActionTileType.Unknown)
            {
                tc.gameObject.AddComponent("ActionTile");
                tc.gameObject.GetComponent <ActionTile>()._actionType = itm.action;
                switch (itm.action)
                {
                case ActionTileType.ChangeSpriteToCollide:
                    tc.gameObject.GetComponent <ActionTile>().actionValue     = itm.value;
                    tc.gameObject.GetComponent <ActionTile>().spriteCollision = true;

                    break;

                case ActionTileType.ChangeSpriteToNotCollide:

                    tc.gameObject.GetComponent <ActionTile>().actionValue     = itm.value;
                    tc.gameObject.GetComponent <ActionTile>().spriteCollision = false;

                    break;

                case ActionTileType.GotoLocation:

                    tc.gameObject.collider.isTrigger = true;
                    tc.gameObject.GetComponent <ActionTile>().actionValue = itm.value;
                    tc.gameObject.GetComponent <ActionTile>().tooltip     = "has action";

                    break;
                }
            }
            _mapTiles.Add(inst);

            tc.changeTile(itm.layer2);
            tc.updateCollision(itm.collide);
        }
    }
コード例 #3
0
ファイル: MapGenerator.cs プロジェクト: Devnithz/RPG-1
    void GenerateTile(TileMapItem itm, int _x, int _y)
    {
        if(itm.layer1 >= 0) {
            Vector3 pos = new Vector3(_x * 16, _y * 16, 1);
            Quaternion qrt = Quaternion.identity;
            GameObject inst = Instantiate(tile, pos, qrt) as GameObject;
            TileChanges tc = inst.GetComponent<TileChanges>();

            tc.changeTile(itm.layer1);
            tc.updateCollision(false);

            _mapTiles.Add(inst);
        }
        if (itm.layer2 >= 0)
        {
            Vector3 pos = new Vector3(_x * 16, _y * 16, 0);
            Quaternion qrt = Quaternion.identity;
            GameObject inst = Instantiate(tile, pos, qrt) as GameObject;
            TileChanges tc = inst.GetComponent<TileChanges>();

            if (itm.action != ActionTileType.Unknown)
            {
                tc.gameObject.AddComponent("ActionTile");
                tc.gameObject.GetComponent<ActionTile>()._actionType = itm.action;
                switch (itm.action)
                {
                    case ActionTileType.ChangeSpriteToCollide:
                        tc.gameObject.GetComponent<ActionTile>().actionValue = itm.value;
                        tc.gameObject.GetComponent<ActionTile>().spriteCollision = true;

                        break;
                    case ActionTileType.ChangeSpriteToNotCollide:

                        tc.gameObject.GetComponent<ActionTile>().actionValue = itm.value;
                        tc.gameObject.GetComponent<ActionTile>().spriteCollision = false;

                        break;
                    case ActionTileType.GotoLocation:

                        tc.gameObject.collider.isTrigger = true;
                        tc.gameObject.GetComponent<ActionTile>().actionValue = itm.value;
                        tc.gameObject.GetComponent<ActionTile>().tooltip = "has action";

                        break;
                }
            }
            _mapTiles.Add(inst);

            tc.changeTile(itm.layer2);
            tc.updateCollision(itm.collide);
        }
    }
コード例 #4
0
ファイル: Map.cs プロジェクト: LuckyBYR/RPG
    public static TileMapItem[,] getMap()
    {
        TileMapItem fl = new TileMapItem();

        fl.layer1 = 6; fl.layer2 = -1; fl.collide = false;
        TileMapItem wl = new TileMapItem();

        wl.layer1 = 6; wl.layer2 = 2; wl.collide = true;
        TileMapItem dr = new TileMapItem();

        dr.layer1 = 6; dr.layer2 = 14; dr.collide = true;
        dr.action = ActionTileType.ChangeSpriteToNotCollide;
        dr.value  = TILE_DOOR_WOOD_OPEN;

        TileMapItem tt = new TileMapItem();

        tt.layer1 = 6; tt.collide = true; tt.layer2 = TILE_CARPET;
        tt.action = ActionTileType.GotoLocation;
        tt.value  = new int[2] {
            6, 6
        };

        TileMapItem bb = new TileMapItem();

        bb.layer1 = 6; bb.collide = true; bb.layer2 = TILE_STAIR_DOWN;
        // bb.action = ActionTileType.ba;
        bb.value = new int[2] {
            6, 6
        };

        TileMapItem[,] tilemap = new TileMapItem[10, 10] {
            { wl, wl, wl, wl, wl, dr, wl, wl, wl, wl },
            { wl, fl, fl, fl, fl, fl, fl, fl, fl, wl },
            { wl, fl, fl, fl, fl, fl, fl, fl, fl, wl },
            { wl, fl, fl, fl, fl, fl, fl, fl, fl, dr },
            { wl, fl, fl, fl, fl, fl, fl, fl, fl, wl },
            { dr, fl, fl, fl, fl, fl, fl, fl, fl, wl },
            { wl, fl, fl, fl, fl, fl, fl, fl, fl, dr },
            { wl, fl, fl, fl, fl, fl, fl, fl, fl, wl },
            { wl, tt, fl, fl, fl, fl, fl, fl, fl, wl },
            { wl, wl, wl, wl, dr, wl, wl, wl, wl, wl }
        };

        return(tilemap);
    }
コード例 #5
0
ファイル: Map.cs プロジェクト: Devnithz/RPG-1
    public static TileMapItem[,] getMap()
    {
        TileMapItem fl = new TileMapItem();
        fl.layer1 = 6; fl.layer2 = -1; fl.collide = false;
        TileMapItem wl = new TileMapItem();
        wl.layer1 = 6; wl.layer2 = 2; wl.collide = true;
        TileMapItem dr = new TileMapItem();
        dr.layer1 = 6; dr.layer2 = 14; dr.collide = true;
        dr.action = ActionTileType.ChangeSpriteToNotCollide;
        dr.value = TILE_DOOR_WOOD_OPEN;

        TileMapItem tt = new TileMapItem();
        tt.layer1 = 6; tt.collide = true; tt.layer2 = TILE_CARPET;
        tt.action = ActionTileType.GotoLocation;
        tt.value = new int[2] { 6, 6 };

        TileMapItem bb = new TileMapItem();
        bb.layer1 = 6; bb.collide = true; bb.layer2 = TILE_STAIR_DOWN;
        // bb.action = ActionTileType.ba;
        bb.value = new int[2] { 6, 6 };

        TileMapItem[,] tilemap = new TileMapItem[10, 10] {
            { wl, wl, wl, wl, wl, dr, wl, wl, wl, wl },
            { wl, fl, fl, fl, fl, fl, fl, fl, fl, wl },
            { wl, fl, fl, fl, fl, fl, fl, fl, fl, wl },
            { wl, fl, fl, fl, fl, fl, fl, fl, fl, dr },
            { wl, fl, fl, fl, fl, fl, fl, fl, fl, wl },
            { dr, fl, fl, fl, fl, fl, fl, fl, fl, wl },
            { wl, fl, fl, fl, fl, fl, fl, fl, fl, dr },
            { wl, fl, fl, fl, fl, fl, fl, fl, fl, wl },
            { wl, tt, fl, fl, fl, fl, fl, fl, fl, wl },
            { wl, wl, wl, wl, dr, wl, wl, wl, wl, wl }
        };

        return tilemap;
    }