コード例 #1
0
    public void updateElement(PlayerController.ElementType newElement)
    {
        elementType             = newElement;
        mainElementDisplay.text = "Element: " + elementType.ToString();

        //TODO:
        if (newElement == PlayerController.ElementType.Fire)
        {
            // set the color of the radial energy bar
            LoadingBar.GetComponent <Image>().color = Color.red;
        }
        else if (newElement == PlayerController.ElementType.Water)
        {
            // set the color of the radial energy bar
            LoadingBar.GetComponent <Image>().color = Color.blue;
        }
        else if (newElement == PlayerController.ElementType.Lightning)
        {
            // set the color of the radial energy bar
            LoadingBar.GetComponent <Image>().color = Color.yellow;
        }
        else if (newElement == PlayerController.ElementType.Earth)
        {
            // set the color of the radial energy bar
            LoadingBar.GetComponent <Image>().color = new Color(120 / 255f, 82 / 255f, 45 / 255f);
        }
    }
コード例 #2
0
    public IEnumerator TestAoeOnMovingEnemy()
    {
        GameObject maincanvas = Instantiate(Resources.Load("Tests/maincanvas")) as GameObject;
        GameObject maincamera = Instantiate(Resources.Load("Tests/maincamera")) as GameObject;
        GameObject gm         = Instantiate(Resources.Load("Tests/GameManager")) as GameObject;

        var        enemy         = Resources.Load("Tests/Enemy_Bat 1");
        Vector2    startposition = new Vector2(0.0f, 0.0f);
        Vector2    endposition   = new Vector2(0.0f, 10.0f);
        GameObject enemy1        = Instantiate(enemy, endposition, new Quaternion()) as GameObject;
        //GameObject enemy2 = Instantiate (enemy, new Vector2 (0.0f, 20.0f), new Quaternion()) as GameObject;
        int startHealth = enemy1.GetComponentInChildren <Enemy>().hp;

        NetworkServer.Listen(7777);

        yield return(new WaitForSeconds(1));

        ProjectileFactory projectileFactory = gm.GetComponent <ProjectileFactory> ();

        PlayerController.ElementType element = PlayerController.ElementType.Water;
        int        level           = 2;
        GameObject projectileClone = Instantiate(Resources.Load("Tests/WaterProjectile2"), startposition, new Quaternion()) as GameObject;

        projectileClone.GetComponent <ProjectileController>().belongsToPlayer();
        Vector2 shootDirection = new Vector2(0.0f, 1.0f);
        Vector2 velocity       = shootDirection.normalized * projectileClone.GetComponent <ProjectileController> ().projectileSpeed;
        float   rotation       = Mathf.Atan2(shootDirection.y, shootDirection.x) * Mathf.Rad2Deg;

        int projectiledamage = projectileClone.GetComponent <ProjectileController> ().projectileDamage;
        int aoedamage        = projectileClone.GetComponent <ProjectileController> ().AOEExplosionPrefab.GetComponent <AOEExplosion> ().AOEDamage;

        float endTime = Time.time + 5.0f;
        bool  once    = true;
        bool  once2   = true;

        enemy1.GetComponentInChildren <Enemy> ().moveSpeed = 0.1f;
        while (Time.time < endTime)
        {
            //if (enemy1.GetComponentInChildren<Enemy>().hp<startHealth && once){
            if (once)
            {
                GameObject waypoint = GameObject.FindGameObjectWithTag("WayPoint");
                waypoint.transform.position = new Vector2(0.0f, 20.0f);
                once = false;
            }
            if (endTime - Time.time < 4.0f && once2)
            {
                projectileClone.GetComponent <ProjectileController> ().setVelocityAndRotation(velocity, rotation);
                once2 = false;
            }
            yield return(new WaitForEndOfFrame());
        }

        int        totaldamage    = projectiledamage + aoedamage;
        int        expectedhealth = startHealth - totaldamage;
        GameObject newenemy       = GameObject.FindGameObjectWithTag("Enemy");
        int        actualhealth   = newenemy.GetComponent <Enemy> ().hp;

        Assert.AreEqual(expectedhealth, actualhealth);
    }
