public void ActivateShield() { if (shields > 0) { shields--; abilities--; GetComponent <AudioSource>().clip = immuneSound; GetComponent <AudioSource>().Play(); if (maxSpeed < baseMaxSpeed) { maxSpeed = baseMaxSpeed; } Camera.main.GetComponentInChildren <CameraOverlay>().ShowOverlay(); //Check all pedestrians for negative ones, and destroy them. GameObject[] allPedestrians = GameObject.FindGameObjectsWithTag("Pedestrian"); foreach (GameObject pedestrianObject in allPedestrians) { Pedestrian pedestrian = pedestrianObject.GetComponent <Pedestrian>(); if (pedestrian.GetRole() == Role.Stink || pedestrian.GetRole() == Role.Chunky || pedestrian.GetRole() == Role.Dazer) { Destroy(pedestrian.gameObject); } } effectsAnimator.SetTrigger("Norm"); } }
void GetNewRole(GameObject pedestrian) { float randomValue = Random.Range(0, raverPercentage + officerPercentage + dazerPercentage + inspectorPercentage + chunkyPercentage + stinkPercentage + coinPercentage); Pedestrian pedestrianScript = pedestrian.GetComponent <Pedestrian>(); if (randomValue < coinPercentage) { pedestrianScript.SetRole(Role.Coin); pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = pedestrianSprites [Random.Range(0, pedestrianSprites.Length)]; } else if (randomValue < stinkPercentage + coinPercentage) { pedestrianScript.SetRole(Role.Stink); pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = pedestrianSprites [Random.Range(0, pedestrianSprites.Length)]; } else if (randomValue < chunkyPercentage + stinkPercentage + coinPercentage) { pedestrianScript.SetRole(Role.Chunky); pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = chunkySprites [Random.Range(0, chunkySprites.Length)]; } else if (randomValue < inspectorPercentage + chunkyPercentage + stinkPercentage + coinPercentage) { pedestrianScript.SetRole(Role.Inspector); pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = inspectorSprites [Random.Range(0, inspectorSprites.Length)]; } else if (randomValue < dazerPercentage + inspectorPercentage + chunkyPercentage + stinkPercentage + coinPercentage) { pedestrianScript.SetRole(Role.Dazer); pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = dazerSprites [Random.Range(0, dazerSprites.Length)]; } else if (randomValue < officerPercentage + dazerPercentage + inspectorPercentage + chunkyPercentage + stinkPercentage + coinPercentage) { pedestrianScript.SetRole(Role.Officer); pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = officerSprites [Random.Range(0, officerSprites.Length)]; } else if (randomValue < raverPercentage + officerPercentage + dazerPercentage + inspectorPercentage + chunkyPercentage + stinkPercentage + coinPercentage) { pedestrianScript.SetRole(Role.Raver); } else { pedestrianScript.SetRole(Role.Norm); pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = pedestrianSprites [Random.Range(0, pedestrianSprites.Length)]; } if (pedestrianScript.GetRole() != Role.Norm) { pedestrianScript.SetMoveSpeed(2); } }
//Handles all interaction with pedestrians, and barricades. void OnCollisionEnter2D(Collision2D other) { //If colliding with a pedestrian. if (other.gameObject.GetComponent <Pedestrian>()) { Pedestrian collidedWith = other.gameObject.GetComponent <Pedestrian>(); switch (collidedWith.GetRole()) { case Role.Coin: if (currentPassengers < maxPassengers) { PassengerObjects[currentPassengers].GetComponent <Image>().sprite = PassengerSprites[1]; GetComponent <AudioSource>().clip = coinSound; GetComponent <AudioSource>().Play(); streetcarAnimator.SetTrigger("Grow"); //Add passenger data. PassengerInfo.Add(new PedestrianData(other.gameObject.GetComponent <SpriteRenderer>().sprite, "Coin", currentPassengers)); currentPassengers++; Destroy(other.gameObject); } break; //No slot taken. case Role.Raver: scoreMultiplier = true; raverBuffTime = 30; raverTimeBar.fillAmount = 1; raverTimeBar.gameObject.SetActive(true); raverTimeBar.GetComponent <UIColorStrobe>().StartCoroutine("RecursiveColorChange"); GetComponent <AudioSource>().clip = raverSound; GetComponent <AudioSource>().Play(); streetcarAnimator.SetBool("Raver", true); musicController.PlayRaverMusic(); // Hide raver other.transform.GetComponent <SpriteRenderer>().enabled = false; other.transform.GetComponent <Collider2D>().enabled = false; other.transform.GetComponent <Pedestrian>().enabled = false; other.transform.position = this.transform.position; other.transform.SetParent(this.transform); break; //No slot taken. case Role.Dazer: //Stun the streetcar. StartCoroutine(TempDisableMovement(other.gameObject)); //Create stun noise. Done so that the remove passenger audio doesn't cancel out this stun noise. GameObject dazerAudioGameObject = new GameObject(); dazerAudioGameObject.AddComponent <AudioSource>(); dazerAudioGameObject.GetComponent <AudioSource>().clip = stunSound; dazerAudioGameObject = Instantiate(dazerAudioGameObject, Vector3.zero, Quaternion.identity) as GameObject; dazerAudioGameObject.GetComponent <AudioSource>().Play(); Destroy(dazerAudioGameObject, 5); //Force out half of passenger count. int halfOfPassengers = (int)(0.5f * currentPassengers); for (int i = 0; i < halfOfPassengers; i++) { int direction = (Random.value < 0.5f) ? -1 : 1; RemovePassenger(direction); } Destroy(other.gameObject); break; case Role.Stink: //Create fart noise. Done so that the remove passenger audio doesn't cancel out this fart noise. GameObject fartSoundGameobject = new GameObject(); fartSoundGameobject.AddComponent <AudioSource>(); fartSoundGameobject.GetComponent <AudioSource>().clip = fartSound; fartSoundGameobject = Instantiate(fartSoundGameobject, Vector3.zero, Quaternion.identity) as GameObject; fartSoundGameobject.GetComponent <AudioSource>().Play(); Destroy(fartSoundGameobject, 5); //Force out random number of passengers. int passengersToRemove = Random.value < 0.5f ? 3 : 4; for (int i = 0; i < passengersToRemove; i++) { int direction = (Random.value < 0.5f) ? -1 : 1; RemovePassenger(direction); } //Adjust capacity panel after passengers removed. PassengerObjects[currentPassengers].GetComponent <Image>().sprite = PassengerSprites[5]; //Trigger animations for streetcar and UI. PassengerObjects[currentPassengers].GetComponent <Animator>().SetTrigger("Pulse"); streetcarAnimator.SetTrigger("Shrink"); //Add passenger data. PassengerInfo.Add(new PedestrianData(other.gameObject.GetComponent <SpriteRenderer>().sprite, "Stink", currentPassengers)); stinkerNum++; currentPassengers++; Destroy(other.gameObject); break; case Role.Inspector: if (currentPassengers < maxPassengers) { if (abilities < 4) { speedBoosts++; currentAbilities[abilities] = "speedboost"; abilities++; inspectorNum++; UpdateAbilities(); } GetComponent <AudioSource>().clip = pickupSound; GetComponent <AudioSource>().Play(); PassengerObjects[currentPassengers].GetComponent <Image>().sprite = PassengerSprites[3]; //Add passenger data. PassengerInfo.Add(new PedestrianData(other.gameObject.GetComponent <SpriteRenderer>().sprite, "Inspector", currentPassengers)); currentPassengers++; Destroy(other.gameObject); } break; case Role.Officer: if (currentPassengers < maxPassengers) { if (abilities < 4) { shields++; currentAbilities[abilities] = "shield"; abilities++; officerNum++; UpdateAbilities(); } GetComponent <AudioSource>().clip = pickupSound; GetComponent <AudioSource>().Play(); PassengerObjects[currentPassengers].GetComponent <Image>().sprite = PassengerSprites[4]; //Add passenger data. PassengerInfo.Add(new PedestrianData(other.gameObject.GetComponent <SpriteRenderer>().sprite, "Officer", currentPassengers)); currentPassengers++; Destroy(other.gameObject); } break; case Role.Chunky: if (currentPassengers < maxPassengers) { if (!boosting) { maxSpeed = slowedMaxSpeed; acceleration = slowedAcceleration; } GetComponent <AudioSource>().clip = slowSound; GetComponent <AudioSource>().Play(); effectsAnimator.SetTrigger("Chunky"); PassengerObjects[currentPassengers].GetComponent <Image>().sprite = PassengerSprites[2]; //Add passenger data. PassengerInfo.Add(new PedestrianData(other.gameObject.GetComponent <SpriteRenderer>().sprite, "Chunky", currentPassengers)); chunkyNum++; currentPassengers++; Destroy(other.gameObject); } break; } //Strobe capacity panel. if (scoreMultiplier) { for (int i = 0; i < currentPassengers; i++) { PassengerObjects[i].GetComponent <UIColorStrobe>().StartCoroutine("RecursiveColorChange"); } } if (currentPassengers > 0) { PassengerObjects[currentPassengers - 1].GetComponentInChildren <Animator>().SetTrigger("Pulse"); } streetcarAnimator.SetBool("Full", (currentPassengers == maxPassengers)); } //If colliding with a barricade. else if (other.transform.CompareTag("Barricade")) { Camera.main.GetComponent <CameraEffects>().ShakeCamera(0.05f); } }
void SetDestination(GameObject pedestrian) { Pedestrian pedestrianScript = pedestrian.GetComponent <Pedestrian>(); pedestrianScript.SetMoveDelayTime(1f); if (pedestrianScript.GetRole() == Role.Norm) { Vector3 newDestination = (Random.value < 0.5f) ? leftEnd : rightEnd; pedestrianScript.SetDestination(newDestination); pedestrian.transform.SetParent(pedestrianContainer); } else if (pedestrianScript.GetRole() == Role.Coin) { // Either spawn to walk sidewalk or spawn in stop if (Random.value < 0.75) { Vector3 newDestination = (Random.value < 0.5f) ? leftEnd : rightEnd; pedestrianScript.SetDestination(newDestination); pedestrian.transform.SetParent(pedestrianContainer); } else { GameObject streetcarStop; //Find a stop that the streetcar is not currently stopped at. do { streetcarStop = streetcarStops[Random.Range(0, streetcarStops.Length)]; } while(streetcarStop.GetComponent <StreetcarStop>().StreetcarStopped()); pedestrian.transform.SetParent(streetcarStop.transform); Vector3 pedestrianPosition = streetcarStop.transform.position + new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(-0.3f, 0.3f), 0); pedestrian.transform.position = pedestrianPosition; chunkyPercentage *= (streetcarStop.transform.childCount - 1); streetcarStop.GetComponent <StreetcarStop>().UpdateMinimap(); pedestrian.GetComponent <Pedestrian>().CheckIfBusStopPedestrian(); } } else if (pedestrianScript.GetRole() == Role.Inspector || pedestrianScript.GetRole() == Role.Officer || pedestrianScript.GetRole() == Role.Raver) { GameObject streetcarStop; do { streetcarStop = streetcarStops[Random.Range(0, streetcarStops.Length)]; } while(streetcarStop.GetComponent <StreetcarStop>().StreetcarStopped()); // If stop already has role, change new person to a coin if (streetcarStop.GetComponent <StreetcarStop>().HasRole(pedestrianScript.GetRole())) { pedestrianScript.SetRole(Role.Coin); pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = pedestrianSprites [Random.Range(0, pedestrianSprites.Length)]; } pedestrian.transform.SetParent(streetcarStop.transform); Vector3 pedestrianPosition = streetcarStop.transform.position + new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(-0.5f, 0.5f), 0); pedestrian.transform.position = pedestrianPosition; streetcarStop.GetComponent <StreetcarStop>().UpdateMinimap(); } else { Vector3 newDestination = new Vector3(pedestrian.transform.position.x, opposingSpawnerTransform.position.y, 0); pedestrianScript.SetDestination(newDestination); pedestrian.transform.SetParent(pedestrianContainer); } }