/// <summary>
    /// Build the whole level.
    /// Edited by Courtney
    /// </summary>
    public void Start()
    {
        grassTile = (GameObject)Resources.Load("Prefabs/Tiles/Grass");
        projectilesEffectParent = map.transform.Find("ProjectilesEffects").transform;
        dotEffectParent         = map.transform.Find("DoTEffects").transform;
        aoEEffects = map.transform.Find("AoEEffects").transform;
        TileDict   = new Dictionary <Point, Tile>();
        float tileSize = grassTile.GetComponent <SpriteRenderer>().sprite.bounds.size.x;

        GenerateTiles(GameManager.Width, GameManager.Height, tileSize);
        EnemyManager.FindTargetTiles();
        SceneryGenerator.GenerateScenery();

        GridGraphManager.Setup(GameManager.Width, GameManager.Height, tileSize);
        Hover.Deactivate();
    }
Exemple #2
0
    /// <summary>
    /// Place tower on passed tile, if it is possible (enough money & don't block path).
    ///
    /// Author: Steven Johnson, David Askari
    /// </summary>
    /// <param name="parentTile">Parent tile for this tower.</param>
    /// <returns>Created tower.</returns>
    public Tower PlaceTower(Tile parentTile)
    {
        if (baseCosts > GameManager.money)
        {
            GameManager.DisplayErrorText("Can't place tower. Not enough funds.");
            return(null);
        }
        GameManager.AddMoney(-baseCosts);

        // Place tower.
        GameObject tower = Instantiate(GameManager.SelectedTower.gameObject, parentTile.transform.position, Quaternion.identity, parentTile.transform);

        if (GameManager.CheckForFirstPlacement())
        {
            StartCoroutine(GameManager.DisplayRewardsPanel());
        }

        // Check if path is blocked.
        if (!GridGraphManager.IsGraphNotBlocked(tower))
        {
            GameManager.DisplayErrorText("Can't place tower here. Path is entirely blocked.");
            GameManager.AddMoney(baseCosts);
            Destroy(tower);
            return(null);
        }

        // Set sprite sorting order.
        tower.GetComponent <SpriteRenderer>().sortingOrder = -parentTile.GridPoint.y;

        // Allow multi tower placement by pressing LeftShift.
        if (!Input.GetKey(KeyCode.LeftShift))
        {
            Hover.Deactivate();
            GameManager.SelectTower(tower.GetComponent <Tower>());
            TowerInformation.Reset();
        }

        tower.GetComponent <Tower>().tile = parentTile;
        return(tower.GetComponent <Tower>());
    }
Exemple #3
0
    /// <summary>
    /// Updates times and other necessary pieces of game play.
    ///
    /// Authors: Amy Lewis, Cole Twitchell, David Askari, Steven Johnson, Courtney Chu
    /// </summary>
    public void Update()
    {
        SetTimerText();
        WaveManager.Update();

        var saturation = ppProfile.colorGrading.settings;

        if (currentWave == 1)
        {
            saturation.basic.saturation = 1;
        }
        else if (currentWave == 6)
        {
            sendBossButton.SetActive(true);
            PauseGame.sendBossButton = sendBossButton.GetComponent <SendBossButton>();
        }

        if (gameOver)
        {
            waveTimer.SetPaused(true);

            if (CastleManager.CastleHealth > 0)
            {
                saturation.basic.saturation = 0;
            }

            PauseGame.Status = true;

            GameObject.Find("OptionsMenu").SetActive(false);
            GameObject.Find("OptionsButton").GetComponent <Button>().interactable = false;
            sendBossButton.GetComponent <SendBossButton>().DisableButton();

            if (CastleManager.CastleHealth > 0)
            {
                XmlImporter.Cleanup();
                PauseGame.Status = false;
                SceneManager.LoadScene("victory_cutscene");
            }
            else
            {
                gameOverObject.transform.Find("GameOverText").GetComponent <Text>().text = "GAME OVER";
                gameOverObject.SetActive(true);
                enabled = false;
            }
        }
        else
        {
            if (!waveTimer.IsPaused() && waveTimer.IsDone())
            {
                waveTimer.SetPaused(true);
                WaveManager.BeginWave();
                AudioManager.PlayBeginWaveSound();
                sendBossButton.GetComponent <SendBossButton>().DisableButton();
            }

            if (WaveManager.WaveFinished() && EnemyManager.EnemiesRemaining() <= 0)
            {
                saturation.basic.saturation = 1.0f - ((float)(currentWave - 1) / (float)totalWaves);
                currentWave++;
                waveText.text = currentWave.ToString();
                waveTimer.Reset();
                waveTimer.SetPaused(false);
                WaveManager.SetNextWave();
                skipTimeButton.interactable = true;
                sendBossButton.GetComponent <SendBossButton>().ResetButton();
            }

            if (Hover.IsActive())
            {
                GameManager.rangeIndicatorRenderer.transform.position = Hover.GetPosition();
            }

            if (Input.GetKeyDown(KeyCode.S))
            {
                GameManager.AddMoney(100);
            }

            if (Input.GetKeyDown(KeyCode.A))
            {
                SkipTimer();
            }
            else if (Input.GetMouseButtonUp(1) && Hover.IsActive())
            {
                GameManager.rangeIndicatorRenderer.enabled = false;
                Hover.Deactivate();
                GameManager.ResetTower();
                TowerInformation.Reset();
            }
        }
        ppProfile.colorGrading.settings = saturation;
        healthText.text = CastleManager.CastleHealth.ToString();
        moneyText.text  = money.ToString();

        errorTextTimer.Update();
        if (errorTextTimer.IsDone())
        {
            errorText.gameObject.SetActive(false);
            errorTextTimer.Reset();
            errorTextTimer.SetPaused(true);
        }
    }