コード例 #1
0
ファイル: DungeonBuilder.cs プロジェクト: ben657/ld45
    public IEnumerator GenerateNavmeshAndComplete(DungeonSegment segment, bool first = false)
    {
        segment.GenerateNavMesh();
        float   s = 0.0f;
        Vector3 pos;

        while (s <= 1.0f)
        {
            yield return(new WaitForFixedUpdate());

            pos   = segment.transform.position;
            pos.y = segmentFallHeight - segmentFallCurve.Evaluate(Mathf.Clamp01(s)) * segmentFallHeight;
            segment.transform.position = pos;
            s += Time.fixedDeltaTime / segmentFallTime;
        }
        if (first)
        {
            SpawnHeroes(segment);
        }
        segment.CompleteGenerate(!first);
        if (first)
        {
            playerHero.GetComponent <UnitMovementController>().Enable();
            foreach (HeroUnit hero in PartyManager.it.party)
            {
                hero.GetComponent <UnitMovementController>().Enable();
            }
        }
    }
コード例 #2
0
ファイル: DungeonBuilder.cs プロジェクト: ben657/ld45
    void SpawnHeroes(DungeonSegment segment)
    {
        playerHero = Instantiate(playerHeroPrefab);
        playerHero.transform.parent = segment.transform;
        cameraController.target     = playerHero.transform;
        playerHero.GetComponent <UnitMovementController>().Disable();
        playerHero.transform.position = segment.transform.position;
        Vector3 spawnDir = -Vector3.right;

        foreach (HeroUnit hero in PartyManager.it.party)
        {
            hero.transform.position = playerHero.transform.position + spawnDir * 2.0f;
            hero.transform.parent   = segment.transform;
            hero.GetMovementController().SetLeader(playerHero);
            hero.ClearUnitsInRange();
            hero.GetMovementController().Enable();
            hero.GetAbilityController().enabled = true;
            spawnDir = Quaternion.AngleAxis(-90, Vector3.up) * spawnDir;
        }
    }
コード例 #3
0
    void UpgradeEquipment()
    {
        upgradeType = Random.Range(1, 5); //This is to determine upgrade type (Either Single(1), WeaponChoice(2), ArmourChoice(3), or AllChoice(4))
        // placeholder until UI is implemented for choices
        upgradeType = 1;
        switch (upgradeType)
        {
        case 1:
            classNum      = Random.Range(1, 4); //This Determines what class the Upgrade is for when it is a single upgrade
            equipmentType = Random.Range(1, 3); //This determines if the upgrade is for Weapon(1) or Armour(2) when it is a single upgrade
            break;

            /* case 2:
             *      classNum = getWeaponChoice();
             *      equipmentType = 1;
             *      break;
             * case 3:
             *      classNum = getArmourChoice();
             *      equipmentType = 2;
             *      break;
             * case 4:
             *      getAllChoice()
             *      break;
             */
        }

        switch (classNum)        // Set heroToUpgrade to the randomized or selected class
        {
        case 1:
            heroToUpgrade = GameObject.FindGameObjectWithTag("Player1").GetComponent <HeroUnit>();
            Debug.Log("Upgrading Fighter");
            break;

        case 2:
            heroToUpgrade = GameObject.FindGameObjectWithTag("Player2").GetComponent <HeroUnit>();
            Debug.Log("Upgrading Caster");
            break;

        case 3:
            heroToUpgrade = GameObject.FindGameObjectWithTag("Player3").GetComponent <HeroUnit>();
            Debug.Log("Upgrading Archer");
            break;
        }

        switch (equipmentType)
        {
        case 1:
            equipmentToUpgrade = heroToUpgrade.weap;
            // Debug.Log("Upgrading Weapon");
            break;

        case 2:
            equipmentToUpgrade = heroToUpgrade.armr;
            // Debug.Log("Upgrading Armour");
            break;
        }

        /*
         *  THIS SECTION WILL HAVE TO BE BALANCED
         */
        rarity = Random.Range(1, 101); //This will determine rarity/strength of the upgrade
        if (rarity <= 60)              // 60% chance
        {
            equipmentToUpgrade.rarity = "Common";
            // Debug.Log("Rarity is now Common");
            upgradeAmount = 1;
        }
        else if (rarity <= 90)      // 30% chance
        {
            equipmentToUpgrade.rarity = "Rare";
            //   Debug.Log("Rarity is now Rare");
            upgradeAmount = 3;
        }
        else if (rarity <= 98)      // 8% chance
        {
            equipmentToUpgrade.rarity = "Epic";
            //  Debug.Log("Rarity is now Epic");
            upgradeAmount = 6;
        }
        else
        {
            equipmentToUpgrade.rarity = "Legendary";
            // Debug.Log("Rarity is now Common");
            upgradeAmount = 8;
        }

        switch (equipmentType)
        {
        case 1:
            Weapon weaponToUpgrade = equipmentToUpgrade as Weapon;
            weaponToUpgrade.damageMin += upgradeAmount;
            weaponToUpgrade.damageMax += upgradeAmount;
            heroToUpgrade.GetComponent <Unit>().InitCBT(heroToUpgrade.name + " ATK Up +" + upgradeAmount);
            break;

        case 2:
            Armour armourToUpgrade = equipmentToUpgrade as Armour;
            armourToUpgrade.armour += upgradeAmount;
            heroToUpgrade.GetComponent <Unit>().InitCBT(heroToUpgrade.name + " DEF Up +" + upgradeAmount);
            break;
        }
    }
