void sprayES() { for (int touch = 0; touch < Input.touchCount; touch++) { if (Input.GetTouch(touch).phase == TouchPhase.Began) { Vector2 touchPosition = Input.GetTouch(touch).position; Vector3 point = Camera.main.ScreenToWorldPoint(touchPosition); Color color = getRandomColor(); for (int i = 0; i < 360; i += 360 / totES) { EnergyShape es = createES(point); es.destination = getPosition(point, i, maxDistance); es.color = color; es.timeToCenter = speed; es.rigidbody.isKinematic = true; es.Prepare(); } social.checkSprayCount(++sprayCount); } } }
EnergyShape[] parallel(int burst = 1) { EnergyShape[] list = new EnergyShape[2 * burst]; float angle1 = getRandomAngle(); float angle2 = angle1 + 3f; Color color = getRandomColor(); Vector2 pos1 = getPosition(angle1); Vector2 pos2 = getPosition(angle2); Vector2 offset = pos1 - getPosition((angle1 + angle2) / 2); Vector2 offset2 = pos2 - getPosition((angle1 + angle2) / 2); for (int i = 0, j = 0; i < burst; i++, j += 2) { EnergyShape es = createES(pos1); es.color = color; es.destination = offset; es.sleepTime = i * burstOffset; EnergyShape es2 = createES(pos2); es2.color = color; es2.destination = offset2; es2.sleepTime = i * burstOffset; list[j] = es; list[j + 1] = es2; } return(list); }
EnergyShape[] perpendicular(int burst = 1) { EnergyShape[] list = new EnergyShape[(int)manager.currentShape * burst]; float start = getRandomAngle(); float offset = 360 / (int)manager.currentShape; for (int i = 0; i < burst; i++) { for (int j = 0; j < (int)manager.currentShape; j++) { float angle = start - offset * j; if (angle < 0) { angle += 360f; } EnergyShape es = createES(getPosition(angle)); es.color = CustomColor.List[j]; es.sleepTime = i * burstOffset; list[i * (int)manager.currentShape + j] = es; } } return(list); }
void spawn(ESInfo info) { EnergyShape[] esList = null; //posizionamento switch (info.positioning) { case Positioning.Standard: esList = standard(info.count); break; case Positioning.Parallel: esList = parallel(info.count); break; case Positioning.Perpendicular: esList = perpendicular(info.count); break; } //comportamento for (int i = 0; i < esList.Length; i++) { EnergyShape es = esList[i]; es.moveType = info.movetype; es.timeToCenter = info.timeToCenter; es.isFast = info.timeToCenter == timeToCenter.fast ? true : false; es.spiralAngularSpeed = es.spiralAngularSpeed * info.verse; // verse è 1 o -1 quindi determina il verso di rotazione es.Prepare(); //reinizializza l'ES nel caso sia stata riutilizzata dal pool } }
public void damage(EnergyShape es) { stopCombo(); if (godMode) { return; } healthPoints--; }
IEnumerator explosionEffect() { //effetto esplosione che spazza via tutte le es Collider[] colliders = Physics.OverlapSphere(explosion.position, explosion.radius); for (int i = 0; i < colliders.Length; i++) { Collider hit = colliders[i]; if (!hit) { continue; } EnergyShape es = hit.GetComponent <EnergyShape>(); if (!es) { continue; } es.stop = true; hit.rigidbody.AddExplosionForce(explosion.power, explosion.position, explosion.radius); } GameObject explosionObj = ObjectPool.Instance.GetObjectForType("EvoExplosionEffect", true); explosionObj.particleSystem.startColor = CustomColor.List[(int)currentShape - 1]; yield return(new WaitForSeconds(explosionObj.particleSystem.duration)); for (int i = 0; i < colliders.Length; i++) { Collider hit = colliders[i]; if (!hit) { continue; } EnergyShape es = hit.GetComponent <EnergyShape>(); if (!es) { continue; } ObjectPool.Instance.PoolObject(hit.gameObject); } ObjectPool.Instance.PoolObject(explosionObj); }
EnergyShape[] standard(int burst = 1) { EnergyShape[] list = new EnergyShape[burst]; float angle = getRandomAngle(); Color color = getRandomColor(); for (int i = 0; i < burst; i++) { EnergyShape es = createES(getPosition(angle)); es.color = color; es.sleepTime = i * burstOffset; list[i] = es; } return(list); }
public void increase(EnergyShape es) { if (endGame) { return; } // COMBO POINTS comboPoints++; if (comboPoints == combo.x2) { comboMultiplier = 2; totalCombo++; } if (comboPoints == combo.x3) { comboMultiplier = 3; } if (comboPoints == combo.x4) { comboMultiplier = 4; } if (comboPoints >= combo.x5) { comboMultiplier = 5; } // EVOLUTION POINTS evolutionPoints++; if (evolutionPoints > getEvolvingRequirements(lastShape)) { evolutionPoints = getEvolvingRequirements(lastShape); } // SCORE POINTS scorePoints += (int)currentShape * (int)es.moveSpeed * comboMultiplier; social.checkCombo(comboMultiplier); social.checkCatchedES(); updateHUD = true; }
void sprayES() { if (Input.GetMouseButtonDown(0)) { Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition); Color color = getRandomColor(); for (int i = 0; i < 360; i += 360 / totES) { EnergyShape es = createES(point); es.destination = getPosition(point, i, maxDistance); es.color = color; es.timeToCenter = speed; es.rigidbody.isKinematic = true; } social.checkSprayCount(++sprayCount); } }
EnergyShape createES(Vector2 position) { GameObject bulletObj = ObjectPool.Instance.GetObjectForType("EnergyShape", false); bulletObj.transform.position = position; bulletObj.transform.rotation = Quaternion.identity; if (manager.endGame) { Destroy(bulletObj, timeToCenter.normal * 2); //alla fine del gioco autodistruggo le es dopo 20 secondi per non sovraccaricare la memoria } else { manager.totalESSpawned++; // for every ES created, not just every spawn procedure executed (can spawn multiple ES at a time) } EnergyShape es = bulletObj.GetComponent <EnergyShape>(); es.Initialize(); //rinizializzo l'es per quando viene ripescata dal pool return(es); }
void OnCollisionEnter(Collision collision) { //se non è un es oppure è in atto l'animazione dell'evoluzione ignoro le collisioni if (collision.gameObject.layer != esLayer || manager.isEvolving) { Destroy(collision.gameObject); return; } bool ok = false; ContactPoint point = collision.contacts[0]; EnergyShape es = collision.gameObject.GetComponent <EnergyShape>(); switch (point.thisCollider.name) { case "Red": if (es.color == CustomColor.Red) { ok = true; } break; case "Green": if (es.color == CustomColor.Green) { ok = true; } break; case "Blue": if (es.color == CustomColor.Blue) { ok = true; } break; case "Yellow": if (es.color == CustomColor.Yellow) { ok = true; } break; case "Orange": if (es.color == CustomColor.Orange) { ok = true; } break; case "Cyan": if (es.color == CustomColor.Cyan) { ok = true; } break; case "Pink": if (es.color == CustomColor.Pink) { ok = true; } break; case "Violet": if (es.color == CustomColor.Violet) { ok = true; } break; } if (ok) { manager.increase(es); manager.totalESCatched++; audio.PlayOneShot(good); StartCoroutine(esExplosionEffect(es.color, point, collision)); } else { manager.damage(es); manager.totalESMissed++; audio.PlayOneShot(wrong); #if !UNITY_STANDALONE Handheld.Vibrate(); #endif if (!animation.isPlaying) { animation.Play("Vibrate"); } } ObjectPool.Instance.PoolObject(collision.gameObject); }