コード例 #3
0
 public void depleteHealth(int damage, PlayerController.ElementType element)
 {
     if (element != elementType && elementType != PlayerController.ElementType.Default)
     {
         return;
     }
     if (health - damage <= 0)
     {
         int  value = Random.Range(minValue, maxValue + 1);
         bool drop  = Random.value <= dropRate;
         Debug.Log(value + "Crystal");
         if (value > 0 && drop)
         {
             GameObject crystal = Instantiate(crystalPrefab, transform.position, Quaternion.identity);
             crystal.GetComponent <Collectible> ().setValue(value);
             //crystal.transform.localScale = new Vector3 (value / 50, value / 50, 1);
             Debug.Log("Crystal" + crystal);
         }
         if (_animator)
         {
             _animator.SetTrigger("GlowingRed");
         }
         Invoke("destroyNow", timeBeforeDestruction);
     }
     else
     {
         health -= damage;
         if (_animator)
         {
             _animator.SetInteger("HealthLevel", health * 3 / maxHealth);
         }
     }
 }
コード例 #4
0
    public IEnumerator TestEnergyResetToNewPowerup2()
    {
        GameObject gm           = (GameObject)Instantiate(Resources.Load("Tests/gamemanager"));
        var        playerPrefab = Resources.Load("Tests/player");
        GameObject player       = (GameObject)Instantiate(playerPrefab);

        gm.GetComponent <GUIManager> ().playerController = player.GetComponent <PlayerController> ();

        int startEnergy = 50;
        int startLevel  = 3;

        PlayerController.ElementType startType = PlayerController.ElementType.Fire;
        int energyAmount = 30;

        player.GetComponent <PlayerController> ().testMode = true;

        NetworkServer.Listen(7777);

        yield return(new WaitForSeconds(5));

        player.GetComponent <PlayerController> ().energy       = startEnergy;
        player.GetComponent <PlayerController> ().elementType  = startType;
        player.GetComponent <PlayerController> ().elementLevel = startLevel;
        yield return(new WaitForSeconds(5));

        int tempEnergy = player.GetComponent <PlayerController> ().energy;

        player.GetComponent <PlayerController> ().gainPowerUp(PlayerController.ElementType.Fire, energyAmount);
        GameObject newplayer      = GameObject.FindGameObjectWithTag("Player");
        int        currentAmount  = newplayer.GetComponent <PlayerController> ().energy;
        int        expectedAmount = tempEnergy + energyAmount;

        Assert.AreEqual(expectedAmount, currentAmount);
    }
コード例 #5
0
    public IEnumerator TestEnergyResetToDefault2()
    {
        GameObject gm           = (GameObject)Instantiate(Resources.Load("Tests/gamemanager"));
        var        playerPrefab = Resources.Load("Tests/player");
        GameObject player       = (GameObject)Instantiate(playerPrefab);

        gm.GetComponent <GUIManager> ().playerController = player.GetComponent <PlayerController> ();

        int startEnergy     = 50;
        int startLevel      = 1;
        int energydecrement = 0;

        PlayerController.ElementType startType = PlayerController.ElementType.Fire;

        player.GetComponent <PlayerController> ().testMode = true;

        NetworkServer.Listen(7777);

        yield return(new WaitForSeconds(5));

        player.GetComponent <PlayerController> ().energy       = startEnergy;
        player.GetComponent <PlayerController> ().elementType  = startType;
        player.GetComponent <PlayerController> ().elementLevel = startLevel;
        yield return(new WaitForSeconds(5));

        player.GetComponent <PlayerController> ().depleteEnergy(energydecrement);
        yield return(new WaitForSeconds(5));

        GameObject newplayer = GameObject.FindGameObjectWithTag("Player");

        PlayerController.ElementType currentType  = newplayer.GetComponent <PlayerController> ().elementType;
        PlayerController.ElementType expectedType = startType;
        Assert.AreEqual(expectedType, currentType);
    }
    [UnityTest]     /*1 Projectile to enemeyBat: enemyBat Hp=7? true;*/
    public IEnumerator ProjectileType2()
    {
        NetworkServer.Listen(7777);
        GameObject        gm = Instantiate(Resources.Load("Tests/GameManager")) as GameObject;
        ProjectileFactory projectileFactory = gm.GetComponent <ProjectileFactory> ();

        PlayerController.ElementType element = PlayerController.ElementType.Fire;
        int         level      = 2;
        Rigidbody2D projectile = projectileFactory.getProjectileFromType(element, level);

        yield return(new WaitForSeconds(1));

        GameObject projectile2 = Instantiate(Resources.Load("Tests/FireballProjectile2")) as GameObject;

        Assert.AreEqual(projectile2.GetComponent <ProjectileController>().projectileDamage, projectile.gameObject.GetComponent <ProjectileController>().projectileDamage);
    }
