Exemplo n.º 1
0
        public void CreateRoom(RoomType typeRoom, int roomID, TileAssetBlock.BlockType typeBlock, Int2 posGridBlockBottomLeft, Int2 posGridBlockTopRight, bool shouldSetTemporary)
        {
            if (shouldSetTemporary)
            {
                RoomIDTemporary         = roomID;
                this.typeRoomTemporary  = typeRoom;
                this.typeBlockTemporary = typeBlock;
            }
            else
            {
                RoomID         = roomID;
                this.typeRoom  = typeRoom;
                this.typeBlock = typeBlock;
            }


            TileAssetBlock tileAssetBlock = AssetManager.GetInstance().GetTileAssetBlockForRoomType(typeRoom);

            if (!shouldSetTemporary)
            {
                isRoom = tileAssetBlock.IsRoom;
            }
            SetPosTileAssetBlock(posGridBlockBottomLeft, posGridBlockTopRight, posGrid, tileAssetBlock, shouldSetTemporary);
            ShipMesh.GetInstance().UpdateTileAsset(posGrid);
        }
Exemplo n.º 2
0
    public Int2 GetAssetForTile(ShipGrid.Tile tile, Sorting sorting)
    {
        bool hasTemporarySettings = tile.HasTemporarySettings();

        ShipGrid.Tile.RoomType roomType       = tile.GetRoomType(shouldGetTemporary: hasTemporarySettings);
        TileAssetBlock         tileAssetBlock = GetTileAssetBlockForRoomType(roomType);
        Int2 posTileAssetBlock = tile.GetPosTileAssetBlock(shouldGetTemporary: hasTemporarySettings);

        return(tileAssetBlock.GetPosTexture(posTileAssetBlock, tile.GetBlockType(shouldGetTemporary: hasTemporarySettings), sorting));
    }
Exemplo n.º 3
0
    void DrawDraggedOutTiles(bool isTemporary)
    {
        if (ShipGrid.GetInstance().GetTile(posGridStart).GetIsRoom())
        {
            return;
        }

        Int2 posGridRoomStart = posGridStart;
        Int2 posGridRoomEnd   = posGridEnd;

        TileAssetBlock.BlockType typeBlock      = TileAssetBlock.BlockType.None;
        TileAssetBlock           tileAssetBlock = AssetManager.GetInstance().GetTileAssetBlockForRoomType(roomTypeCurrent);

        // Block
        if (posGridEnd.y - posGridStart.y != 0 && tileAssetBlock.HasAnyValueInBlock())
        {
            rotation  = Direction.None;
            typeBlock = TileAssetBlock.BlockType.Block;
        }

        // Line
        else if (posGridEnd.x - posGridStart.x != 0 && tileAssetBlock.HasAnyValueInLine())
        {
            rotation         = Direction.None;
            typeBlock        = TileAssetBlock.BlockType.Line;
            posGridRoomEnd.y = posGridRoomStart.y;
        }

        // Single
        else if (tileAssetBlock.HasAnyValueInSingle())
        {
            typeBlock      = TileAssetBlock.BlockType.Single;
            posGridRoomEnd = posGridRoomStart;
        }

        // Fail
        else
        {
            Debug.LogError(roomTypeCurrent + "'s TileAssetBlock doesn't contain any data!");
        }

        Int2 newPosGridRoomBottomLeft = new Int2(Mathf.Min(posGridRoomStart.x, posGridRoomEnd.x), Mathf.Min(posGridRoomStart.y, posGridRoomEnd.y));
        Int2 newPosGridRoomTopRight   = new Int2(Mathf.Max(posGridRoomStart.x, posGridRoomEnd.x), Mathf.Max(posGridRoomStart.y, posGridRoomEnd.y));

        Int2 newCoveredTileCount = new Int2();

        newCoveredTileCount.x = (newPosGridRoomTopRight.x - newPosGridRoomBottomLeft.x) + 1;
        newCoveredTileCount.y = (newPosGridRoomTopRight.y - newPosGridRoomBottomLeft.y) + 1;

        if (newCoveredTileCount.y > 1)
        {
            if (posGridEnd.y > posGridStart.y)
            {
                newPosGridRoomBottomLeft.y -= (newCoveredTileCount.y - 1);
            }
            else
            {
                newPosGridRoomTopRight.y += (newCoveredTileCount.y - 1);
            }
            newCoveredTileCount.y = newCoveredTileCount.y * 2 - 1;
        }

        Int2 gridSize = ShipGrid.GetInstance().GetSize();

        bool isColliding = false;

        for (int x = 0; x < newCoveredTileCount.x; x++)
        {
            if (isColliding)
            {
                break;
            }

            for (int y = 0; y < newCoveredTileCount.y; y++)
            {
                Int2 tilePosGrid = newPosGridRoomBottomLeft + new Int2(x, y);
                tilePosGrid.x = Mathf.Clamp(tilePosGrid.x, 0, gridSize.x);
                tilePosGrid.y = Mathf.Clamp(tilePosGrid.y, 0, gridSize.y);

                ShipGrid.Tile tile = ShipGrid.GetInstance().GetTile(tilePosGrid);
                isColliding = tile.GetIsRoom();

                Vector2 size     = new Vector2(gridSize.x, gridSize.y);
                Vector2 worldPos = (Vector2)ShipGrid.GetInstance().transform.position - (size / 2) + new Vector2(tilePosGrid.x, tilePosGrid.y) + new Vector2(0.5f, 0.5f);
                float   duration = 100.0f;
                float   length   = 0.25f;
                Debug.DrawLine(worldPos + length * Vector2.up, worldPos + length * Vector2.right, Color.magenta, duration);
                Debug.DrawLine(worldPos + length * Vector2.right, worldPos + length * Vector2.down, Color.magenta, duration);
                Debug.DrawLine(worldPos + length * Vector2.down, worldPos + length * Vector2.left, Color.magenta, duration);
                Debug.DrawLine(worldPos + length * Vector2.left, worldPos + length * Vector2.up, Color.magenta, duration);
            }
        }

        if (isColliding)
        {
            newCoveredTileCount      = lastCoveredTileCount;
            newPosGridRoomBottomLeft = lastPosGridRoomBottomLeft;
            newPosGridRoomTopRight   = lastPosGridRoomTopRight;
        }
        lastPosGridRoomBottomLeft = newPosGridRoomBottomLeft;
        lastPosGridRoomTopRight   = newPosGridRoomTopRight;
        lastCoveredTileCount      = newCoveredTileCount;

        affectedTileCount = newCoveredTileCount.x * newCoveredTileCount.y;
        if (affectedTiles == null || affectedTiles.Length < affectedTileCount)
        {
            affectedTiles = new Int2[affectedTileCount];
        }

        int roomID = ShipGrid.Tile.GetUniqueRoomID(newPosGridRoomBottomLeft);

        for (int x = 0; x < newCoveredTileCount.x; x++)
        {
            for (int y = 0; y < newCoveredTileCount.y; y++)
            {
                Int2 tilePosGrid = newPosGridRoomBottomLeft + new Int2(x, y);
                tilePosGrid.x = Mathf.Clamp(tilePosGrid.x, 0, gridSize.x);
                tilePosGrid.y = Mathf.Clamp(tilePosGrid.y, 0, gridSize.y);

                ShipGrid.Tile tile = ShipGrid.GetInstance().GetTile(tilePosGrid);
                tile.SetRotation(rotation, isTemporary);
                tile.CreateRoom(roomTypeCurrent, roomID, typeBlock, newPosGridRoomBottomLeft, newPosGridRoomTopRight, isTemporary);
                affectedTiles[y * newCoveredTileCount.x + x] = tilePosGrid;
            }
        }
    }