コード例 #4
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (Core.gameStart && !Core.gameEnd) {

            if (Core.gameRestart) {
                if (Core.anotherRound) {
                    for (int i =0; i < GetComponentsInChildren<UnitProfile>().Length; i++)
                        Destroy (GetComponentsInChildren <UnitProfile> () [i].gameObject);
                    Awake ();
                }

                Core.gameRestart = false;
                nextUsage = Time.time + delay;
                heroSize = frontHero.GetComponent<RectTransform> ();
                nextAttack = 0;
                nextChange = 0;
                moveX = 0;
                moveY = - heroSize.rect.height * heroSize.localScale.y;
                currentDirection = "down";
                setMove (currentDirection);
                for (int i = 0; i < 2; i++) {
                    spawnUnits ();
                }

                for (int i =0; i < GetComponentsInChildren<UnitProfile>().Length; i++) {
                    Debug.Log (GetComponentsInChildren <UnitProfile> () [i].name);
                }

            }

            // change character from button z or x
            if (!Core.getInstance ().isFight () && Time.time > nextChange) {
                // switching from front to endline
                if (Input.GetKeyUp ("x")) {

                    source.PlayOneShot (swapSound);

                    //nextChange = Time.time + delayChange;

                    Debug.Log (((HeroUnit)Core.getInstance ().heroLine () [0]).name);

                    // first, set tmp direction and position
                    Core.getInstance ().setTempPosition (((HeroUnit)Core.getInstance ().heroLine () [0]).transform.position);
                    Core.getInstance ().setTempDirection (((HeroUnit)Core.getInstance ().heroLine () [0]).getFlipDirection ());

                    // set the current head to false
                    frontHero.setHead (false);
                    frontHero.enabled = false;

                    // and move up the line from character 2 up ahead
                    for (int j = 1; j < Core.getInstance().heroLine().Count; j++) {
                        Vector3 otherTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position;
                        string dirTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).getFlipDirection ();
                        ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position = Core.getInstance ().getTempPosition ();
                        ((HeroUnit)Core.getInstance ().heroLine () [j]).flip (Core.getInstance ().getTempDirection ());
                        Core.getInstance ().setTempPosition (otherTemp);
                        Core.getInstance ().setTempDirection (dirTemp);
                    }
                    // then move the first hero to the last of the line
                    ((HeroUnit)Core.getInstance ().heroLine () [0]).transform.position = Core.getInstance ().getTempPosition ();
                    ((HeroUnit)Core.getInstance ().heroLine () [0]).flip (Core.getInstance ().getTempDirection ());

                    // now swap the array and set the rest
                    Core.getInstance ().heroLine ().RemoveAt (0);
                    Core.getInstance ().heroLine ().Add (frontHero);
                    frontHero.enabled = true;
                    frontHero = ((HeroUnit)Core.getInstance ().heroLine () [0]);

                    Debug.Log (((HeroUnit)Core.getInstance ().heroLine () [0]).name);

                    heroSize = frontHero.GetComponent<RectTransform> ();
                    Core.getInstance ().setCurrentHeadHero (frontHero);
                    Core.getInstance ().getCurrentHead ().setHead (true);
                    Core.getInstance ().getCurrentHead ().setDirection (currentDirection);

                    // switching from end to frontline
                } else if (Input.GetKeyUp ("z")) {

                    source.PlayOneShot (swapSound);

                    //nextChange = Time.time + delayChange;

                    // first, set tmp direction and position
                    Core.getInstance ().setTempPosition (((HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]).transform.position);
                    Core.getInstance ().setTempDirection (((HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]).getFlipDirection ());

                    // set the current head to false
                    frontHero.setHead (false);
                    frontHero = (HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1];
                    frontHero.enabled = false;
                    Vector3 otherTemp;
                    string dirTemp;

                    // and move back the line from hero before last to the last
                    for (int j = Core.getInstance().heroLine().Count-2; j >= 0; j--) {
                        otherTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position;
                        dirTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).getFlipDirection ();
                        ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position = Core.getInstance ().getTempPosition ();
                        ((HeroUnit)Core.getInstance ().heroLine () [j]).flip (Core.getInstance ().getTempDirection ());
                        Core.getInstance ().setTempPosition (otherTemp);
                        Core.getInstance ().setTempDirection (dirTemp);
                    }
                    // then move the last hero to the front of the line
                    otherTemp = ((HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]).transform.position;
                    dirTemp = ((HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]).getFlipDirection ();
                    ((HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]).transform.position = Core.getInstance ().getTempPosition ();
                    ((HeroUnit)Core.getInstance ().heroLine () [Core.getInstance ().heroLine ().Count - 1]).flip (Core.getInstance ().getTempDirection ());
                    Core.getInstance ().setTempPosition (otherTemp);
                    Core.getInstance ().setTempDirection (dirTemp);

                    // now swap the array
                    Core.getInstance ().heroLine ().RemoveAt (Core.getInstance ().heroLine ().Count - 1);
                    Core.getInstance ().heroLine ().Insert (0, frontHero);
                    frontHero.enabled = true;
                    heroSize = frontHero.GetComponent<RectTransform> ();
                    Core.getInstance ().setCurrentHeadHero (frontHero);
                    Core.getInstance ().getCurrentHead ().setHead (true);
                    Core.getInstance ().getCurrentHead ().setDirection (currentDirection);
                }
            }

            if (!isClicked) {
                if (Input.GetKey ("up") && !onDown) {
                    moveX = 0;
                    moveY = heroSize.rect.height * heroSize.localScale.y;
                    isClicked = true;
                    if ((onRight || onLeft) && isNearbyWallUp)
                        setMove (currentDirection);
                    else {
                        currentDirection = "up";
                        setMove (currentDirection);
                    }
                } else if (Input.GetKey ("down") && !onUp) {
                    moveX = 0;
                    moveY = - heroSize.rect.height * heroSize.localScale.y;
                    isClicked = true;
                    if ((onRight || onLeft) && isNearbyWallDown)
                        setMove (currentDirection);
                    else {
                        currentDirection = "down";
                        setMove (currentDirection);
                    }
                } else if (Input.GetKey ("left") && !onRight) {
                    moveX = - heroSize.rect.width * heroSize.localScale.x;
                    moveY = 0;
                    isClicked = true;
                    if ((onUp || onDown) && isNearbyWallLeft)
                        setMove (currentDirection);
                    else {
                        currentDirection = "left";
                        setMove (currentDirection);
                    }
                } else if (Input.GetKey ("right") && !onLeft) {

                    moveX = heroSize.rect.width * heroSize.localScale.x;
                    moveY = 0;
                    isClicked = true;
                    if ((onUp || onDown) && isNearbyWallRight)
                        setMove (currentDirection);
                    else {
                        currentDirection = "right";
                        setMove (currentDirection);
                    }
                }

            }

            if (Core.heroCrash) {
                losingHero ();
                nextUsage = Time.time + delay;
            }

            // check if is battle
            if (Core.getInstance ().isFight () && Time.time > nextAttack) {

                //check if still on fight
                if (Core.getInstance ().getCurrentHead () != null &&
                    !Core.getInstance ().heroWin ()
                    && !Core.getInstance ().enemyWin ()) {
                    source.PlayOneShot (atkSound);
                    nextAttack = Time.time + delayAttack;
                    Core.getInstance ().getFight ();
                    Debug.Log ("fight");
                }

                //check if hero death in each time
                if (Core.getInstance ().enemyWin ()) {

                    source.PlayOneShot (loseSound);
                    Core.getInstance ().getCurrentEnemy ().setDirection ("none");
                    Core.getInstance ().setTempPosition (((HeroUnit)Core.getInstance ().heroLine () [0]).transform.position);
                    Core.getInstance ().setTempDirection (((HeroUnit)Core.getInstance ().heroLine () [0]).getFlipDirection ());
                    Core.getInstance ().heroLine ().RemoveAt (0);

                    if (Core.getInstance ().heroLine ().Count == 0) {
                        Core.getInstance ().setActive (false);
                        Core.gameEnd = true;
                        Core.anotherRound = true;

                    } else {
                        frontHero = ((HeroUnit)Core.getInstance ().heroLine () [0]);
                        heroSize = frontHero.GetComponent<RectTransform> ();
                        Debug.Log (frontHero.name);
                        Core.getInstance ().setCurrentHeadHero (frontHero);
                        for (int j = 0; j < Core.getInstance().heroLine().Count; j++) {
                            Debug.Log ("count" + Core.getInstance ().heroLine ().Count);
                            Vector3 otherTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position;
                            string dirTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).getFlipDirection ();
                            ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position = Core.getInstance ().getTempPosition ();
                            ((HeroUnit)Core.getInstance ().heroLine () [j]).flip (Core.getInstance ().getTempDirection ());
                            Core.getInstance ().setTempPosition (otherTemp);
                            Core.getInstance ().setTempDirection (dirTemp);
                        }
                        Core.getInstance ().getCurrentHead ().setHead (true);
                        Core.getInstance ().getCurrentHead ().setDirection (currentDirection);
                        //setMove (currentDirection);
                        //Core.getInstance ().setHeroDirection (currentDirection);
                        Core.getInstance ().getCurrentEnemy ().setDirection (Core.getInstance ().getCurrentEnemy ().getTempEnemyStatus ());
                    }

                    Debug.Log ("enemy win");
                } else if (Core.getInstance ().heroWin ()) {
                    source.PlayOneShot (winSound);
                    Core.getInstance ().setActive (false);
                    Core.getInstance ().getCurrentEnemy ().setDirection ("death");
                    Core.getInstance ().removeCurrentEnemy (currentDirection);
                    moveX = tmpX;
                    moveY = tmpY;
                    Debug.Log ("hero win");

                    for (int i = 0; i < Core.getInstance().heroLine().Count; i++) {
                        Core.getInstance ().addScore (((HeroUnit)Core.getInstance ().heroLine () [i]).getHp ());
                    }

                    spawnUnits ();

                    if (delay > 0.05)
                        delay -= 0.01f;
                }

            }

            // While walking
            if (!Core.getInstance ().isFight () && Time.time > nextUsage && !Core.gameEnd) {

                source.PlayOneShot (walkSound);

                for (int i = 0; i < Core.getInstance().heroLine().Count; i++) {
                    //if on first hero
                    if (i == 0) {

                        Core.getInstance ().getCurrentHead ().flip (currentDirection);
                        Core.getInstance ().setTempPosition (((HeroUnit)Core.getInstance ().heroLine () [i]).transform.position);
                        Core.getInstance ().setTempDirection (((HeroUnit)Core.getInstance ().heroLine () [i]).getFlipDirection ());

                        if (Core.getInstance ().getToEnemy (currentDirection)) {
                            tmpX = moveX;
                            tmpY = moveY;
                            moveX = 0;
                            moveY = 0;
                            Core.getInstance ().setHeroDirection (currentDirection);
                            Core.getInstance ().setActive (true);
                            break;
                        } else {
                            isClicked = false;
                        }

                        frontHero.transform.position = new Vector3 (
                Mathf.Clamp (frontHero.transform.position.x + moveX, -5.04f, 5.04f),
                Mathf.Clamp (frontHero.transform.position.y + moveY, -3.6f, 3.6f),
                frontHero.transform.position.z);
                        nextUsage = Time.time + delay;

                        if (isCrash ()) {
                            losingHero ();
                            break;
                            //Core.getInstance ().heroLine ().re
                        }

                    } else {
                        Vector3 otherTemp = ((HeroUnit)Core.getInstance ().heroLine () [i]).transform.position;
                        string dirTemp = ((HeroUnit)Core.getInstance ().heroLine () [i]).getFlipDirection ();
                        ((HeroUnit)Core.getInstance ().heroLine () [i]).transform.position = Core.getInstance ().getTempPosition ();
                        ((HeroUnit)Core.getInstance ().heroLine () [i]).flip (Core.getInstance ().getTempDirection ());
                        Core.getInstance ().setTempPosition (otherTemp);
                        Core.getInstance ().setTempDirection (dirTemp);
                    }

                }
            }

            //Debug.Log("x : "+ (frontHero.transform.position.x + moveX) + " y : "+ (frontHero.transform.position.y + moveY));
        }
    }
