Beispiel #1
0
    /*
     * Plants an existing carrot on the ground at a certain position
     * 3 Cases:
     *	- If the destination cell is empty, the carrot is planted there, returns the planted carrot.
     *	- If the destination cell is invalid (out of bounds), the carrot is destroyed, returns null.
     *	- If the destination cell already contains a carrot, the planted carrot merges into the other one, returns the already planted carrot.
     *		The merge adds the food amount to the already planted carrot, the merged carrot is destroyed
     */
    private void PlantCarrot(object source, Grabbable.DropData data)
    {
        if (source is Grabbable gb)
        {
            CarrotController carrot = gb.GetComponent <CarrotController>();
            if (!carrot)
            {
                return;
            }

            Instantiate(DestroyVFXPrefab, carrot.transform.position, Quaternion.identity);

            Vector2Int cell = data.Cell;

            if (!_grid.IsValidCell(cell))
            {
                Destroy(carrot.gameObject);
                return;
            }

            if (_carrots.ContainsKey(cell))
            {
                CarrotController placedCarrot = _carrots[cell];
                placedCarrot.Merge(carrot);
                Destroy(carrot.gameObject);
                return;
            }

            _carrots.Add(cell, carrot);
        }
    }
Beispiel #2
0
    /*
     * Executed when a rabbit is dropped
     */
    private void OnRabbitDrop(object sender, Grabbable.DropData data)
    {
        if (sender is Grabbable gb)
        {
            RabbitController rabbit = gb.GetComponent <RabbitController>();
            if (!rabbit)
            {
                return;
            }

            Vector2Int cell = data.Cell;

            if (!_grid.IsValidCell(cell))
            {
                rabbit.Kill();
            }
        }
    }
 private void OnDrop(object sender, Grabbable.DropData data) => ResumeGrowing();
Beispiel #4
0
 public void OnDrop(object sender, Grabbable.DropData data) => ChangeState(Action.Idle);