Example #1
0
    //Given a human spawn point on the map, spawn the amount of humans.
    public List<GameObject> spawnHuman(Vector2 location, int amount, SpawnBoat spawnBoat)
    {
        List<GameObject> humans = new List<GameObject>(amount);

        for (int currHuman = 0; currHuman < amount; ++currHuman) {

            StartCoroutine(spawnHuman (currHuman * 3.0f, location, humans, spawnBoat));
        }

        return humans;
    }
Example #2
0
    //Spawns a human at the given location after a delay.
    // Humans face towards the center of the map.
    IEnumerator spawnHuman(float delay, Vector2 location, List<GameObject> humansList, SpawnBoat spawnBoat = null)
    {
        yield return new WaitForSeconds(delay);

        string[] files = Directory.GetFiles(Application.dataPath + "/../GA/Genomes/");

        List<string> fileNames = new List<string>();

        //Loop through each file in the directory
        for (int currFile = 0; currFile < files.Length; ++currFile) {

            if(!files[currFile].Substring(files[currFile].Length-4).Equals(".txt"))
                continue;

            fileNames.Add(files[currFile]);
        }

        files = fileNames.ToArray();

        Genome genome;
        if(files.Length != 0){

            int index = Random.Range(0, files.Length);
            genome = Genome.load(File.ReadAllText(files[index]));
            //Debug.Log("Genome from file: "+ files[index]);
        }
        else {
            genome = new FiveFeelerGenome();
        }

        GameObject human = spawnHumanImmediate(location, map.getSpawnAngle(location), genome);

        //Quaternion.LookRotation(transform.forward, Vector3.zero - map.cellIndexToWorld(location))
        humansList.Add (human);

        if(spawnBoat != null){
            human.GetComponent<HumanAgent>().spawnBoat = spawnBoat;
            spawnBoat.incrementNumSpawned();
        }
    }