Пример #1
0
    public void detectAndSetSprite()
    {
        Vector3 position = gameObject.transform.position;
        GroundTileController leftTile   = groundTileManager.getTileByPosition(position + Vector3.left);
        GroundTileController rightTile  = groundTileManager.getTileByPosition(position + Vector3.right);
        GroundTileController topTile    = groundTileManager.getTileByPosition(position + Vector3.up);
        GroundTileController bottomTile = groundTileManager.getTileByPosition(position + Vector3.down);

        bool leftTilled;
        bool rightTilled;
        bool topTilled;
        bool bottomTilled;

        if (leftTile != null)
        {
            leftTilled = leftTile.currentGroundType == GroundType.Dirt;
        }
        else
        {
            leftTilled = false;
        }

        if (rightTile != null)
        {
            rightTilled = rightTile.currentGroundType == GroundType.Dirt;
        }
        else
        {
            rightTilled = false;
        }

        if (topTile != null)
        {
            topTilled = topTile.currentGroundType == GroundType.Dirt;
        }
        else
        {
            topTilled = false;
        }

        if (bottomTile != null)
        {
            bottomTilled = bottomTile.currentGroundType == GroundType.Dirt;
        }
        else
        {
            bottomTilled = false;
        }

        if (bottomTilled && topTilled && leftTilled && rightTilled)
        {
            spriteRenderer.sprite = allClosed;
        }
        else if (!bottomTilled && !topTilled && !leftTilled && !rightTilled)
        {
            spriteRenderer.sprite = allOpen;
        }
        else if (bottomTilled && !topTilled && !leftTilled && !rightTilled)
        {
            spriteRenderer.sprite = topOpen;
        }
        else if (topTilled && !bottomTilled && !leftTilled && !rightTilled)
        {
            spriteRenderer.sprite = bottomOpen;
        }
        else if (leftTilled && !rightTilled && !topTilled && !bottomTilled)
        {
            spriteRenderer.sprite = rightOpen;
        }
        else if (rightTilled && !leftTilled && !topTilled && !bottomTilled)
        {
            spriteRenderer.sprite = leftOpen;
        }
        else if (rightTilled && topTilled && !bottomTilled && !leftTilled)
        {
            spriteRenderer.sprite = bottomLeftOpen;
        }
        else if (leftTilled && topTilled && !bottomTilled && !rightTilled)
        {
            spriteRenderer.sprite = bottomRightOpen;
        }
        else if (rightTilled && bottomTilled && !topTilled && !leftTilled)
        {
            spriteRenderer.sprite = topLeftOpen;
        }
        else if (leftTilled && bottomTilled && !topTilled && !rightTilled)
        {
            spriteRenderer.sprite = topRightOpen;
        }
        else
        {
            spriteRenderer.sprite = allClosed;
        }
    }
Пример #2
0
    // Private Functions

    private void setTilledBooleans()
    {
        Vector3 position = gameObject.transform.position;
        GroundTileController leftTile        = groundTileManager.getTileByPosition(position + Vector3.left);
        GroundTileController rightTile       = groundTileManager.getTileByPosition(position + Vector3.right);
        GroundTileController topTile         = groundTileManager.getTileByPosition(position + Vector3.up);
        GroundTileController bottomTile      = groundTileManager.getTileByPosition(position + Vector3.down);
        GroundTileController diagTopLeft     = groundTileManager.getTileByPosition(position + Vector3.up + Vector3.left);
        GroundTileController diagTopRight    = groundTileManager.getTileByPosition(position + Vector3.up + Vector3.right);
        GroundTileController diagBottomRight = groundTileManager.getTileByPosition(position + Vector3.down + Vector3.right);
        GroundTileController diagBottomLeft  = groundTileManager.getTileByPosition(position + Vector3.down + Vector3.left);

        if (leftTile != null)
        {
            leftTilled = leftTile.currentGroundType == GroundType.Dirt;
        }
        else
        {
            leftTilled = false;
        }

        if (rightTile != null)
        {
            rightTilled = rightTile.currentGroundType == GroundType.Dirt;
        }
        else
        {
            rightTilled = false;
        }

        if (topTile != null)
        {
            topTilled = topTile.currentGroundType == GroundType.Dirt;
        }
        else
        {
            topTilled = false;
        }

        if (bottomTile != null)
        {
            bottomTilled = bottomTile.currentGroundType == GroundType.Dirt;
        }
        else
        {
            bottomTilled = false;
        }

        if (diagTopLeft != null)
        {
            topLeftTilled = diagTopLeft.currentGroundType == GroundType.Dirt;
        }
        else
        {
            topLeftTilled = false;
        }

        if (diagTopRight != null)
        {
            topRightTilled = diagTopRight.currentGroundType == GroundType.Dirt;
        }
        else
        {
            topRightTilled = false;
        }

        if (diagBottomLeft != null)
        {
            bottomLeftTilled = diagBottomLeft.currentGroundType == GroundType.Dirt;
        }
        else
        {
            bottomLeftTilled = false;
        }

        if (diagBottomRight != null)
        {
            bottomRightTilled = diagBottomRight.currentGroundType == GroundType.Dirt;
        }
        else
        {
            bottomRightTilled = false;
        }
    }
