Ejemplo n.º 1
0
 // Check if the target is a crop
 protected bool IsTargetACrop()
 {
     TileData.TileType targetType = gameController.TileMap.GetTile(targetFinalPos);
     return(targetType == TileData.TileType.CropSeed ||
            targetType == TileData.TileType.CropGrowing ||
            targetType == TileData.TileType.CropMature);
 }
Ejemplo n.º 2
0
    static TileBook()
    {
        // Load tile prefabs from folder
        Tile[] tilePrefabs = Resources.LoadAll <Tile>("Prefabs/Tiles");
        // Initialise dictionary for tiles and indices
        tiles       = new Dictionary <string, Tile>(tilePrefabs.Length);
        tileIndices = new Dictionary <int, string>(tilePrefabs.Length);
        tileData    = new Dictionary <string, TileData>(tilePrefabs.Length);

        int index = 0;

        // Fill dictionary for tile and indices from loaded resources
        foreach (Tile tile in tilePrefabs)
        {
            tiles.Add(tile.name, tile);
            tileIndices.Add(index, tile.name);

            TileData          data     = new TileData();
            bool              canBuild = !(tile.name == "Wall" || tile.name == "Object");
            bool              canBlock = (tile.name == "Wall");
            TileData.TileType type     = (tile.name == "Object" || tile.name == "NullObject") ? TileData.TileType.ObjectTile : TileData.TileType.WorldTile;
            data.SetTileType(type);
            data.SetCanBuildUpon(canBuild);
            data.SetCanBlockAir(canBlock);
            data.SetIsSealed(false);

            tileData.Add(tile.name, data);

            index++;
        }
    }
Ejemplo n.º 3
0
    // Adds or removes crop tiles in an array list of all currently growing tiles
    public void UpdateCropArray(TileCoordinate tilePos, TileData.TileType type)
    {
        if (type == TileData.TileType.CropSeed)
        {
            _currentedPlantedCrops.Add(new KeyValuePair <TileCoordinate, TileData.TileType>(tilePos, type));
            //Debug.Log("ADDED TILE TO CROP ARRAY x:" + tilePos.CoordX + " z:" + tilePos.CoordZ + " Type: " + type);
        }
        else if (type == TileData.TileType.PlantableCooldown)
        {
            int  curIndex    = -1;
            int  removeIndex = -1;
            bool removeCrop  = false;
            foreach (var crop in _currentedPlantedCrops)
            {
                curIndex++;
                if (crop.Key.Equals(tilePos))
                {
                    removeCrop  = true;
                    removeIndex = curIndex;
                }
            }
            if (removeCrop)
            {
                _currentedPlantedCrops.RemoveAt(removeIndex);
                //Debug.Log("REMOVED TILE FROM CROP ARRAY x:" + tilePos.CoordX + " z:" + tilePos.CoordZ + " Type: " + type);
            }
        }

        foreach (var crop in _currentedPlantedCrops)
        {
            //Debug.Log("CROPS IN ARRAY: x:" + crop.Key.CoordX + " z:" + crop.Key.CoordZ + " Type: " + crop.Value);
        }
    }
Ejemplo n.º 4
0
    public void SetSprite(TileData.TileType newType)
    {
        // Set the sprite based on the given tile type.
        Sprite newSprite = null;

        switch (newType)
        {
        case TileData.TileType.Unoccupied:
            newSprite = spriteUnoccupied;
            break;

        case TileData.TileType.Regular:
            //int randomInt = Random.Range(0, tiles.Length);
            //newSprite = tiles[randomInt];
            newSprite = tiles[data.GetSpriteIndex()];
            break;

        case TileData.TileType.Vestige:
            newSprite = spriteVestigeList[0];
            //SyncSpriteToVestigeLevel();
            break;

        case TileData.TileType.Asteroid:
            newSprite = spriteUnoccupied;
            Animator asteroidObj = Instantiate(animationAsteroid, transform);
            asteroidObj.transform.localPosition = new Vector2(0, GetComponent <RectTransform>().rect.height * 0.18f);
            asteroidObj.GetComponent <RectTransform>().sizeDelta = new Vector2(GetComponent <RectTransform>().rect.width * 1 / 0.63f, GetComponent <RectTransform>().rect.height * 1 / 0.63f);
            asteroidObj.GetComponent <ReactorBreachBehavior>().ReferenceTile(this, spriteAsteroid);
            break;
        }
        spriteRenderer.sprite = newSprite;
    }
