Near finish

This commit is contained in:
2023-07-30 23:14:41 +05:30
parent 1569760e7b
commit 400336ef4f
1979 changed files with 1696464 additions and 301 deletions

View File

@@ -5,6 +5,11 @@ using UnityEngine.U2D;
public class LevelGeneratorV2 : MonoBehaviour
{
public static LevelGeneratorV2 instance;
void Awake(){
instance= this;
}
public LineRenderer debugLine;
[SerializeField]public Range amplitude = new Range(1,2);
[SerializeField]public Range distance = new Range(2,5);
@@ -19,6 +24,7 @@ public class LevelGeneratorV2 : MonoBehaviour
public float tangentSmoothness = 1.5f;
float space =0;
float spaceBot =0;
[Header("Asteroids")]
public float asteroidGenerationHeightThreshold =6;
@@ -28,10 +34,15 @@ public class LevelGeneratorV2 : MonoBehaviour
public Range asteroidTorque = new Range(0.1f,0.5f);
public Range asteroidsPerBlock = new Range(4,8);
[Header("PowerUps")]
public GameObject powerupPrefabs;
public float powerupDistanceInterval = 500;
// Start is called before the first frame update
void Start()
{
lastPowerupX = powerupDistanceInterval;
Application.targetFrameRate = 60;
// #if UNITY_EDITOR
// debugLine.gameObject.SetActive(true);
@@ -57,10 +68,12 @@ public class LevelGeneratorV2 : MonoBehaviour
List<Vector3> points = new List<Vector3>();
float a;
public float heightSmoothness = 0.1f;
float lastPowerupX;
void GenerateNext(int amount = 50){
Range height = heights[Random.Range(0,heights.Length)];
Debug.Log(height);
if(space <= 0){space = height.GetRandom();}
if(spaceBot <= 0){spaceBot = height.GetRandom();}
space = Mathf.Lerp(space, height.GetRandom(), heightSmoothness);
if(points.Count <= 0){points.Add(new Vector3(0,0));}
@@ -85,6 +98,12 @@ public class LevelGeneratorV2 : MonoBehaviour
rb.transform.localScale = rb.transform.localScale * asteroidScale.GetRandom();
asteroids++;
}
if(lastPowerupX < x){
lastPowerupX += powerupDistanceInterval;
borrowedPickups.Add(ObjectPool.Spawn(powerupPrefabs, new Vector3(x,y)));
}
}
@@ -108,6 +127,7 @@ public class LevelGeneratorV2 : MonoBehaviour
//Top Terrain
SpriteShapeController top_controller = pooled[0];
spaceBot = Mathf.Lerp(spaceBot, height.GetRandom(), heightSmoothness);
borrowed.Add(pooled[0]);
pooled.RemoveAt(0);
@@ -115,18 +135,19 @@ public class LevelGeneratorV2 : MonoBehaviour
top_controller.spline.Clear();
InsertNewPoint(top_controller, points[startIndex]+ new Vector3(0, 50));
for(int i=startIndex; i < points.Count; i++){
InsertNewPoint(top_controller, points[i] + new Vector3(0, space));
InsertNewPoint(top_controller, points[i] + new Vector3(0, spaceBot));
}
InsertNewPoint(top_controller, points[points.Count-1] + new Vector3(0,50));
top_controller.GetComponent<PolygonCollider2D>().enabled=true;
top_controller.transform.position = Vector3.zero;
top_controller.gameObject.SetActive(false);
top_controller.gameObject.SetActive(true);
Debug.Log(space+ ", " + spaceBot);
UpdateLine();
}
public List<GameObject> borrowedAsteroids = new List<GameObject>();
public List<GameObject> borrowedPickups = new List<GameObject>();
void CleanupBorrowed(){
for(int i= borrowed.Count-1; i > 0; i--){
if(borrowed[i].spline.GetPosition(borrowed[i].spline.GetPointCount()-1).x < PlayerController.position.x -30){
@@ -141,6 +162,22 @@ public class LevelGeneratorV2 : MonoBehaviour
borrowedAsteroids.RemoveAt(i);
}
}
for(int i=borrowedPickups.Count-1; i> 0; i--){
if(borrowedPickups[i].transform.position.x + 20 < PlayerController.position.x){
ObjectPool.Despawn(borrowedPickups[i]);
borrowedPickups.RemoveAt(i);
}
}
}
public void DespawnPickup(GameObject obj){
ObjectPool.Despawn(obj);
borrowedPickups.Remove(obj);
}
public void DespawnAsteroid(GameObject obj){
ObjectPool.Despawn(obj);
borrowedAsteroids.Remove(obj);
}
void UpdateLine(){