Ejemplo n.º 1
0
    public void Build()
    {
        Debug.Log($"Let's build the building: {buildingType}!");

        // Construct prefab
        Building createdBuilding = Instantiate(myBuildingPrefab);

        createdBuilding.Rotation = myRotation;
        createdBuilding.UpdateRotationSprite();

        this.world.AddBuilding(createdBuilding);

        foreach (BuildingSelectionSquare square in mySquares)
        {
            CodeTile curTile = square.TileUnderneath;

            // Both:
            curTile.ParentBuilding = createdBuilding;


            // Buildings:
            if (square.myType == BuildingSelectionSquare.Type.building)
            {
                curTile.UpdateTileType(CodeTile.Type.building);
                createdBuilding.TilesUnderneath.Add(curTile);
            }

            // Entrances:
            else
            {
                createdBuilding.Entrances.Add(curTile);

                if (createdBuilding.sign == null)
                {
                    SignPost sign = CreateSignPost(square.TileUnderneath.posX, square.TileUnderneath.posY, myRotation);
                    createdBuilding.sign = sign;
                    //sign.transform.SetParent(createdBuilding.transform);
                }
            }
        }
        this.world.TileMapUpdate();

        // Modify prefab:
        BuildingSelectionSquare bottomLeft = GetBottomLeftSquare();

        createdBuilding.originX = this.originX + bottomLeft.relativeX;
        createdBuilding.originY = this.originY + bottomLeft.relativeY;

        // Play sound effect

        // Notification:
        world.notificationCanvas.AddNotification(Notification.Type.userAction, $"Successfully constructed {createdBuilding.Name}.");
    }
Ejemplo n.º 2
0
    private void SetTileTypeFromChar(int row, int col, char c)
    {
        CodeTile curTile = WorldTiles[row][col];

        switch (c)
        {
        case 'T':
            curTile.UpdateTileType(CodeTile.Type.tree);
            TreeTiles.Add(curTile);
            break;

        case 'S':
            curTile.UpdateTileType(CodeTile.Type.stone);
            StoneTiles.Add(curTile);
            break;

        case 'W':
            curTile.UpdateTileType(CodeTile.Type.water);
            break;

        case 'D':
            curTile.UpdateTileType(CodeTile.Type.road);
            curTile.isPath = true;
            RoadTiles.Add(curTile);
            break;

        case '1':
            curTile.UpdateTileType(CodeTile.Type.road);
            curTile.isPath    = true;
            curTile.isMapEdge = true;
            curTile.mapEdgeId = 1;
            SpawnTiles.Add(curTile);
            RoadTiles.Add(curTile);
            break;

        case '2':
            curTile.UpdateTileType(CodeTile.Type.road);
            curTile.isPath    = true;
            curTile.isMapEdge = true;
            curTile.mapEdgeId = 2;
            SpawnTiles.Add(curTile);
            RoadTiles.Add(curTile);
            break;

        case '3':
            curTile.UpdateTileType(CodeTile.Type.road);
            curTile.isPath    = true;
            curTile.isMapEdge = true;
            curTile.mapEdgeId = 3;
            SpawnTiles.Add(curTile);
            RoadTiles.Add(curTile);
            break;

        case '4':
            curTile.UpdateTileType(CodeTile.Type.road);
            curTile.isPath    = true;
            curTile.isMapEdge = true;
            curTile.mapEdgeId = 4;
            SpawnTiles.Add(curTile);
            RoadTiles.Add(curTile);
            break;

        case '5':
            curTile.UpdateTileType(CodeTile.Type.road);
            curTile.isPath    = true;
            curTile.isMapEdge = true;
            curTile.mapEdgeId = 5;
            SpawnTiles.Add(curTile);
            RoadTiles.Add(curTile);
            break;

        default:
            break;
        }
    }