Ejemplo n.º 5
0
 void OnChanged(TileData.TileType newType)
 {
     if (Changed != null)
     {
         Changed(newType);
     }
 }
Ejemplo n.º 6
0
    // Create hill and lake blocks at random points in the map
    private void CreateHillsAndLakes()
    {
        for (int i = 0; i < Map.numberOfHills; i++)
        {
            int radius             = Random.Range(0, 5);
            TileData.TileType type = TileData.TileType.Hill;
            bool        isClear    = false;
            Point <int> middle     = new Point <int>();

            while (!isClear)
            {
                middle  = new Point <int> (Random.Range(5, Map.mapSizeX - 5), Random.Range(5, Map.mapSizeY - 5));
                isClear = CheckRadius(middle, radius, type);
            }

            Environment.CreateEnvironment(middle, radius, type);
        }

        for (int i = 0; i < Map.numberOfLakes; i++)
        {
            int radius             = Random.Range(0, 5);
            TileData.TileType type = TileData.TileType.Lake;
            bool        isClear    = false;
            Point <int> middle     = new Point <int>();

            while (!isClear)
            {
                middle  = new Point <int> (Random.Range(5, Map.mapSizeX - 5), Random.Range(5, Map.mapSizeY - 5));
                isClear = CheckRadius(middle, radius, type);
            }

            Environment.CreateEnvironment(middle, radius, type);
        }
    }
Ejemplo n.º 7
0
 private void Tile_Changed(TileData.TileType newType)
 {
     if (newType == TileData.TileType.Unoccupied)
     {
         tilesClearedRecently = true;
     }
 }
Ejemplo n.º 8
0
    public void PerformAction()
    {
        if (LockingInput())
        {
            return;
        }

        // If tile is plantable
        TileData.TileType type = _gameController.TileMap.GetTile(_tilePos);
        switch (type)
        {
        case TileData.TileType.Plantable:
            Plant();
            break;

        case TileData.TileType.CropMature:
            Harvest();
            break;

        case TileData.TileType.Ground:
        case TileData.TileType.PlantableCooldown:
            ShowPopupWithDelay(MSG_NOT_PLANTABLE);
            break;

        case TileData.TileType.CropSeed:
        case TileData.TileType.CropGrowing:
            ShowPopupWithDelay(MSG_NOT_MATURE);
            break;
        }
    }
Ejemplo n.º 9
0
    // Change the action icon based on the tile that the player is standing on
    private void UpdateActionIcon()
    {
        TileCoordinate playerPos = GameController.TileMap.GetPlayer().GetTilePosition();

        TileData.TileType tileType = GameController.TileMap.GetTile(playerPos);
        switch (tileType)
        {
        case TileData.TileType.Plantable:
            ActionIcon.sprite = PlantSprite;
            ActionIcon.color  = Color.white;
            break;

        case TileData.TileType.Ground:
        case TileData.TileType.PlantableCooldown:
            ActionIcon.sprite = PlantSprite;
            ActionIcon.color  = FADED_COLOUR;
            break;

        case TileData.TileType.CropSeed:
        case TileData.TileType.CropGrowing:
            ActionIcon.sprite = HarvestSprite;
            ActionIcon.color  = FADED_COLOUR;
            break;

        case TileData.TileType.CropMature:
            ActionIcon.sprite = HarvestSprite;
            ActionIcon.color  = Color.white;
            break;
        }
    }
Ejemplo n.º 10
0
 public void SetAnticipatedHighlight(TileData.TileType type)
 {
     if (type == TileData.TileType.Regular)
     {
         spriteRenderer.color = new Color(0.0f, 0.0f, 1.0f, 0.5f);
     }
     else if (type == TileData.TileType.Vestige)
     {
         spriteRenderer.color = new Color(1.0f, 0.0f, 0.0f, 0.5f);
     }
 }
