Exemplo n.º 1
0
    protected override void UpdateAddOn()
    {
        GameSession session = GameSession.Instance;

        if (session.isDefender)
        {
            if (session.selectedObject is Tower)
            {
                guiTexture.pixelInset = Constants.offScreenRect;
            }
            else
            {
                guiTexture.pixelInset = onScreen;
            }
            if (Constants.TowerBuildCosts[ability.ToString()] <= session.credits)
            {
                guiTexture.color = Constants.clear;
            }
            else
            {
                guiTexture.color = Constants.desaturate;
            }
        }
        else
        {
            guiTexture.pixelInset = onScreen;
            AlienSpawnPoint spawn = (AlienSpawnPoint)session.selectedObject;
            if (maskSize[spawn] != null)
            {
                cooldownMask.pixelInset = (Rect)maskSize[spawn];
            }
            else
            {
                cooldownMask.pixelInset = Constants.offScreenRect;
            }
            if (session.credits >= Constants.AlienCost[ability.ToString()] && session.tick > 0)
            {
                guiTexture.color = Constants.clear;
            }
            else
            {
                guiTexture.color = Constants.desaturate;
            }
        }

        int abilityNum = (int)ability;

        if (abilityNum > 5)
        {
            abilityNum -= 6;
        }
        if (Input.GetKeyDown(keys[abilityNum]))
        {
            handleDown();
        }
    }
Exemplo n.º 2
0
    /*
     * private IEnumerator Dispatch(){
     *      while(true){
     *              yield return _sync();
     *
     *              if(overallAlienQueue.Count != 0){
     *                      Debug.Log("noticed entry");
     *                      yield return new WaitForSeconds(spawnWaitTime);
     *                      Debug.Log("Spawning");
     *                      ObjLocPair dispatch = overallAlienQueue.Dequeue();
     *
     *                      dispatch.loc.Spawn(dispatch.obj);
     *              }
     *      }
     * }*/

    public IEnumerator BuildAlien(string alienType, int spawnPointID, int routeID)
    {
        Alien.noOfAliens++;
        float      timePassed = 0f, buildTime = spawnWaitTime;
        GUITexture icon = ((GameObject)Instantiate(PrefabManager.UIAlienIcon)).GetComponent <GUITexture>();

        icon.texture = PrefabManager.PrefabIcons[alienType];
        while (timePassed <= buildTime)
        {
            yield return(_sync());

            timePassed += Time.deltaTime;
            float percentage = timePassed / spawnWaitTime;
            icon.pixelInset = Constants.getRectToScreen(440, 230 - (530 * percentage), 60, 60);
        }
        Destroy(icon.gameObject);
        if (!GameSession.Instance.isNetworkGame || GameSession.Instance.isDefender)
        {
            AlienSpawnPoint sp = GameStart.Instance.spawnPoints[spawnPointID];
            sp.Spawn(PrefabManager.PrefabAliens[alienType], spawnPointID, routeID);
        }
    }
Exemplo n.º 3
0
    private IEnumerator Cooldown(AlienSpawnPoint spawn)
    {
        breakFlag = false;
        float cooldownTime = Constants.AlienCooldown[ability.ToString()], currentCooldownTime = 0f;

        while (currentCooldownTime <= cooldownTime)
        {
            if (breakFlag)
            {
                breakFlag = false;
                break;
            }

            yield return(_sync());

            currentCooldownTime += Time.deltaTime;
            float percentage = (cooldownTime - currentCooldownTime) / cooldownTime;
            maskSize[spawn] = new Rect(onScreen.x - 5, onScreen.y - 5, onScreen.width + 10, percentage * onScreen.height + 10);
        }
        maskSize[spawn]     = Constants.offScreenRect;
        enabledTable[spawn] = true;
        breakFlag           = false;
    }
Exemplo n.º 4
0
    public override void ButtonDown()
    {
        ScreenDebugger.addText(ability.ToString());
        GameSession session = GameSession.Instance;

        if (session.isDefender)
        {
            if (session.disableTouch)
            {
                return;
            }

            if (session.selectedObject is Tower)
            {
                // Cancel tower selection
                session.selectedObject.Deselect();
            }

            if (session.selectedCard != null &&
                session.selectedCard != this)
            {
                session.selectedCard.Deselect();
            }

            if (session.selectedObject == null)
            {
                if (session.selectedCard == this)
                {
                    // Double-tapping is a deselect
                    Deselect();
                }
                else
                {
                    // Just select
                    Select();
                    SelectableObject.showAll = true;
                    guiTexture.texture       = PrefabManager.PrefabCards[ability.ToString() + "Selected"];
                }
            }
            else
            {
                if (session.selectedCard == this)
                {
                    // Build tower

                    string abilityS = ability.ToString();
                    if (Constants.TowerBuildCosts[abilityS] <= session.credits)
                    {
                        Tower tower = Tower.Create(ability.ToString(), (TowerSpawnPoint)session.selectedObject);
                        tower.Select();
                    }
                    else
                    {
                        // Do something here
                    }
                }
                else
                {
                    // Change selection
                    Select();
                    session.showConfirmation();
                }
            }
        }
        else
        {
            if (session.selectedObject is AlienSpawnPoint)
            {
                guiTexture.texture = PrefabManager.PrefabCards[ability.ToString() + "Selected"];
                AlienSpawnPoint spawn = (AlienSpawnPoint)GameSession.Instance.selectedObject;
                if (session.selectedCard == this && (enabledTable[spawn] == null || (bool)enabledTable[spawn] == true))
                {
                    if (session.tick <= 0)
                    {
                        // Cannot spawn when time is up
                        return;
                    }
                    string abilityString = ability.ToString();
                    if (session.credits >= Constants.AlienCost[abilityString])
                    {
                        session.credits -= Constants.AlienCost[abilityString];
                        AlienSpawnPoint sp            = (AlienSpawnPoint)session.selectedObject;
                        int             spawnPointPos = Array.IndexOf(GameStart.Instance.spawnPoints, sp);
                        int             routePos      = UnityEngine.Random.Range(0, sp.routes.Length);
                        session.SpawnUnit(abilityString, spawnPointPos, routePos);

                        enabledTable[spawn] = false;

                        StartCoroutine(Cooldown(spawn));
                    }
                    else
                    {
                        // TODO complain not enuff credits somehow!
                    }
                }
                else
                {
                    if (session.selectedCard != null && session.selectedCard != this)
                    {
                        session.selectedCard.Deselect();
                    }
                    Select();
                }
            }
        }
    }