//At minimum, one species must recover hunger. public void generateSpecies() { Controller.Instance.speciesList = new EdiblePlant[listLength]; for (int i = 0; i < Controller.Instance.speciesList.Length; i++) { EdiblePlant e = Instantiate(baseplant, transform.position, Quaternion.identity); e.healthHealed = Random.Range(-10, 10); e.hungerRecovered = Random.Range(-10, 10); int randomVal = Random.Range(0, 8); switch (randomVal) { case 0: e.pE = EdiblePlant.possibleEffects.None; break; case 1: e.pE = EdiblePlant.possibleEffects.Poisoned; break; case 2: e.pE = EdiblePlant.possibleEffects.Paralyzed; break; case 3: e.pE = EdiblePlant.possibleEffects.Speedy; break; case 4: e.pE = EdiblePlant.possibleEffects.Slowed; break; case 5: e.pE = EdiblePlant.possibleEffects.Confused; break; case 6: e.pE = EdiblePlant.possibleEffects.Drunk; break; case 7: e.pE = EdiblePlant.possibleEffects.Hungry; break; } e.spr.sprite = spriteList[Random.Range(0, spriteList.Length)]; Controller.Instance.speciesList[i] = e; } checkSpecies(); }
//If the player hits the spacebar while on top of an edible plant, eat the plant, then apply the effects to the player. public void consumeFood() { if (Input.GetKeyDown(KeyCode.Space)) { Collider2D[] checkForItem = Physics2D.OverlapBoxAll(transform.position, GetComponent <BoxCollider2D>().size, 0); foreach (Collider2D itemCollider in checkForItem) { if (itemCollider.GetComponent <EdiblePlant>() != null) { EdiblePlant e = itemCollider.GetComponent <EdiblePlant>(); health += e.healthHealed; energy += e.hungerRecovered; //If th eplant has an effect, flip it on. switch (e.pE) { case EdiblePlant.possibleEffects.None: possibleStatuses[0] = true; timeLeft[0] = 5f; break; case EdiblePlant.possibleEffects.Poisoned: possibleStatuses[1] = true; timeLeft[1] = 5f; break; case EdiblePlant.possibleEffects.Paralyzed: possibleStatuses[2] = true; timeLeft[2] = 5f; break; case EdiblePlant.possibleEffects.Speedy: possibleStatuses[3] = true; timeLeft[3] = 5f; break; case EdiblePlant.possibleEffects.Slowed: possibleStatuses[4] = true; timeLeft[4] = 5f; break; case EdiblePlant.possibleEffects.Confused: possibleStatuses[5] = true; timeLeft[5] = 5f; break; case EdiblePlant.possibleEffects.Drunk: possibleStatuses[6] = true; timeLeft[6] = 5f; break; case EdiblePlant.possibleEffects.Hungry: possibleStatuses[7] = true; timeLeft[7] = 5f; break; } Destroy(e.gameObject); } } } }
// Use this for initialization void Start() { //this will ensure that the biome has a randomly picked color upon activation if (this.gameObject.tag == "DesertTile") { isDesert = true; } if (this.gameObject.tag == "GrassTile") { isGrass = true; } if (this.gameObject.tag == "IceTile") { isIce = true; } this.GetComponent <MeshRenderer>().material.color = Random.ColorHSV(0f, 1f, 0f, 1f, 0f, 1f); float textureNumber = Random.Range(0, 3); //these for statements will populate the world accordingly with how mnay of a specific asset you want at randomized locations with //randomized size as well. if (isDesert) { for (int i = 0; i < amountOfAsset1; i++) { spawnPosition = new Vector3(Random.Range(-0.65f, 0.65f), -1f, Random.Range(-0.65f, 0.65f)); GameObject biome = (GameObject)Instantiate(desertTerrainAsset1, transform.position, Quaternion.identity); // biome.transform.localScale = new Vector3(Random.Range(1, 5), Random.Range(1, 5), 1); biome.transform.SetParent(this.transform); biome.transform.localPosition = spawnPosition; } for (int i = 0; i < amountOfAsset2; i++) { spawnPosition = new Vector3(Random.Range(-0.65f, 0.65f), -1f, Random.Range(-0.65f, 0.65f)); GameObject biome = (GameObject)Instantiate(desertTerrainAsset2, transform.position, Quaternion.identity); // biome.transform.localScale = new Vector3(Random.Range(1, 5), Random.Range(1, 5), 1); biome.transform.SetParent(this.transform); biome.transform.localPosition = spawnPosition; } for (int i = 0; i < amountOfAsset3; i++) { spawnPosition = new Vector3(Random.Range(-0.65f, 0.65f), -1f, Random.Range(-0.65f, 0.65f)); GameObject biome = (GameObject)Instantiate(desertTerrainAsset3, transform.position, Quaternion.identity); // biome.transform.localScale = new Vector3(Random.Range(1, 5), Random.Range(1, 5), 1); biome.transform.SetParent(this.transform); biome.transform.localPosition = spawnPosition; } for (int i = 0; i < amountOfPlants; i++) { spawnPosition = new Vector3(Random.Range(-0.65f, 0.65f), -1f, Random.Range(-0.65f, 0.65f)); EdiblePlant plant = Controller.Instance.speciesList[0]; EdiblePlant terrainPlant = (EdiblePlant)Instantiate(plant, transform.position, Quaternion.identity); terrainPlant.transform.SetParent(this.transform); terrainPlant.transform.localPosition = spawnPosition; } } if (isGrass) { for (int i = 0; i < amountOfAsset1; i++) { spawnPosition = new Vector3(Random.Range(-0.65f, 0.65f), -1f, Random.Range(-0.65f, 0.65f)); GameObject biome = (GameObject)Instantiate(grassTerrainAsset1, transform.position, Quaternion.identity); // biome.transform.localScale = new Vector3(Random.Range(1, 5), Random.Range(1, 5), 1); biome.transform.SetParent(this.transform); biome.transform.localPosition = spawnPosition; } for (int i = 0; i < amountOfAsset2; i++) { spawnPosition = new Vector3(Random.Range(-0.65f, 0.65f), -1f, Random.Range(-0.65f, 0.65f)); GameObject biome = (GameObject)Instantiate(grassTerrainAsset2, transform.position, Quaternion.identity); // biome.transform.localScale = new Vector3(Random.Range(1, 5), Random.Range(1, 5), 1); biome.transform.SetParent(this.transform); biome.transform.localPosition = spawnPosition; } for (int i = 0; i < amountOfAsset3; i++) { spawnPosition = new Vector3(Random.Range(-0.65f, 0.65f), -1f, Random.Range(-0.65f, 0.65f)); GameObject biome = (GameObject)Instantiate(grassTerrainAsset3, transform.position, Quaternion.identity); // biome.transform.localScale = new Vector3(Random.Range(1, 5), Random.Range(1, 5), 1); biome.transform.SetParent(this.transform); biome.transform.localPosition = spawnPosition; } for (int i = 0; i < amountOfPlants; i++) { spawnPosition = new Vector3(Random.Range(-0.65f, 0.65f), -1f, Random.Range(-0.65f, 0.65f)); EdiblePlant plant = Controller.Instance.speciesList[1]; EdiblePlant terrainPlant = (EdiblePlant)Instantiate(plant, transform.position, Quaternion.identity); terrainPlant.transform.SetParent(this.transform); terrainPlant.transform.localPosition = spawnPosition; } } if (isIce) { for (int i = 0; i < amountOfAsset1; i++) { spawnPosition = new Vector3(Random.Range(-0.65f, 0.65f), -1f, Random.Range(-0.65f, 0.65f)); GameObject biome = (GameObject)Instantiate(iceTerrainAsset1, transform.position, Quaternion.identity); // biome.transform.localScale = new Vector3(Random.Range(1, 5), Random.Range(1, 5), 1); biome.transform.SetParent(this.transform); biome.transform.localPosition = spawnPosition; } for (int i = 0; i < amountOfAsset2; i++) { spawnPosition = new Vector3(Random.Range(-0.65f, 0.65f), -1f, Random.Range(-0.65f, 0.65f)); GameObject biome = (GameObject)Instantiate(iceTerrainAsset2, transform.position, Quaternion.identity); // biome.transform.localScale = new Vector3(Random.Range(1, 5), Random.Range(1, 5), 1); biome.transform.SetParent(this.transform); biome.transform.localPosition = spawnPosition; } for (int i = 0; i < amountOfAsset3; i++) { spawnPosition = new Vector3(Random.Range(-0.65f, 0.65f), -1f, Random.Range(-0.65f, 0.65f)); GameObject biome = (GameObject)Instantiate(iceTerrainAsset3, transform.position, Quaternion.identity); // biome.transform.localScale = new Vector3(Random.Range(1, 5), Random.Range(1, 5), 1); biome.transform.SetParent(this.transform); biome.transform.localPosition = spawnPosition; } for (int i = 0; i < amountOfPlants; i++) { spawnPosition = new Vector3(Random.Range(-0.65f, 0.65f), -1f, Random.Range(-0.65f, 0.65f)); EdiblePlant plant = Controller.Instance.speciesList[2]; EdiblePlant terrainPlant = (EdiblePlant)Instantiate(plant, transform.position, Quaternion.identity); terrainPlant.transform.SetParent(this.transform); terrainPlant.transform.localPosition = spawnPosition; } } }