コード例 #1
0
    void placeBuilding(Vector2 pos, RaycastHit2D hit)
    {
        GameObject instance = GameObject.Instantiate(previewPrefab, buildingContainer.transform);

        instance.tag = "Building";
        BuildingPlatformController bpc = hit.collider.GetComponent <BuildingPlatformController>();

        bpc.place(instance.GetComponent <Building>());               // Set the building

        // Play the audio
        audioSource.pitch  = Random.Range(0.5f, 1.5f);
        audioSource.volume = 0.9f;
        audioSource.clip   = place;
        audioSource.Play();

        // Decrease amount in GUI
        int newAmount = int.Parse(previewAmountText.text) - 1;

        previewAmountText.text = newAmount + "";

        if (newAmount <= 0)
        {
            stopPreview();
        }
    }
コード例 #2
0
ファイル: Solutions.cs プロジェクト: donand/Earthquake-Game
    public bool correctPlacement(BuildingPlatformController bpc)
    {
        foreach (SolutionItem si in solutions)
        {
            if (si.platform.Equals(bpc))
            {
                // If it is found, the correct type of building and upgrade should have been placed
                Upgrade.UpgradeType uType = Upgrade.UpgradeType.None;
                if (si.platform.upgrade != null)
                {
                    uType = si.platform.upgrade.type;
                }
                Building.BuildingType bType = Building.BuildingType.None;
                if (si.platform.building != null)
                {
                    bType = si.platform.building.type;
                }

                if (si.upgrade == uType && si.building == bType)
                {
                    return(true);
                }

                return(false);
            }
        }
        // If it isn't defined as solution, it should be empty
        if ((bpc.building == null || bpc.building.type == Building.BuildingType.None) &&
            (bpc.upgrade == null || bpc.upgrade.type == Upgrade.UpgradeType.None))
        {
            return(true);
        }
        return(false);
    }
コード例 #3
0
    bool checkAllowPlacement(RaycastHit2D hit)
    {
        // Only allow angle between -10 and 10 degrees steep
        float angle = Mathf.Atan2(hit.normal.y, hit.normal.x) * Mathf.Rad2Deg;

        if (!(angle > 80 && angle < 100))
        {
            return(false);
        }

        // Only allow placement in building zones
        if (!hit.collider.tag.Equals("BuildingPlatform"))
        {
            return(false);
        }

        // Only one building can be built for each platform
        BuildingPlatformController bpc = hit.collider.GetComponent <BuildingPlatformController>();

        if (!bpc.isBuilt || bpc.isUpgraded)
        {
            return(false);
        }

        return(true);
    }
コード例 #4
0
    // The idea is to put behaviours specific to a mode in a separate object, e.g. the wave simulator,
    // so that we don't need exceptions for every mode. The script starts in its Start method
    public void setGameMode(GameMode newMode)
    {
        Debug.Log(mode + " -> " + newMode);
        // Exceptions
        if (mode == GameMode.Building && newMode == GameMode.Upgrade)
        {
            if (!buildingList.finishedPlacing())
            {
                userFeedback.setText("You should place all buildings before continuing");
                return;
            }
        }
        else if ((mode == GameMode.Building || mode == GameMode.Upgrade) && newMode == GameMode.Simulation)
        {
            // Todo: Check if all buildings have been set
            if (!buildingList.finishedPlacing())
            {
                userFeedback.setText("You should place all buildings before continuing");
                return;
            }
            else if (!upgradeList.finishedPlacing())
            {
                userFeedback.setText("You should place all upgrades before continuing");
                return;
            }

            // Disable all undo buttons
            GameObject[] platforms = GameObject.FindGameObjectsWithTag("BuildingPlatform");
            foreach (GameObject go in platforms)
            {
                Button b = go.GetComponentInChildren <Button>();
                if (b != null)
                {
                    b.gameObject.SetActive(false);
                }
            }


            earthquakeSimulator.simulateEarthquake();

            // Check if passed
            bool passed = true;
            foreach (GameObject go in platforms)
            {
                BuildingPlatformController bpc = go.GetComponent <BuildingPlatformController>();
                if (bpc.building != null && bpc.building.type == Building.BuildingType.Thematic)
                {
                    continue;
                }
                else if (!bpc.isCorrect())
                {
                    Debug.Log(bpc.building);
                    passed = false;
                    break;
                }
            }

            if (passed)
            {
                StartCoroutine(setGameMode(GameMode.Pass, finishWaitTime));
            }
            else
            {
                StartCoroutine(setGameMode(GameMode.Fail, finishWaitTime));
            }
        }
        else if (mode == GameMode.Upgrade && newMode == GameMode.Building)
        {
            // Todo: Remove/reset upgrades when going back?
        }
        else if (mode == GameMode.Upgrade && newMode == GameMode.Simulation)
        {
            // Check if all foundations have been set
            if (!upgradeList.finishedPlacing())
            {
                userFeedback.setText("Place all upgrades before continuing");
                return;
            }
        }
        else if (newMode == GameMode.Pass)
        {
            onPass.Invoke();
        }
        else if (newMode == GameMode.Fail)
        {
            onFail.Invoke();
        }

        // In every case, switch all objects
        List <GameObject> oldObjs = getModeObjects(mode);
        List <GameObject> newObjs = getModeObjects(newMode);

        foreach (GameObject go in oldObjs)
        {
            go.SetActive(false);
        }
        foreach (GameObject go in newObjs)
        {
            go.SetActive(true);
        }

        mode = newMode;

        // Stop wave propogation when modes change
        targetController.stopWaves();
    }