using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using UnityEngine; public class Upgrade { public string name = "MT"; public int amount = 0; public Upgrade(string n) { name = n; } } public class Upgrades { public Upgrade mopUpgrade = new Upgrade("Mop Radius"); public Upgrade speedUpgrade = new Upgrade("Move speed"); public Upgrade ropeUpgrade = new Upgrade("Longer Rope"); public Upgrade healthUpgrade = new Upgrade("More health"); public Upgrade damageUpgrade = new Upgrade("More rope damage"); public Upgrade bloodUpgrade = new Upgrade("MORE BLOOD!"); public Upgrade reelUpgrade = new Upgrade("Faster rope reel speed"); } public class Upgrader : MonoBehaviour { public GameObject player1; public GameObject player2; public BloodComputeShader bloodManager; public RopeSimulator rope; public Upgrades upgrades { get; private set; } public float mopSizeIncrease = 1.1f; public float speedIncrease = 1.1f; public float ropeIncrease = 1.1f; public float healthIncrease = 1.1f; public float damageIncrease = 1.1f; public float bloodIncrease = 1.1f; public float reelIncrease = 1.1f; public int upgradeCost = 10000; private RectTransform Player1Cursor; private RectTransform Player2Cursor; private PlayerInput Player1Input; private PlayerInput Player2Input; private float acceptTime = 0f; private Image background; private Image[] upgradeImages = new Image[8]; // Start is called before the first frame update void Start() { Player1Cursor = transform.Find("Player1 Cursor").GetComponent(); Player2Cursor = transform.Find("Player2 Cursor").GetComponent(); Player1Input = player1.GetComponent(); Player2Input = player2.GetComponent(); background = GetComponent(); int idx = 0; foreach (Image i in GetComponentsInChildren()) { if (i.gameObject.name.StartsWith("Upgrade")) upgradeImages[idx++] = i; } // Debug.Log("Found " + idx + " upgrades"); upgrades = new Upgrades(); } bool canUpgrade() { // return bloodManager.score >= upgradeCost; return true; } int getRegion(float x, float y, int regions) { if (x + y == 0) return -1; float angle = Mathf.Atan2(x, -y) + Mathf.PI; float regionSize = (Mathf.PI * 2.0f) / ((float)regions); int region = (int)((((Mathf.PI * 2.0f) - angle) / regionSize) + 0.5f); if (region > regions - 1) return 0; return region; } // Update is called once per frame void Update() { if (canUpgrade()) { int p1a = getRegion(Player1Input.look.x, Player1Input.look.y, 8); int p2a = getRegion(Player2Input.look.x, Player2Input.look.y, 8); Debug.Log(p1a); if (p1a != -1 && p2a == p1a) { if (acceptTime > 2f) { switch (p1a) { case 0: UpgradeMopSize(); break; case 1: UpgradeSpeed(); break; case 2: RopeUpgrade(); break; case 3: HealthUpgrade(); break; case 4: DamageUpgrade(); break; case 5: BloodUpgrade(); break; case 6: ReelUpgrade(); break; case 7: break; } bloodManager.score -= upgradeCost; acceptTime = 0f; } else { acceptTime += Time.deltaTime; foreach (Image i in upgradeImages) { i.fillAmount = 1f; } upgradeImages[p1a].fillAmount = acceptTime / 2f; } } else { if (acceptTime > 0f) { foreach (Image i in upgradeImages) { i.fillAmount = 1f; } } acceptTime = 0f; // background.fillAmount = 0f; } } Player1Cursor.localPosition = Player1Input.look.normalized * (125 - 12); Player2Cursor.localPosition = Player2Input.look.normalized * (125 - 12); } /// Increases mop radius by 10% public void UpgradeMopSize() { bloodManager.CleanRadius *= mopSizeIncrease; upgrades.mopUpgrade.amount++; } /// Increases move speed by 10% public void UpgradeSpeed() { player1.GetComponent().moveSpeed *= speedIncrease; player2.GetComponent().moveSpeed *= speedIncrease; upgrades.speedUpgrade.amount++; } public void RopeUpgrade() { // todo: public methods rope.ropeMaxLength *= ropeIncrease; upgrades.ropeUpgrade.amount++; } public void HealthUpgrade() { var comp1 = player1.GetComponent(); comp1.setMaxHealth((int)(comp1.getMaxHealth() * healthIncrease)); var comp2 = player2.GetComponent(); comp2.setMaxHealth((int)(comp2.getMaxHealth() * healthIncrease)); upgrades.healthUpgrade.amount++; } public void DamageUpgrade() { // todo: public rope methods // rope.da upgrades.damageUpgrade.amount++; } public void BloodUpgrade() { bloodManager.scoreMult *= bloodIncrease; upgrades.bloodUpgrade.amount++; } public void ReelUpgrade() { // todo rope methods rope.ropeExtendSpeed *= reelIncrease; upgrades.reelUpgrade.amount++; } }