Пример #1
0
    /// <summary>
    /// Remove a block from the blockmap, not leaving its resources on ThingMap
    /// </summary>
    public bool RemoveWall(int x, int y, BlockType type)
    {
        switch (type)
        {
        case BlockType.Wall:
            return(BlockMap.SetBlock(x, y, Option.None <Wall>()));

        case BlockType.Tile:
            return(TileMap.SetBlock(x, y, Option.None <Tile>()));
        }
        return(false);
    }
Пример #2
0
    public override void _Ready()
    {
        MainMap = this;

        //Gets tilemap children
        BlockMap = (BlockMap)GetNode("BlockMap");
        TileMap  = (TileMap)GetNode("TileMap");
        ThingMap = (ThingMap)GetNode("ThingMap");

        BlockMapTiles = BlockMap.Map;
        TileMapTiles  = TileMap.Map;
        //ThingMapTiles = ThingMap.Map; <- ???

        if (new Tile().GetBlocks().Find(x => x.Name.ToLower() == "grass_block" && x.GetType() == typeof(Tile)) is Tile tile)
        {
            TileMap.Fill(Option.Some(tile));
        }

        //else throw new Exception("NO_GRASS_TILE_FOUND");

        // Adding pre applied blocks
        for (int x = 0; x < BlockMap.Map.GetLength(0); x++)
        {
            for (int y = 0; y < BlockMap.Map.GetLength(1); y++)
            {
                BlockMap.Map[x, y] = BlockMap.GetCell(x, y) == -1 ? Option.None <Wall>() : Option.Some(new Wall()
                {
                    Name = ""
                });
            }
        }

        if (new Wall().GetBlocks().Find(x => x.Name.ToLower() == "mine" && x.GetType() == typeof(Wall)) is Wall bloc2k)
        {
            BlockMap.SetBlock(3, 3, Option.Some(bloc2k));
        }

        if (new Wall().GetBlocks().Find(x => x.Name.ToLower() == "mine" && x.GetType() == typeof(Wall)) is Wall block)
        {
            BlockMap.SetBlock(2, 2, Option.Some(block));
        }


        CollisionFor("link.png", Shape.Capsule).MatchSome(x => SpawnBeing(new Robot("Ribbit")
        {
            Speed = 3
        }, new Vector2(50, 50), "link.png", new Vector2(0.2f, 0.2f), x));
        CollisionFor("link.png", Shape.Capsule).MatchSome(x => SpawnBeing(new Robot("Snakeoil")
        {
            Speed = 3
        }, new Vector2(100, 100), "link.png", new Vector2(0.2f, 0.2f), x));
    }
Пример #3
0
 /// <summary>
 /// Adds a block to the blockmap.
 /// </summary>
 public bool AddBlock(int x, int y, Block block)
 {
     if (block is Wall wall)
     {
         return(BlockMap.SetBlock(x, y, Option.Some(wall)));
     }
     else if (block is Tile tile)
     {
         return(TileMap.SetBlock(x, y, Option.Some(tile)));
     }
     else
     {
         return(false);
     }
 }
Пример #4
0
    public void CreateField(string CsvName, Transform parent, BlockMap block_map)
    {
        //文字検索用
        int[]      iDat = new int[4];
        GameObject cube = null;
        //CSVの全文字列を保存する
        string str = "";
        //取り出した文字列を保存する
        string    strget   = "";
        int       Xcubepos = 0;
        int       Zcubepos = 0;
        TextAsset csvfile  = Resources.Load("csv/" + CsvName) as TextAsset;
        //文字列読み取る
        StringReader reader = new StringReader(csvfile.text);

        //戻り値:使用できる文字がないか、ストリームがシークをサポートしていない場合は -1
        while (reader.Peek() > -1)
        {
            string line = reader.ReadLine();
            //真ん中の点が無いと12とか21が出るよ
            str = str + "," + line;
        }

        //最後に検索文字列の","を追記。最後を取りこぼす
        str = str + ",";


        for (int z = 0; z < line_n; z++)
        {
            //ループするたびにxを0に。この位置からずらさないように
            Xcubepos = 0;
            for (int x = 0; x < row_n; x++)
            {
                //IndexOfメソッドは文字列内に含まれる文字、文字列の位置を取得することができる。
                iDat[0] = str.IndexOf(",", iDat[0]);
                //次の","を検索
                iDat[1] = str.IndexOf(",", iDat[0] + 1);
                //何文字取り出すか決定
                iDat[2] = iDat[1] - iDat[0] - 1;
                //iDat[2]文字ぶんだけ取り出す
                strget = str.Substring(iDat[0] + 1, iDat[2]);
                //文字列を数値型に変換
                iDat[3] = int.Parse(strget);
                //次のインデックスへ
                iDat[0]++;

                position.Set(Xcubepos, 0, Zcubepos);

                if (iDat[3] < 10)
                {
                    for (int i = 1; i <= iDat[3]; ++i)
                    {
                        position.y            = i - 1;
                        cube                  = Instantiate(StageCubes[i - 1], position, Quaternion.identity);
                        cube.transform.parent = parent;
                        block_map.SetBlock(Zcubepos, Xcubepos, i - 1, cube);
                    }
                }
                //壊れないブロック
                else
                {
                    position.y            = iDat[3] - 11;
                    cube                  = Instantiate(StrongCube, position, Quaternion.identity);
                    cube.transform.parent = parent;
                    block_map.SetBlock(Zcubepos, Xcubepos, iDat[3] - 11, cube);
                }
                //配置位置を(カメラから見て)右に移動
                Xcubepos++;
            }
            //配置位置を(カメラから見て)縦に移動
            Zcubepos++;
        }
    }