Exemple #1
0
    // Place an invalid block into the right neigbhor chunk.
    private void PlaceInvalidBlock(int x, int y, int z, BLOCK_TYPE block)
    {
        block = BLOCK_TYPE.Water;

        int x2 = x, z2 = z;

        if (x < 0)
        {
            x2 += 16;
            this.ChunkLeft.AddBlock(x2, y, z2, block);
            return;
        }

        if (z < 0)
        {
            z2 = 16 + z2;
            this.ChunkBack.AddBlock(x2, y, z2, block);
            return;
        }

        if (x > 15)
        {
            x2 -= 16;
            this.ChunkRight.AddBlock(x2, y, z2, block);
            return;
        }

        if (z > 15)
        {
            z2 -= 16;
            this.ChunkFront.AddBlock(x2, y, z2, block);
            return;
        }
    }
Exemple #2
0
    public void SetBaseBlock(BasePos basePos)
    {
        if (emptyRoomNum.Count <= 0)
        {
            return;
        }

        BLOCK_TYPE baseBlock   = BLOCK_TYPE.STONE;
        GameObject blockPrefab = blockManager.blockPrefabDic[baseBlock];

        int curRoomNum = emptyRoomNum[0];

        RoomData curRoom = new RoomData(curRoomNum, basePos);

        curRoom.sparseBlockInfo = new List <BlockInfo>();
        roomList.Add(curRoom);

        emptyRoomNum.RemoveAt(0);

        for (int i = 0; i < MAX_WORLD_SIZE; ++i)
        {
            for (int j = 0; j < MAX_WORLD_SIZE; ++j)
            {
                curRoom.sparseBlockInfo.Add(new BlockInfo(basePos.x + i, basePos.y + 0, basePos.z + j, baseBlock, 0.0f));
                updateBlockInfo.Push(new BlockInfo(basePos.x + i, basePos.y + 0, basePos.z + j, baseBlock, 0.0f));
                roomNumDic.Add(new Vector3(basePos.x + i, 0, basePos.z + j), curRoomNum);
            }
        }

        return;
    }
Exemple #3
0
    public static void SetBlock(Vector3 position, BLOCK_TYPE block)
    {
        var globalPosition = StepifyVector(position);

        int localX = (int)globalPosition.x % 16;
        int localZ = (int)globalPosition.z % 16;

        if (localX < 0)
        {
            localX += 16;
        }
        if (localZ < 0)
        {
            localZ += 16;
        }

        var localPosition = new Vector3(localX, globalPosition.y, localZ);

        int chunkX        = (int)Mathf.Stepify(globalPosition.x, 16) / 16;
        int chunkZ        = (int)Mathf.Stepify(globalPosition.z, 16) / 16;
        var chunkPosition = new Vector2(chunkX, chunkZ);

        var chunk = GetChunk(chunkPosition);

        chunk.AddBlock(localPosition, block);

        if (!m_ChunkRebuildList.Contains(chunk.Position))
        {
            m_ChunkRebuildList.Add(chunk.Position);
        }
    }
Exemple #4
0
 public BlockInfo(int posX, int posY, int posZ, BLOCK_TYPE type, float rotation)
 {
     this.posX     = (short)posX;
     this.posY     = (short)posY;
     this.posZ     = (short)posZ;
     this.type     = type;
     this.rotation = rotation;
 }
Exemple #5
0
 /// <summary>
 /// Constructor for the Tile. Initilazing the frame for the tile,
 /// Boolean that tells if the block is passable, and the type of the block
 /// </summary>
 /// <param name="r">Frame for the block</param>
 /// <param name="passable">Is it passable</param>
 /// <param name="bt">Type of the block</param>
 public Tile(Rectangle rectangle, bool passable, BLOCK_TYPE bt)
 {
     Rectangle    = rectangle;
     IsPassable   = passable;
     type         = bt;
     ContainsBomb = false;
     time         = new Timer();
     hasItem      = false;
 }
Exemple #6
0
        public static Color GetColor(BLOCK_TYPE type, int x, int z)
        {
            var color = m_Palette[type];

            if (type == BLOCK_TYPE.Grass)
            {
                color = color.LinearInterpolate(new Color(1, 1, 0), NoiseMaker.GetHumidity(x, z));
            }

            return(color);
        }
Exemple #7
0
 void AddBlockPrefabToDictionary(Object[] prefabList)
 {
     Debug.Log("AddBlockPrefabToDictionary Called");
     foreach (GameObject prefab in prefabList)
     {
         // Add to Dictionary
         BLOCK_TYPE bType = prefab.GetComponent <BlockScript>().bType;
         blockPrefabDic.Add(bType, prefab);
         Debug.LogWarning("Append blockPrefabDic : " + bType + " , " + prefab.name);
     }
 }
