Esempio n. 1
0
    void BumpUpgradeSelection(int adjust)
    {
        int newIndex = CurrentUpgradeSelection + adjust;
        int count    = 0;

        for (int i = CurrentUpgradeSelection + adjust; ; i += adjust)
        {
            if (i < 0)
            {
                i = selections.Count - 1;
            }
            else if (i >= selections.Count)
            {
                i = 0;
            }
            IUpgradeable ug = Game.Instance.playerShip.GetUpgradeable((PlayerShip.UpgradeType)i);
            if (ug.CanUpgrade())
            {
                CurrentUpgradeSelection = i;
                break;
            }
            count++;

            if (count >= selections.Count)
            {
                CurrentUpgradeSelection = (int)PlayerShip.UpgradeType.NoUpgrades;
                break;
            }
        }
    }
Esempio n. 2
0
 ///
 /// Upgrade the ship and the specified upgradeble.
 ///
 public void Upgrade(IUpgradeable upgradeable)
 {
     // full health recovery
     this.health = this.maxHealth;
     if (upgradeable.CanUpgrade())
     {
         upgradeable.Upgrade();
     }
     Game.Instance.ShowMessage(UItext.MessageType.RankUp, Game.Instance.ExplorationCount.ToString());
 }
Esempio n. 3
0
    void TryToUpgrade(IUpgradeable upgradeable)
    {
        // If we have enough money
        if (upgradeable.CanUpgrade() && PlayerData.Instance.CanAfford(upgradeable.GetUpgradeCost()))
        {
            //Spend the money
            PlayerData.Instance.Spend(upgradeable.GetUpgradeCost());

            //Upgrade
            upgradeable.Upgrade();

            var cost = upgradeable.GetUpgradeCost();
            var text = cost >= 0 ? cost.ToString() : "-";
            UpgradeButton.transform.GetChild(0).Find("Price").GetComponent <TMPro.TextMeshProUGUI>().text = text;
        }
    }
Esempio n. 4
0
    void Update()
    {
        totalExplored.text = game.ExplorationCount.ToString();

        var player = Game.Instance.playerShip;

        if (player)
        {
            hpBar.fillAmount = player.health / (float)player.maxHealth;
        }
        else
        {
            hpBar.fillAmount = 0;
        }

        int gridNum = Game.Instance.GetCurrentGrid();

        textCurrentSector.text = "Sector: " + Game.Instance.GetSectorName(gridNum);

        // text
        if (!_showingText && _messageQueue.Count > 0)
        {
            // show the next message
            textForPlayer.text    = _messageQueue.Dequeue();
            textForPlayer.enabled = true;
            textForPlayer.transform.parent.gameObject.SetActive(true);

            if (notificationSound)
            {
                Game.Instance.effectsAudioSource.PlayOneShot(notificationSound);
            }

            _textTimerCounter = 0;
            _showingText      = true;
        }
        else if (_showingText)
        {
            if (_textTimerCounter >= textTimer)
            {
                textForPlayer.enabled = false;
                textForPlayer.transform.parent.gameObject.SetActive(false);
                textForPlayer.text = string.Empty;
                _showingText       = false;
                _textTimerCounter  = 0;
            }
            _textTimerCounter += Time.deltaTime;
        }
        //

        for (int i = 0; i < juices.Count; i++)
        {
            juices[i].enabled = (i + 1) <= WarpCount;
        }

        if (CurrentUpgradeSelection != (int)PlayerShip.UpgradeType.NoUpgrades)
        {
            // if (Input.GetButtonDown("Upgrade Selection Down"))
            // {
            //     BumpUpgradeSelection(-1);
            // }

            // if (Input.GetButtonDown("Upgrade Selection Up"))
            // {
            //     BumpUpgradeSelection(1);
            // }

            float axVal = Input.GetAxis("Upgrade Selection");
            if (axVal != _lastSelectionX)
            {
                if (axVal < 0)
                {
                    BumpUpgradeSelection(-1);
                }
                else if (axVal > 0)
                {
                    BumpUpgradeSelection(1);
                }
                _lastSelectionX = axVal;
            }

            UpdateStarsAndSelections();

            // Automatically bump the upgrade if current is not upgradeable.
            IUpgradeable upgradeable = Game.Instance.playerShip.GetUpgradeable();
            if (!upgradeable.CanUpgrade())
            {
                BumpUpgradeSelection(1);
            }
        }
        else
        {
            // Try to find a new thing we can upgrade.
            BumpUpgradeSelection(1);
            UpdateStarsAndSelections();
        }
    }