Exemple #1
0
    void OnMouseDown()
    {
        switch (m_index)
        {
        case 0:
            if (State.PlayerMoney > State.COST_ICBM_UPGRADE && count < 3)
            {
                m_unitFactory.m_icbmLevel++;
                State.PlayerMoney -= State.COST_ICBM_UPGRADE;
                AudioSource.PlayClipAtPoint(m_buySound, transform.position, 0.7f);

                count++;
                m_moneyEffect.StartEffect(-State.COST_ICBM_UPGRADE);
            }
            else
            {
                AudioSource.PlayClipAtPoint(m_failSound, transform.position, 0.7f);
            }
            break;

        case 1:
            if (State.PlayerMoney > State.COST_BOMBER_UPGRADE && count < 3)
            {
                m_unitFactory.m_bomberLevel++;

                State.PlayerMoney -= State.COST_BOMBER_UPGRADE;
                AudioSource.PlayClipAtPoint(m_buySound, transform.position, 0.7f);

                count++;
                m_moneyEffect.StartEffect(-State.COST_BOMBER_UPGRADE);
            }
            else
            {
                AudioSource.PlayClipAtPoint(m_failSound, transform.position, 0.7f);
            }
            break;

        case 2:
            if (State.PlayerMoney > State.COST_FIGHTER_UPGRADE && count < 3)
            {
                m_unitFactory.m_fighterLevel++;
                State.PlayerMoney -= State.COST_FIGHTER_UPGRADE;
                AudioSource.PlayClipAtPoint(m_buySound, transform.position, 0.7f);

                count++;
                m_moneyEffect.StartEffect(-State.COST_FIGHTER_UPGRADE);
            }
            else
            {
                AudioSource.PlayClipAtPoint(m_failSound, transform.position, 0.7f);
            }
            break;

        default:
            Debug.LogError("Invalid Upgrade UI index given for draw.");
            break;
        }
    }
Exemple #2
0
    void Update()
    {
        // Gold update
        m_gptTimer.elapsed += Time.deltaTime;
        while (m_gptTimer.HasElapsed())
        {
            State.m_playerMoney += PLAYER_GPT;

            m_moneyEffect.StartEffect(PLAYER_GPT);

            State.m_enemyMoney += ENEMY_GPT;
            m_gptTimer.SetBack();
        }

        // Check for win condition
        Debug.LogWarning(m_enemyFabs.Count + " " + m_playerFabs.Count);
        if (m_enemyFabs.Count == 0)
        {
            StartCoroutine(EndGame(true));
        }
        else if (m_playerFabs.Count == 0)
        {
            StartCoroutine(EndGame(false));
        }
    }
Exemple #3
0
    public void TakeDamage(int damage)
    {
        // Deal damage
        if (!dead)
        {
            StartCoroutine(HitEffect());
            m_damage += damage;
        }
        // If the entity is now dead, play death stuff and reward correct player
        if (dead && !m_rewardGiven)
        {
            m_rewardGiven = true;

            AudioSource.PlayClipAtPoint(m_destructionSound, this.transform.position, 0.6f);
            if (m_owner == Owner.PLAYER)
            {
                State.EnemyMoney += m_money;
            }
            else
            {
                State.PlayerMoney += m_money;
                m_moneyEffect.StartEffect(m_money);
            }

            // Explosion!
            Explode();
        }
    }
Exemple #4
0
 void OnMouseDown()
 {
     if (State.PlayerMoney >= State.GetCostOf(m_type))
     {
         State.PlayerMoney -= State.GetCostOf(m_type);
         m_fab.AddToSpawnList(m_type);
         AudioSource.PlayClipAtPoint(m_buySound, transform.position, 0.7f);
         m_moneyEffect.StartEffect(-State.GetCostOf(m_type));
     }
 }
Exemple #5
0
    void Update()
    {
        Vector3 clickPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (Input.GetMouseButtonDown(0))
        {
            // Check if the click was on the point
            if (GetComponent <Collider2D>().OverlapPoint(clickPos))
            {
                if (!IsOpen())
                {
                    AudioSource.PlayClipAtPoint(m_clickSound, transform.position);
                }
                else
                {
                    AudioSource.PlayClipAtPoint(m_cancelSound, transform.position, 0.5f);
                    m_spawnList.Clear();
                    m_unitQueueUI.Clear();
                }
                SetOpen(!IsOpen());
            }
            // Check if it collides with any children
            else if (m_fighterButton.GetComponent <Collider2D>().OverlapPoint(clickPos) ||
                     m_bomberButton.GetComponent <Collider2D>().OverlapPoint(clickPos) ||
                     m_icbmButton.GetComponent <Collider2D>().OverlapPoint(clickPos))
            {
                // Nothing to do, children are doing work
            }
            // Check if it collides with any other points
            else
            {
                Point destination = ClickedOnPoint(clickPos);
                if (null != destination && IsOpen())
                {
                    foreach (Entity.Type type in m_spawnList)
                    {
                        GameObject unit = m_unitFactory.SpawnUnit(type);
                        unit.GetComponent <Unit>().SetSourceAndTarget(m_point, destination);
                        unit.SetActive(false);
                        m_spawnQueue.Enqueue(unit);
                    }
                    StopAllCoroutines();
                    if (m_spawnList.Count > 0)
                    {
                        m_spawnList.Clear();
                        m_unitQueueUI.Clear();
                        AudioSource.PlayClipAtPoint(m_launchSound, transform.position, 0.5f);
                        AI.m_userStarted = true;
                    }
                    StartCoroutine(SpawnUnits());
                    SetOpen(false);
                }
                // Player clicked in an invalid location, cancel everything
                else
                {
                    if (IsOpen())
                    {
                        AudioSource.PlayClipAtPoint(m_cancelSound, transform.position, 0.5f);
                        int diff = State.PlayerMoney;
                        foreach (Entity.Type type in m_spawnList)
                        {
                            State.PlayerMoney += State.GetCostOf(type);
                        }
                        diff = State.PlayerMoney - diff;
                        if (diff > 0)
                        {
                            m_moneyEffect.StartEffect(diff);
                        }

                        m_spawnList.Clear();
                        m_unitQueueUI.Clear();
                    }
                    SetOpen(false);
                }
            }
        }
    }