Пример #3
0
    public void useEquippedItem()
    {
        ItemType             item       = playerInventory.heldItem;
        GroundTileController controller = groundTileManager.getTileByPosition(selectedTileController.selectedTilePosition);

        if (selectedTileController.selectedTilePosition == groundTileManager.ovenPosition)
        {
            if (!foodManager.isCooking)
            {
                foodManager.toggleRecipePanel();
            }
        }
        else if (selectedTileController.selectedTilePosition == groundTileManager.vendingMachinePosition)
        {
            // Open shop menu.
            shopManager.toggleShopPanel();
        }
        else if (selectedTileController.selectedTilePosition != groundTileManager.belowVendingMachinePosition)
        {
            switch (item)
            {
            case ItemType.WaterCan:
                if (controller.currentGroundType == GroundType.Dirt)
                {
                    controller.plant.waterGround();
                    sfxPlayer.playWaterSound();
                }
                break;

            case ItemType.Hoe:
                if (selectedTileController.selectedTilePosition != groundTileManager.cratePosition)
                {
                    controller.groundHitWithHoe();
                    sfxPlayer.playHitGround();
                }
                break;

            case ItemType.CarrotSeed:
            case ItemType.PotatoeSeed:
            case ItemType.GarlicSeed:
            case ItemType.PepperSeed:
            case ItemType.ChickpeaSeed:
                if (controller.currentGroundType == GroundType.Dirt && !controller.plant.seedPresent)
                {
                    controller.plantSeed(item);
                    playerInventory.deleteInventoryItem();
                }
                break;

            case ItemType.Carrot:
            case ItemType.Potatoe:
            case ItemType.Pepper:
            case ItemType.Chickpea:
            case ItemType.Garlic:
                if (selectedTileController.selectedTilePosition == groundTileManager.cratePosition)
                {
                    // store it
                    foodManager.addItemToStorage(item);
                    playerInventory.deleteInventoryItem();
                }
                else
                {
                    // eat it
                    playerInventory.deleteInventoryItem();
                    ageManager.eatFood(foodManager.getAgeFromItemType(item));
                    sfxPlayer.playEatFoodSound();
                }
                break;

            case ItemType.RecipeOne:
            case ItemType.RecipeTwo:
            case ItemType.RecipeThree:
            case ItemType.RecipeFour:
            case ItemType.RecipeFive:
                playerInventory.deleteInventoryItem();
                ageManager.eatFood(foodManager.getAgeFromItemType(item));
                sfxPlayer.playEatFoodSound();
                break;

            case ItemType.None:
                if (controller.plant.canBePicked)
                {
                    playerInventory.setNewInventoryItem(plantManager.getItemTypeFromPlantType(controller.plant.plantType));
                    controller.plant.pickPlant();
                    sfxPlayer.playPickupPlantSound();
                }
                break;

            default:
                Debug.Log("Unhandled ItemType in UseItem");
                break;
            }
        }
    }