Exemple #1
0
    EnemyShipDictionary GetAvailableEnemiesSprites(int sizeCategory, EnemyShipDictionary ships)
    {
        EnemyShipDictionary availableEnemies = new EnemyShipDictionary();

        foreach (KeyValuePair <string, EnemyShip> ship in ships)
        {
            if (ship.Value.GetSize() == sizeCategory)
            {
                availableEnemies.Add(ship.Key, ship.Value);
            }
        }
        return(availableEnemies);
    }
Exemple #2
0
    void GenerateArea(GameObject obj, GameObject parent, float x, float y, float length, int amount)
    {
        for (int i = 0; i < amount; i++)
        {
            float      randX  = UnityEngine.Random.Range(0, length);
            float      randY  = UnityEngine.Random.Range(0, length);
            GameObject newObj = Instantiate(obj, parent.transform);
            newObj.transform.localPosition = new Vector3(x + randX, y + randY);
            int sizeCategory = UnityEngine.Random.Range(1, 4);
            EnemyShipDictionary availableEnemies = GetAvailableEnemiesSprites(sizeCategory, enemyShips);
            EnemyShip           ship             = availableEnemies.ElementAt(UnityEngine.Random.Range(0, availableEnemies.Count)).Value;
            newObj.GetComponent <SpriteRenderer>().sprite = ship.GetSprite();
            EnemyController shipController = newObj.GetComponent <EnemyController>();
            shipController.health    = ship.GetHealth();
            shipController.maxHealth = ship.GetHealth();
            newObj.GetComponentInChildren <HealthVisualizer>().healthMax = ship.GetHealth();
            shipController.detectionRadius = ship.GetSize() * 12.5f;
            shipController.speedModifier   = (5 - ship.GetSize()) / 4.0f;
            newObj.transform.localScale    = new Vector3(sizeCategory + 1, sizeCategory + 1, 1);

            Destroy(newObj.GetComponent <PolygonCollider2D>());
            newObj.AddComponent <PolygonCollider2D>();
        }
    }