Ejemplo n.º 11
0
 // Returns true if the entire Block is made of this type of tile.
 public bool GetIsEntirely(TileData.TileType type)
 {
     foreach (TileData tile in tiles)
     {
         if (tile.GetTileType() != type)
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 12
0
    // Returns the number of tiles of a certain type in the block.
    public int GetTileCount(TileData.TileType type)
    {
        int count = 0;

        foreach (TileData t in tiles)
        {
            if (t.GetTileType() == type)
            {
                ++count;
            }
        }
        return(count);
    }
Ejemplo n.º 13
0
    public List <TileData> GetReferencesToType(TileData.TileType type)
    {
        List <TileData> result = new List <TileData>();

        foreach (TileData t in tiles)
        {
            if (t.GetTileType() == type)
            {
                result.Add(t);
            }
        }
        return(result);
    }
Ejemplo n.º 14
0
    private void checkIntegrity(Vector3Int pos)
    {
        if (foreground.GetTile(pos) != null)
        {
            SoundManager.Instance.PlayCrash((pos.x - main_cam.transform.position.x) / 100.0f);
            // Destroy House
            int x, y = pos.y;
            if (foreground.GetTile(new Vector3Int(pos.x + 3, pos.y, 0)) != null)
            {
                x = pos.x + 2;
            }
            else
            {
                x = pos.x - 1;
            }
            //Left
            foreground.SetTile(new Vector3Int(x + -2, y + 0, 0), null);
            foreground.SetTile(new Vector3Int(x + -2, y + 1, 0), null);
            foreground.SetTile(new Vector3Int(x + -2, y + 2, 0), null);
            foreground.SetTile(new Vector3Int(x + -1, y + 2, 0), null);
            foreground.SetTile(new Vector3Int(x + -1, y + 3, 0), null);
            //Right
            foreground.SetTile(new Vector3Int(x + 1, y + 0, 0), null);
            foreground.SetTile(new Vector3Int(x + 1, y + 1, 0), null);
            foreground.SetTile(new Vector3Int(x + 1, y + 2, 0), null);
            foreground.SetTile(new Vector3Int(x + 0, y + 2, 0), null);
            foreground.SetTile(new Vector3Int(x + 0, y + 3, 0), null);

            GameObject tmp_house_fx = house_fxs[x];
            house_fxs.Remove(x);
            Destroy(tmp_house_fx);

            // Kill random worker
            Destroy(workers[workers.Count - 1].gameObject);
            workers.RemoveAt(workers.Count - 1);
            if (workers.Count == 0)
            {
                should_reset = true;
            }
            return;
        }
        else if (map.GetTile(pos) == null)
        {
            return;
        }
        TileData.TileType type_below = data_from_base[map.GetTile(new Vector3Int(pos.x, pos.y - 1, 0))].type;
        if (type_below != TileData.TileType.ground_dirt_flat && type_below != TileData.TileType.gold)
        {
            mineTile(pos);
        }
    }
Ejemplo n.º 15
0
 // Place a tile on cooldown
 public void RemoveCropFromTile(TileCoordinate tilePos,
                                GameController controller, bool isResetCombo = true)
 {
     TileData.TileType type = _mapData.GetTile(tilePos);
     if (type == TileData.TileType.CropSeed ||
         type == TileData.TileType.CropGrowing ||
         type == TileData.TileType.CropMature)
     {
         SetTile(tilePos, TileData.TileType.PlantableCooldown);
         if (isResetCombo)
         {
             controller.ResetCombo();
         }
     }
 }
Ejemplo n.º 16
0
    // Helper function.
    public void Duplicate(TileData other)
    {
        TileData.TileType newType = other.GetTileType();
        Fill(newType);
        if (newType == TileData.TileType.Vestige)
        {
            int level = other.GetVestigeLevel();

            //Debug.Log("Tile.Duplicate: other vestige level: " + level);

            SetVestigeLevel(level);
        }
        int spriteIndex = other.GetSpriteIndex();

        SetSpriteIndex(spriteIndex);
    }
Ejemplo n.º 17
0
 private bool CheckRadius(Point <int> middle, int radius, TileData.TileType type)
 {
     for (int y = middle.y + radius; y >= middle.y - radius; y--)
     {
         for (int x = middle.x + radius; x >= middle.x - radius; x--)
         {
             if (Map.mapData [x, y] != null)
             {
                 if (Map.mapData [x, y].IsSameEnvironment(type))
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Ejemplo n.º 18
0
    public void Fill(TileData.TileType newType)
    {
        TileData.TileType previousType = GetTileType();
        if (previousType != newType)
        {
            // Before we actually change the tile type, check and handle special cases.
            if (newType == TileData.TileType.Unoccupied)
            {
                // Create the fading visual effects if the Tile hasn't already been cleared.
                if (previousType != TileData.TileType.Unoccupied &&
                    previousType != TileData.TileType.Uninitialized)
                {
                    CreateVanishVisualEffects();
                }
            }

            data.Fill(newType);

            SetSprite(newType);
            trueSprite = spriteRenderer.sprite;

            OnChanged(newType);
        }
    }
Ejemplo n.º 19
0
 // Returns true if the given TileType is clearable.
 // This method essentially lists all of the clearable TileTypes.
 public static bool GetIsClearableInSquare(TileData.TileType type)
 {
     return(type == TileType.Regular ||
            type == TileType.Vestige);
 }
Ejemplo n.º 20
0
 public void Fill(int row, int col, TileData.TileType newType)
 {
     tiles[row, col].Fill(newType);
 }
Ejemplo n.º 21
0
 // Set the type of the tile at the given (x, z) tile coordinate
 // and recreate the mesh to reflect the changes
 public void SetTile(TileCoordinate tilePos, TileData.TileType type)
 {
     _mapData.SetTile(tilePos, type);
     CreateMesh();
 }
Ejemplo n.º 22
0
    public static void CreateEnvironment(Point <int> middle, int radius, TileData.TileType type)
    {
        bool isWalkable;

        if (type == TileData.TileType.Hill)
        {
            isWalkable = true;
        }
        else
        {
            isWalkable = false;
        }
        Point <int> buttomLeft = new Point <int> (middle.x - radius, middle.y - radius);
        Point <int> topRight   = new Point <int> (middle.x + radius, middle.y + radius);


        if (type == TileData.TileType.Hill || type == TileData.TileType.Lake)
        {
            if (radius == 0)
            {
                Map.mapData [middle.x, middle.y] = new TileData(1, isWalkable, type);
            }
            else
            {
                for (int y = Map.mapSizeY - 1; y >= 0; y--)
                {
                    for (int x = Map.mapSizeX - 1; x >= 0; x--)
                    {
                        if (y < buttomLeft.y || y > topRight.y || x < buttomLeft.x || x > topRight.x)
                        {
                            continue;
                        }
                        else if (y == buttomLeft.y)
                        {
                            if (x == buttomLeft.x)
                            {
                                //Debug.Log ("A2");
                                Map.mapData [x, y].ChangeTile(2, isWalkable, type);
                            }
                            else if (x == topRight.x)
                            {
                                //Debug.Log ("A3");
                                Map.mapData [x, y].ChangeTile(5, isWalkable, type);
                            }
                            else if (x < topRight.x && x > buttomLeft.x)
                            {
                                //Debug.Log ("A4");
                                Map.mapData [x, y].ChangeTile(9, isWalkable, type);
                            }
                        }
                        else if (y == topRight.y)
                        {
                            if (x == topRight.x)
                            {
                                //Debug.Log ("A5");
                                Map.mapData [x, y].ChangeTile(4, isWalkable, type);
                            }
                            else if (x == buttomLeft.x)
                            {
                                //Debug.Log ("A5");
                                Map.mapData [x, y].ChangeTile(3, isWalkable, type);
                            }
                            else if (x < topRight.x && x > buttomLeft.x)
                            {
                                //Debug.Log ("A7");
                                Map.mapData [x, y].ChangeTile(7, isWalkable, type);
                            }
                        }
                        else if (x == buttomLeft.x)
                        {
                            if (y < topRight.y && y > buttomLeft.y)
                            {
                                Map.mapData [x, y].ChangeTile(6, isWalkable, type);
                            }
                        }
                        else if (x == topRight.x)
                        {
                            if (y < topRight.y && y > buttomLeft.y)
                            {
                                Map.mapData [x, y].ChangeTile(8, isWalkable, type);
                            }
                        }
                        else
                        {
                            Map.mapData [x, y].ChangeTile(1, isWalkable, type);
                        }
                    }
                }
            }
        }
    }