private void GenerateLine(float x, float z, int length, float spacing) { Vector2 direction = new Vector2(x, z) - scrLandscape.Instance.GetCentre(); direction.Normalize(); float bend = Random.Range(-0.2f, 0.2f); // Amount the direction bends per orb. // Make sure it is possible to produce the length of string required. if (length > pool.Remaining) { // There aren't enough orbs available for a string, so cease creation. if (pool.Remaining < LENGTH_MIN) { return; } length = pool.Remaining; } Vector2 position = new Vector2(x, z); scrLightOrb previous = null; for (int i = 0; i < length; ++i) { // Create an orb. scrLightOrb current = (scrLightOrb)pool.Create(position.x, position.y, i, length); // Link the orb to the previous orb. current.SetInitialLink(previous); // Prepare for the next orb. previous = current; // Move to the next position. position += direction * spacing; // Bend in the direction perpendicular to the current direction. Vector2 perp = new Vector2(-direction.y, direction.x); direction += perp * bend; direction.Normalize(); } }
// ---- scrGenerator ---- protected override void Generate() { if (PlayerController.Instance.LightScore == 0) { return; // Do not generate if player has no light. } // Check for a free position. Vector2 position; if (GetFreePosition(out position)) { // Choose an powerup to generate. scrPowerup.Powerup effect = (scrPowerup.Powerup)Random.Range(0, 4); // Generate the powerup. scrPoolable powerup = pool.Create(position.x, position.y, effect); } distanceRequired = Mathf.Max(DISTANCE_MAX - DISTANCE_REDUCTION_PER_LIGHT * PlayerController.Instance.LightScore, DISTANCE_MIN); // Reduce the distance required by the amount of light the player has. }