コード例 #7
0
    public IEnumerator TestAoeOnStaticEnemy()
    {
        GameObject maincanvas = Instantiate(Resources.Load("Tests/maincanvas")) as GameObject;
        GameObject maincamera = Instantiate(Resources.Load("Tests/maincamera")) as GameObject;
        GameObject gm         = Instantiate(Resources.Load("Tests/GameManager")) as GameObject;

        var        enemy  = Resources.Load("Tests/Enemy_Bat 1");
        GameObject enemy1 = Instantiate(enemy, new Vector2(0.0f, 10.0f), new Quaternion()) as GameObject;
        //GameObject enemy2 = Instantiate (enemy, new Vector2 (0.0f, 20.0f), new Quaternion()) as GameObject;
        int startHealth = enemy1.GetComponentInChildren <Enemy>().hp;

        NetworkServer.Listen(7777);

        yield return(new WaitForSeconds(1));

        ProjectileFactory projectileFactory = gm.GetComponent <ProjectileFactory> ();

        PlayerController.ElementType element = PlayerController.ElementType.Water;
        int        level           = 2;
        GameObject projectileClone = Instantiate(Resources.Load("Tests/WaterProjectile2"), new Vector2(0.0f, 0.0f), new Quaternion()) as GameObject;

        projectileClone.GetComponent <ProjectileController>().belongsToPlayer();
        Vector2 shootDirection = new Vector2(0.0f, 1.0f);
        Vector2 velocity       = shootDirection.normalized * projectileClone.GetComponent <ProjectileController> ().projectileSpeed;
        float   rotation       = Mathf.Atan2(shootDirection.y, shootDirection.x) * Mathf.Rad2Deg;

        projectileClone.GetComponent <ProjectileController> ().setVelocityAndRotation(velocity, rotation);

        int projectiledamage = projectileClone.GetComponent <ProjectileController> ().projectileDamage;
        int aoedamage        = projectileClone.GetComponent <ProjectileController> ().AOEExplosionPrefab.GetComponent <AOEExplosion> ().AOEDamage;

        Debug.Log(projectiledamage);
        Debug.Log(aoedamage);

        yield return(new WaitForSeconds(5));

        int        totaldamage    = projectiledamage + aoedamage;
        int        expectedhealth = startHealth - totaldamage;
        GameObject newenemy       = GameObject.FindGameObjectWithTag("Enemy");
        int        actualhealth   = newenemy.GetComponent <Enemy> ().hp;

        Assert.AreEqual(expectedhealth, actualhealth);
    }
