Пример #1
0
    public void FarmTile(FarmableTile farmableTile)
    {
        if (!goblinInventory.ContainsItemType(goblinAction))
        {
            return;
        }
        switch (goblinAction)
        {
        case ItemAction.Harvest: farmableTile.Harvest(); break;

        case ItemAction.Seed:
        {
            GetPlantSeed();
            if (indexOfPlant == -1)
            {
                return;
            }
            farmableTile.PlantSomething(plantInfo);
            goblinInventory.ReduceItemAt(indexOfPlant, 1);
            break;
        }

        case ItemAction.Plow: farmableTile.PlowField(); break;

        case ItemAction.Water: farmableTile.WaterPlant(); break;
        }
    }
 public void StopTrackingPosition()
 {
     toolSelected = false;
     tileSelector.SetActive(false);
     currentFarmableTileSelected = null;
     StopAllCoroutines();
 }
Пример #3
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == "Tillable")
     {
         activeTile = other.GetComponent <FarmableTile>();
     }
 }
Пример #4
0
    /// <summary>
    /// Move towards destination first in x direction, then in y direction.
    /// </summary>
    private void MoveTowardsDestination()
    {
        int     xDirection = Utility.GetXDirection(transform.position, currentDestination, walkSpeed);
        Vector2 pos        = transform.position;

        if (xDirection != 0)
        {
            transform.position = new Vector2(pos.x + walkSpeed * xDirection, pos.y);
        }
        else
        {
            int yDirection = Utility.GetYDirection(transform.position, currentDestination, walkSpeed);
            if (yDirection != 0)
            {
                transform.position = new Vector2(pos.x, pos.y + walkSpeed * yDirection);
            }
            else
            {
                if (farmableTiles.Count == 0)
                {
                    headedSomewhere = false; return;
                }
                //get next position
                time = 0f;
                FarmableTile farmableTile = farmableTiles.Dequeue();
                goblin.FarmTile(farmableTile);
                if (farmableTiles.Count == 0)
                {
                    currentDestination = ogPosition; return;
                }
                currentDestination = farmableTiles.Peek().transform.position;
            }
        }
    }
Пример #5
0
    //adds a tile to its list and marks is with a mark sprite
    private void AddFarmableTile(FarmableTile tile)
    {
        tiles.Add(tile);
        GameObject mark = Instantiate(markPrefab);

        mark.transform.position = tile.transform.position;
        marks.Add(mark);
    }
Пример #6
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        FarmableTile farmableTile = collision.gameObject.GetComponent <FarmableTile>();

        if (farmableTile != null)
        {
            currentFarmableTile = farmableTile;
        }
    }
Пример #7
0
    //removes tile from its list and destroys the mark that was on it.
    private void RemoveFarmableTile(FarmableTile tile)
    {
        int index = tiles.FindIndex(x => x.Equals(tile));

        tiles.RemoveAt(index);
        GameObject mark = marks[index];

        marks.RemoveAt(index);
        Destroy(mark);
    }
    public void GetTileSelected()
    {
        RaycastHit2D hit = Physics2D.Raycast(tileSelectorCenter.transform.position, new Vector2(0.1f, 0));

        if (hit.collider != null)
        {
            currentFarmableTileSelected = hit.collider.gameObject.GetComponent <FarmableTile>();
        }
        else
        {
            currentFarmableTileSelected = null;
        }
    }