Exemple #8
0
 void LoadMapFromJSON(JSONNode nodes)
 {
     for (int i = 0; i < nodes.Count; ++i)
     {
         List <JSONNode> nodeInfo = nodes[i].Childs.ToList();
         BLOCK_TYPE      bType    = (BLOCK_TYPE)System.Enum.Parse(typeof(BLOCK_TYPE), nodeInfo[3]);
         sparseBlockInfo.Add(new BlockInfo(
                                 nodeInfo[0].AsInt,
                                 nodeInfo[1].AsInt,
                                 nodeInfo[2].AsInt,
                                 bType,
                                 nodeInfo[4].AsFloat
                                 ));
     }
 }
Exemple #9
0
    // Adds a block into a subchunk from globalposition using ints.
    public void AddBlock(int x, int y, int z, BLOCK_TYPE block)
    {
        if (!IsPositionValid(x, y, z))
        {
            GD.Print("Invalid block palced");
            PlaceInvalidBlock(x, y, z, block);
            return;
        }

        int subChunkIndex  = GetSubChunkIdFromHeight(y);
        int subChunkHeight = y - ((int)CHUNK_SIZE * (subChunkIndex));
        var localPosition  = new Vector3(x, subChunkHeight, z);

        m_SubChunks[subChunkIndex].AddBlock(localPosition, block);
    }
Exemple #10
0
    public void SetBlock(Vector3 selectedPos, BLOCK_TYPE bType, Quaternion rotation)
    {
        Vector3 vec = selectedPos;

        vec.y = 0.0f;

        int curRoomNum = roomNumDic[vec];

        curRoom = roomList.Find(r => r.roomNumber == curRoomNum);
        Debug.LogError(curRoomNum + ", " + curRoom.roomNumber);

        Vector3 rot    = rotation.eulerAngles;
        var     rotate = rot.y;

        curRoom.sparseBlockInfo.Add(new BlockInfo((int)selectedPos.x, (int)selectedPos.y, (int)selectedPos.z, bType, rotate));
        updateBlockInfo.Push(new BlockInfo((int)selectedPos.x, (int)selectedPos.y, (int)selectedPos.z, bType, rotate));
    }
Exemple #11
0
    // Adds a block in this subchunk.
    public void AddBlock(Vector3 position, BLOCK_TYPE block)
    {
        int x = (int)position.x;
        int y = (int)position.y;
        int z = (int)position.z;

        // If we are adding an empty block, just remove it.
        if (block is BLOCK_TYPE.Empty)
        {
            RemoveBlock(position);
            return;
        }

        // Update flags for each side.
        if (y == Chunk.CHUNK_SIZE - 1)
        {
            m_topCount++;
        }
        if (y == 0)
        {
            m_bottomCount++;
        }
        if (x == Chunk.CHUNK_SIZE - 1)
        {
            m_rightCount++;
        }
        if (x == 0)
        {
            m_leftCount++;
        }
        if (z == Chunk.CHUNK_SIZE - 1)
        {
            m_frontCount++;
        }
        if (z == 0)
        {
            m_backCount++;
        }


        // Sets the block and update the total count.
        m_Blocks[x, y, z] = (int)block;

        Chunk.Updated = false;
        BlockCount++;
    }
Exemple #12
0
    void HitItemBlock()
    {
        BlockLife--;
        if (ItemType == ItemController.ITEM_TYPE.ITEM_COIN)
        {
            GameObject GameRule = GameObject.Find("GameRule");
            GameRule   Rule     = GameRule.GetComponent("GameRule") as GameRule;
            Rule.GetCoin();
            se.SEPlay(SEController.SE_LABEL.SE_COIN);
        }
        var Root     = GameObject.Find("ItemRoot");
        var ItemCtrl = Root.GetComponent("ItemController") as ItemController;

        ItemCtrl.GenerateItem(ItemType, transform.position);
        if (BlockLife == 0)
        {
            gameObject.renderer.material.color       = new Color(1, 1, 1, 0);
            gameObject.renderer.material.mainTexture = null;
            BlockType = BLOCK_TYPE.NONE_BLOCK;
        }
    }
Exemple #13
0
 public BlockObject()
 {
     Block_Type = BLOCK_TYPE.BLOCKOBJECT;
 }
Exemple #14
0
 public Block(char blockType)
 {
     BlockType = (BLOCK_TYPE) blockType;
     IsEmpty = true;
 }
Exemple #15
0
 public Block(BLOCK_TYPE blockType)
 {
     BlockType = blockType;
     IsEmpty = true;
 }
Exemple #16
0
 public Block()
 {
     IsEmpty = true;
     BlockType = BLOCK_TYPE.Floor;
 }
Exemple #17
0
 // Adds a block into a subchunk from globalposition using Vector3.
 public void AddBlock(Vector3 position, BLOCK_TYPE block)
 {
     AddBlock((int)position.x, (int)position.y, (int)position.z, block);
 }