コード例 #8
0
    public IEnumerator TestPlayerWithPowerUp1()
    {
        GameObject gameManager  = (GameObject)Instantiate(Resources.Load("Tests/gamemanager"));
        var        playerPrefab = Resources.Load("Tests/player");
        GameObject player       = (GameObject)Instantiate(playerPrefab);

        gameManager.GetComponent <GUIManager> ().register(player);
        player.GetComponent <PlayerController> ().testMode = true;

        NetworkServer.Listen(7777);

        yield return(new WaitForSeconds(2));

        // we now spawn the power up for the player's consumption
        var        powerupPrefab = Resources.Load("Tests/powerup");
        GameObject powerup       = (GameObject)Instantiate(powerupPrefab);

        powerup.transform.position = new Vector2(0.0f, 0.0f);
        int setEnergy = 50;

        PlayerController.ElementType setElement = PlayerController.ElementType.Fire;
        powerup.GetComponent <PowerUpPickup> ().energy      = setEnergy;
        powerup.GetComponent <PowerUpPickup> ().elementType = setElement;

        yield return(new WaitForSeconds(1));

        float lossRate = player.GetComponent <PlayerController> ().energyLossRate;

        yield return(new WaitForSeconds(4));

        GameObject newplayer = GameObject.FindGameObjectWithTag("Player");
        int        newEnergy = newplayer.GetComponent <PlayerController> ().energy;

        PlayerController.ElementType newElement = newplayer.GetComponent <PlayerController> ().elementType;

        Debug.Log(newEnergy);
        Debug.Log(setEnergy - (lossRate * 5));
        Debug.Log(newElement);
        Debug.Log(setElement);
        var check = (newEnergy == (setEnergy - (lossRate * 5)) && newElement == setElement);

        Assert.That(check);
    }
コード例 #9
0
    public void depleteHealth(int damage, PlayerController.ElementType elementType)
    {
        if (immuneTo.Contains(elementType))
        {
            return;
        }
        if (hp - damage <= 0)
        {
            // add Spawn Gold coin , Kenny
            int  value = Random.Range(minValue, maxValue + 1);
            bool drop  = Random.value <= dropRate;
            Debug.Log(value + "Crystal");
            if (value > 0 && drop)
            {
                GameObject crystal = Instantiate(crystalPrefab, transform.position, Quaternion.identity);
                crystal.GetComponent <Collectible> ().setValue(value);
                //crystal.transform.localScale = new Vector3 (value / 50, value / 50, 1);
                Debug.Log("Crystal" + crystal);
            }
            // if belongs to a spawner, reduce monsterCountLeft
            if (spawnerParent != null)
            {
                spawnerParent.GetComponent <MonsterRoomSpawner> ().reduceMonsterCount();
            }

            hp = 0;
            Instantiate(explosionPrefab, transform.position, transform.rotation);
            for (int i = 0; i < wayPoints.Length; i++)
            {
                DestroyObject(wayPoints [i]);
            }
            DestroyObject(transform.parent.gameObject);
            DestroyObject(EnemyHealthBar);
            DestroyObject(this.gameObject);
        }
        else
        {
            hp -= damage;
        }
    }
コード例 #10
0
    // Return the corresponding projectile based on current elementType
    public Rigidbody2D getProjectileFromType(PlayerController.ElementType element, int level)
    {
        switch (element)
        {
        case PlayerController.ElementType.Fire:
            switch (level)
            {
            case 0:
                return(projectileFire0);

            case 1:
                return(projectileFire1);

            case 2:
                return(projectileFire2);

            case 3:
                return(projectileFire3);

            default:
                return(projectileDefault);
            }

        case PlayerController.ElementType.Water:
            switch (level)
            {
            case 0:
                return(projectileWater0);

            case 1:
                return(projectileWater1);

            case 2:
                return(projectileWater2);

            case 3:
                return(projectileWater3);

            default:
                return(projectileDefault);
            }

        case PlayerController.ElementType.Lightning:
            switch (level)
            {
            case 0:
                return(projectileLightning0);

            case 1:
                return(projectileLightning1);

            case 2:
                return(projectileLightning2);

            case 3:
                return(projectileLightning3);

            default:
                return(projectileDefault);
            }

        case PlayerController.ElementType.Earth:
            switch (level)
            {
            case 1:
                return(projectileEarth1);

            case 2:
                return(projectileEarth2);

            case 3:
                return(projectileEarth3);

            default:
                return(projectileDefault);
            }

        default:
            return(projectileDefault);
        }
    }