コード例 #5
0
    // When head hero die, rearrange the line
    private void losingHero()
    {
        source.PlayOneShot (loseSound);
        Core.getInstance ().setTempPosition (((HeroUnit)Core.getInstance ().heroLine () [0]).transform.position);
        Core.getInstance ().setTempDirection (((HeroUnit)Core.getInstance ().heroLine () [0]).getFlipDirection ());
        Debug.Log ("crash");
        Core.getInstance ().getCurrentHead ().addHp (-100);
        Core.getInstance ().heroLine ().RemoveAt (0);

        if (Core.getInstance ().heroLine ().Count == 0) {
            Core.gameEnd = true;
            Core.anotherRound = true;
        } else {

            frontHero = ((HeroUnit)Core.getInstance ().heroLine () [0]);
            heroSize = frontHero.GetComponent<RectTransform> ();
            Debug.Log (frontHero.name);
            Core.getInstance ().setCurrentHeadHero (frontHero);
            Core.getInstance ().getCurrentHead ().setHead (true);
            Core.getInstance ().getCurrentHead ().setDirection (currentDirection);
            //setMove (currentDirection);
            if (Core.heroCrash)
                Core.heroCrash = false;
            else {
                for (int j = 0; j < Core.getInstance().heroLine().Count; j++) {
                    Vector3 otherTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position;
                    string dirTemp = ((HeroUnit)Core.getInstance ().heroLine () [j]).getFlipDirection ();
                    ((HeroUnit)Core.getInstance ().heroLine () [j]).transform.position = Core.getInstance ().getTempPosition ();
                    ((HeroUnit)Core.getInstance ().heroLine () [j]).flip (Core.getInstance ().getTempDirection ());
                    Core.getInstance ().setTempPosition (otherTemp);
                    Core.getInstance ().setTempDirection (dirTemp);
                }
            }
        }
    }