Exemplo n.º 4
0
        void SetPosTileAssetBlock(Int2 posGridBlockBottomLeft, Int2 posGridBlockTopRight, Int2 posGridTile, TileAssetBlock tileAssetBlock, bool shouldSetTemporary)
        {
            if (posGridBlockTopRight.x == 0 && posGridBlockTopRight.y == 0)
            {
                if (shouldSetTemporary)
                {
                    posTileAssetBlockTemporary = Int2.zero;
                }
                else
                {
                    posTileAssetBlock = Int2.zero;
                }
            }
            else
            {
                Int2 posBlock                      = posGridTile - posGridBlockBottomLeft;
                Int2 posBlockMax                   = posGridBlockTopRight - posGridBlockBottomLeft;
                Int2 posBlockCenter                = posBlockMax / 2;
                Int2 newPosTileAssetBlock          = Int2.zero;
                TileAssetBlock.BlockType blockType = GetBlockType(shouldSetTemporary);
                switch (blockType)
                {
                case TileAssetBlock.BlockType.None:
                    break;

                case TileAssetBlock.BlockType.Block:
                    // x
                    if (posBlock.x == posBlockMax.x)
                    {
                        newPosTileAssetBlock.x = 2;
                    }
                    else if (posBlock.x > 0)
                    {
                        newPosTileAssetBlock.x = 1;
                    }
                    else
                    {
                        newPosTileAssetBlock.x = 0;
                    }

                    // y
                    if (posBlock.y > posBlockCenter.y)
                    {
                        if (posBlock.y == posBlockMax.y)
                        {
                            newPosTileAssetBlock.y = 2;
                        }
                        else
                        {
                            newPosTileAssetBlock.y = 1;
                        }
                    }
                    else if (posBlock.y < posBlockCenter.y)
                    {
                        if (posBlock.y == 0)
                        {
                            newPosTileAssetBlock.y = -2;
                        }
                        else
                        {
                            newPosTileAssetBlock.y = -1;
                        }
                    }
                    else
                    {
                        newPosTileAssetBlock.y = 0;
                    }
                    break;

                case TileAssetBlock.BlockType.Line:
                    // x
                    if (posBlock.x == posBlockMax.x)
                    {
                        newPosTileAssetBlock.x = 2;
                    }
                    else if (posBlock.x > 0)
                    {
                        newPosTileAssetBlock.x = 1;
                    }
                    else
                    {
                        newPosTileAssetBlock.x = 0;
                    }

                    // y
                    newPosTileAssetBlock.y = 0;
                    break;

                case TileAssetBlock.BlockType.Single:
                    newPosTileAssetBlock.x = 0;
                    newPosTileAssetBlock.y = 0;
                    break;

                default:
                    Debug.LogError(blockType + " hasn't been properly implemented yet!");
                    break;
                }

                if (shouldSetTemporary)
                {
                    posTileAssetBlockTemporary = newPosTileAssetBlock;
                }
                else
                {
                    posTileAssetBlock = newPosTileAssetBlock;
                }
            }
        }