Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- All classes of "Pandemic JAM Simulator". Sorry for the quick and dirty code. Doubts: joseamoyano@gmail.com
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class AuxiliarButton : MonoBehaviour
- {
- public void ExitApp()
- {
- Application.Quit();
- }
- public void Restart()
- {
- SceneManager.LoadScene(0);
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CheckRole : MonoBehaviour
- {
- [SerializeField]
- Sprite citizen, cured, dead, infected, police, sanitary;
- SpriteRenderer spriteRenderer;
- RegularMovement regularMovement;
- private void Awake()
- {
- spriteRenderer = GetComponent<SpriteRenderer>();
- regularMovement = GetComponent<RegularMovement>();
- }
- private void Start()
- {
- regularMovement.StateInString();
- //ChangeState(regularMovement.stateInString);
- }
- public void InitialStates(string state)
- {
- if (state == "police")
- {
- spriteRenderer.sprite = police;
- }
- else if (state == "sanitary")
- {
- spriteRenderer.sprite = sanitary;
- }
- else if (state == "infected")
- {
- spriteRenderer.sprite = infected;
- }
- }
- public void ChangeState(string state)
- {
- if(state == "cured")
- {
- spriteRenderer.sprite = cured;
- }
- else if(state == "infected")
- {
- spriteRenderer.sprite = infected;
- }
- else if(state == "dead")
- {
- spriteRenderer.sprite = dead;
- }
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Diseable : MonoBehaviour
- {
- public int count;
- RegularMovement regularMovement;
- private void Awake()
- {
- regularMovement = GetComponent<RegularMovement>();
- }
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (regularMovement.isInfected)
- {
- count++;
- if (count >= 2000)
- {
- int temp = Random.Range(0, 100);
- if (temp >= 0 && temp <= 10)
- {
- regularMovement.Die();
- }
- else
- {
- //gameObject.GetComponent<RegularMovement>().isInfected = false;
- gameObject.GetComponent<RegularMovement>().isCured = true;
- gameObject.GetComponent<CheckRole>().ChangeState("cured");
- }
- gameObject.GetComponent<RegularMovement>().isInfected = false;
- }
- }
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class GenerateCitizen : MonoBehaviour
- {
- public int totalNumberCitizen;
- public GameObject citizen, infected, police, sanitary;
- public List<GameObject> citizenList;
- public int numberOfPolice;
- public int numberOfSanitary;
- public int numberOfEducation;
- [SerializeField]
- Slider slider;
- [SerializeField]
- Text text;
- [SerializeField]
- GameObject button1, button2, button3, button4, slider1, text1,text4;
- [SerializeField]
- Text textButton1, textButton2, textButton3;
- void CreateCitizen()
- {
- for (int i = 0; i <= numberOfPolice; i++)
- citizenList.Add(police);
- for (int i = 0; i <= numberOfSanitary; i++)
- citizenList.Add(sanitary);
- for (int i = 0; i <= totalNumberCitizen; i++)
- citizenList.Add(citizen);
- citizenList.Add(infected);
- for (int i = 0; i < citizenList.Count; i++)
- {
- GameObject temp = Instantiate(citizenList[i], new Vector2(Random.Range(-8, 8), Random.Range(5.5f, -3.5f)), Quaternion.identity);
- if(!temp.GetComponent<RegularMovement>().isPolice && !temp.GetComponent<RegularMovement>().isSanitary && numberOfEducation>0)
- {
- numberOfEducation--;
- temp.GetComponent<RegularMovement>().isResponsable = true;
- }
- }
- }
- public void AddPolices()
- {
- numberOfPolice++;
- textButton1.text = numberOfPolice.ToString();
- }
- public void AddSanitaries()
- {
- numberOfSanitary++;
- textButton2.text = numberOfSanitary.ToString();
- }
- public void AddEducation()
- {
- numberOfEducation++;
- textButton3.text = numberOfEducation.ToString();
- }
- public void AddCitizen()
- {
- totalNumberCitizen = (int)slider.value;
- text.text = "Citizens = " + (int)slider.value;
- }
- public void StartSimulation()
- {
- CreateCitizen();
- button1.SetActive(false);
- button2.SetActive(false);
- button3.SetActive(false);
- button4.SetActive(false);
- slider1.SetActive(false);
- text1.SetActive(false);
- text4.SetActive(false);
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class RegularMovement : MonoBehaviour
- {
- [SerializeField]
- Rigidbody2D rb2d;
- [SerializeField]
- Vector2 regularVelocity;
- public bool isInfected, isResponsable, isDead, isPolice, isSanitary, isCured;
- public string stateInString;
- [SerializeField]
- Collider2D coll2D;
- [SerializeField]
- float magnitudV;
- MonoBehaviour policeBehaviour, sanitarBehaviour;
- CheckRole checkRole;
- private void Awake()
- {
- checkRole = GetComponent<CheckRole>();
- }
- // Start is called before the first frame update
- void Start()
- {
- BeginMovement();
- StateInString();
- }
- public void StateInString()
- {
- if (isInfected)
- stateInString = "infected";
- else if(isPolice)
- stateInString = "police";
- else if (isPolice)
- stateInString = "sanitary";
- checkRole.InitialStates(stateInString);
- }
- // Update is called once per frame
- void Update()
- {
- if (!isResponsable && !isDead && rb2d.velocity.magnitude < 0.5f)
- BeginMovement();
- magnitudV = rb2d.velocity.magnitude;
- if (isResponsable)
- rb2d.velocity = Vector2.zero;
- }
- void BeginMovement()
- {
- if (!isResponsable)
- {
- regularVelocity = new Vector2(Random.Range(-3, 3), Random.Range(-3, 3)).normalized;
- rb2d.velocity = regularVelocity;
- }
- else
- {
- rb2d.velocity = Vector2.zero;
- }
- }
- private void OnCollisionEnter2D(Collision2D collision)
- {
- if (!isResponsable)
- {
- if (collision.gameObject.layer == 8)
- {
- regularVelocity *= new Vector2(-1, 1)/*.normalized*/;
- rb2d.velocity = regularVelocity;
- }
- else if (collision.gameObject.layer == 9)
- {
- regularVelocity *= new Vector2(1, -1)/*.normalized*/;
- rb2d.velocity = regularVelocity;
- }
- else if (collision.gameObject.layer == 10)
- {
- rb2d.velocity *= new Vector2(-1, -1);
- CheckIfIsSpecialCitizen(collision);
- }
- }
- else
- {
- rb2d.velocity = Vector2.zero;
- }
- }
- void CheckIfIsSpecialCitizen(Collision2D collision)
- {
- GameObject tempCitizen = collision.gameObject;
- if (!tempCitizen.GetComponent<RegularMovement>().isPolice && !tempCitizen.GetComponent<RegularMovement>().isSanitary)
- {
- if (isPolice)
- {
- tempCitizen.GetComponent<RegularMovement>().isResponsable = true;
- rb2d.velocity = Vector2.zero;
- }
- else if (isSanitary && tempCitizen.GetComponent<RegularMovement>().isInfected)
- {
- tempCitizen.GetComponent<RegularMovement>().isInfected = false;
- tempCitizen.GetComponent<RegularMovement>().isCured = true;
- tempCitizen.GetComponent<CheckRole>().ChangeState("cured");
- }
- }
- if (isInfected && !tempCitizen.GetComponent<RegularMovement>().isPolice && !tempCitizen.GetComponent<RegularMovement>().isSanitary)
- {
- tempCitizen.GetComponent<RegularMovement>().isInfected = true;
- tempCitizen.GetComponent<CheckRole>().ChangeState("infected");
- }
- }
- public void Die()
- {
- isDead = true;
- gameObject.GetComponent<CheckRole>().ChangeState("dead");
- rb2d.velocity = Vector2.zero;
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Walls : MonoBehaviour
- {
- [SerializeField]
- GameObject rightWall, leftWall, upWall, downWall;
- // Start is called before the first frame update
- void Start()
- {
- GenerateCollidersAcrossScreen();
- }
- void GenerateCollidersAcrossScreen()
- {
- Vector3 ScreenSize = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0));
- leftWall.transform.position = new Vector3(-ScreenSize.x - 0.25f, 0, leftWall.transform.position.z);
- rightWall.transform.position = new Vector3(ScreenSize.x + 0.25f, 0, rightWall.transform.position.z);
- upWall.transform.position = new Vector3(0, ScreenSize.y + 0.25f, upWall.transform.position.z);
- downWall.transform.position = new Vector3(0, -ScreenSize.y + 1.75f, downWall.transform.position.z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement