void _makeInstance() { if (instance != null) { instance = this; } }
// Update is called once per frame void Update() { if (Time.time > Timer) { int choice = Random.Range(0, 3); switch (choice) { case 0: Ball basic = new BasicBall(basic_ball); balls.Add(basic.Obj, basic); break; case 1: Ball bouncy = new BouncyBall(bouncy_ball); balls.Add(bouncy.Obj, bouncy); break; case 2: Ball explosive = new ExplosiveBall(explosive_ball); balls.Add(explosive.Obj, explosive); break; } Timer = Time.time + Random.Range(2f, 4f); } }
public void BouncyBallTest() { var b = new BouncyBall(BouncyBall.PathsByPathPrefixing); Assert.AreEqual(b.bouncyBall(10, 1), 10); Assert.AreEqual(b.bouncyBall(10, 10), 1); Assert.AreEqual(b.bouncyBall(10, 3), 4); Assert.AreEqual(b.bouncyBall(10, 0), 42); Assert.AreEqual(b.bouncyBall(36, 2), 239); Assert.AreEqual(b.bouncyBall(120, 0), 1844349560); }
public override void Wipe() { closest = null; pickupCount = 0; ballCount = 0; if (Random.value - corruption > 0) { actionEnabled = false; } }
void _makeInstance() { instance = this; }
void OnTriggerEnter(Collider other) { if (exploding) { return; } if (other.gameObject.CompareTag("Pickup")) { Pickup pickup = other.gameObject.GetComponent <Pickup>(); if (pickup.isActive && pickup.isLive) { // Score points! Game.UpdateScore(pickup.baseScore * scoreModifier); actionEnabled = true; corruption += 0.01f; pickupCount++; ballCount = 0; if ((type == BallType.DarkStar && pickup.type == PickupType.Black) || (type == BallType.Moon && pickup.type == PickupType.Silver)) { if (other.transform.localScale.x < 6f) { other.transform.localScale *= 1.2f; pickup.rotationSpeed *= 0.8f; } } else { // Explode if embiggened or return object to pool if (pickup.transform.localScale.x > 1f) { pickup.Explode(); } else { pickup.Score(); pickup.isLive = false; pickup.RemoveIn(0.3f); } } } if (type != BallType.Basic) { Shrink(); } } if (other.gameObject.CompareTag("Ball")) { BouncyBall ball = other.gameObject.GetComponent <BouncyBall>(); if (!ball.exploding && transform.localScale.x <= 2f) { corruption += 0.01f; actionEnabled = true; ballCount++; float velocity = Mathf.Abs(other.attachedRigidbody.velocity.x + other.attachedRigidbody.velocity.y + other.attachedRigidbody.velocity.z); float scaleRatio = ball.transform.localScale.x - transform.localScale.x; if (scaleRatio > 0 && UnityEngine.Random.value < scaleRatio) { ball.Grow(velocity); ball.SpawnValue = ball.SpawnValue + SpawnValue; // Return to pool exploding = true; StartCoroutine(Wait(0.1f, () => { if (isActive) { ReturnToPool(); } })); } } } }
void Split(float velocity) { Column column = World.GetColumn(World.GetChunkPosition(transform.position)); if (column != null) { Spawns spawn; //Color spawnColor = hsvColor.ToColor(); Vector3 scale = transform.localScale * 0.5f; float newSpawnValue = SpawnValue * 0.25f; int splits = 1; if (velocity > 20f) { splits = 2; } else if (velocity > 30f) { splits = 3; } else if (velocity > 50f) { splits = 4; } else if (velocity > 80f) { splits = 5; } if (type == BallType.Imploding) { spawn = Spawns.MysteryEgg; } else if (type == BallType.Exploding) { spawn = Spawns.SuperBouncyBall; } else if (type == BallType.Moon) { spawn = Spawns.Moon; } else if (type == BallType.DarkStar) { spawn = Spawns.DarkStar; } else { spawn = Spawns.BouncyBall; scale = transform.localScale; newSpawnValue = 1f; splits *= 3; } List <ProceduralToolkit.ColorHSV> newColors = hsvColor.GetAnalogousPalette(splits); int count = 0; StartCoroutine(RepeatThen(splits, 0.1f, () => { PooledObject obj = World.Spawn.Object(spawn, newColors[count].ToColor(), mass, transform.position, Mathf.Lerp(0f, corruption, Random.value)); count++; if (obj != null) { obj.transform.localScale = scale; BouncyBall ball = obj.GetComponent <BouncyBall>(); // Prevent moon explosions if (ball.type == BallType.Moon) { ball.growthRate = 1.05f; } ball.Activate(0.5f); ball.SpawnValue = newSpawnValue; column.spawns.Add(obj); } }, () => { Explode(); })); } }
void HandleBalls() { if (SpawnManager.Balls.Count == 0) { return; } // find a ball Vector3 d = Vector3.zero; float distance = Mathf.Infinity; BouncyBall ball = null; if (bix <= 0 || bix > SpawnManager.Balls.Count - 1) { bix = SpawnManager.Balls.Count - 1; } for (; bix >= 0; bix--) { ball = SpawnManager.Balls[bix]; if (!ball.inRange) { continue; } if (ball == null || !ball.isActive) { SpawnManager.Balls.Remove(ball); } else { break; } } if (ball == null) { return; } // find closest ball to this ball for (int i = SpawnManager.Balls.Count - 1; i >= 0; i--) { if (i == bix) { continue; } BouncyBall b = SpawnManager.Balls[i]; if (!b.inRange) { continue; } if (b == null || !b.isActive) { SpawnManager.Balls.Remove(b); } if (distance > 4f) { d = b.transform.position - ball.transform.position; if (d.sqrMagnitude < distance) { ball.closest = b; distance = d.sqrMagnitude; } } } bix--; }
SpawnedObject SpawnBall(PooledObject prefab, Color color, int key, float corruption) { BouncyBall ball = prefab.GetPooledInstance <BouncyBall>(); if (ball == null && SleptBalls.Count > 0) { BouncyBall sleeper = SleptBalls[0]; SleptBalls.RemoveAt(0); if (sleeper != null) { sleeper.ReturnToPool(); Balls.Remove(sleeper); ball = prefab.GetPooledInstance <BouncyBall>(); } } if (ball == null) { return(null); } ball.exploding = false; ball.inRange = true; ball.hasAction = true; ball.type = ((BouncyBall)prefab).type; ball.hsvColor = new ColorHSV(color); Balls.Add(ball); if (ball.type == BallType.Basic) { ball.color = color; ball.size = 0.95f; ball.scoreModifier = 1; ball.growthRate = 0; ball.shrinkRate = 0; ball.massIncrease = 0; ball.massDecrease = 0; ball.maxSize = 0.95f; ball.minSize = 0.95f; ball.explodeAtMax = false; ball.explodeAtMin = false; if (corruption > 0.1f) { ball.emission = Tile.Brighten(color, 1f); } int note = Mathf.FloorToInt(Mathf.Lerp(0f, 6.999f, ball.hsvColor.h)); int note2 = Mathf.FloorToInt(Mathf.Lerp(0f, 23.999f, ball.hsvColor.h)); var playSound = ball.GetComponent <PlayHitSound>(); playSound.worldHitSound = selfBallOctave[(int)scales[key][note]]; playSound.objectHitSound = ballOctave[(int)scales[key][note2] + 11]; } if (ball.type == BallType.Imploding) { ball.color = color; ball.size = 3f; ball.scoreModifier = 10; ball.growthRate = 1.1f; ball.shrinkRate = 0.8f; ball.massIncrease = 1.1f; ball.massDecrease = 0.98f; ball.maxSize = 6f; ball.minSize = 0.85f; ball.explodeAtMax = false; ball.explodeAtMin = true; ball.SpawnObject = Spawns.BlackPickup; ball.SpawnIncrement = 1f; ball.SpawnValue = 4f; int note = Mathf.FloorToInt(Mathf.Lerp(0f, 6.999f, ball.hsvColor.h)); var playSound = ball.GetComponent <PlayHitSound>(); playSound.worldHitSound = selfBallOctave[(int)scales[key][note]]; playSound.objectHitSound = largeDarkOctave[(int)scales[key][note]]; } if (ball.type == BallType.Exploding) { ball.color = color; ball.size = 4f; ball.scoreModifier = 5; ball.growthRate = 1.25f; ball.shrinkRate = 0.95f; ball.massIncrease = 1.01f; ball.massDecrease = 0.98f; ball.maxSize = 14f; ball.minSize = 1.6f; ball.explodeAtMax = true; ball.explodeAtMin = false; ball.SpawnObject = Spawns.SilverPickup; ball.SpawnIncrement = 1f; ball.SpawnValue = 4f; int note = Mathf.FloorToInt(Mathf.Lerp(0f, 6.999f, ball.hsvColor.h)); var playSound = ball.GetComponent <PlayHitSound>(); playSound.worldHitSound = selfHits[(int)scales[key][note] + 11]; playSound.objectHitSound = ballOctave[(int)scales[key][note] + 47]; } if (ball.type == BallType.Moon) { ball.color = Color.white; ball.size = 7f; ball.scoreModifier = 2; ball.growthRate = 1.2f; ball.shrinkRate = 0.9f; ball.massIncrease = 1.01f; ball.massDecrease = 1.02f; ball.maxSize = 14f; ball.minSize = 2f; ball.explodeAtMax = true; ball.explodeAtMin = true; ball.SpawnObject = Spawns.BouncyBall; ball.SpawnIncrement = 2f; ball.SpawnValue = 10f; int note = Mathf.FloorToInt(Mathf.Lerp(0f, 6.999f, ball.hsvColor.h)); var playSound = ball.GetComponent <PlayHitSound>(); playSound.worldHitSound = selfHits[(int)scales[key][note] + 23]; playSound.objectHitSound = moonOctave[(int)scales[key][note]]; ball.emission = Color.white; } if (ball.type == BallType.DarkStar) { ball.color = Color.black; ball.size = 7f; ball.scoreModifier = 4; ball.growthRate = 1.1f; ball.shrinkRate = 0.85f; ball.massIncrease = 1.1f; ball.massDecrease = 1.01f; //! ball.maxSize = 14f; ball.minSize = 2f; ball.explodeAtMax = true; ball.explodeAtMin = true; ball.SpawnObject = Spawns.BouncyBall; ball.SpawnIncrement = 2f; ball.SpawnValue = 10f; int note = Mathf.FloorToInt(Mathf.Lerp(0f, 6.999f, ball.hsvColor.h)); var playSound = ball.GetComponent <PlayHitSound>(); playSound.worldHitSound = selfHits[(int)scales[key][note]]; playSound.objectHitSound = darkStarOctave[(int)scales[key][note]]; ball.emission = Color.black; } return((SpawnedObject)ball); }