68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.U2D;
|
|
|
|
public class LevelGenerator : MonoBehaviour
|
|
{
|
|
public static LevelGenerator instance { get; private set; }
|
|
public SpriteShapeController spriteShapeController;
|
|
public int LevelCount = 1000;
|
|
public float groundLevel = -5.5f;
|
|
public float maxHeight = 5;
|
|
public Vector2 minDiff, maxDiff;
|
|
public Vector3[] points {get; private set;}
|
|
|
|
public int GoalDistance= 10;
|
|
void Start()
|
|
{
|
|
spriteShapeController.spline.Clear();
|
|
|
|
points = new Vector3[LevelCount+1];
|
|
for(int i=0; i < LevelCount; i++){
|
|
if(i ==0){
|
|
points[i] = new Vector3(0,groundLevel);
|
|
spriteShapeController.spline.InsertPointAt(i, points[i]);
|
|
continue;
|
|
}
|
|
|
|
Vector3 addition = new Vector3(Random.Range(minDiff.x, maxDiff.x), Random.Range(minDiff.y, maxDiff.y));
|
|
float newX = points[i-1].x + addition.x;
|
|
float newY = points[i-1].y + addition.y;
|
|
while(newY < groundLevel+2){
|
|
newY += Mathf.Abs(addition.y);
|
|
}
|
|
while(newY > maxHeight){
|
|
newY -= Mathf.Abs(addition.y);
|
|
}
|
|
points[i] = new Vector3(newX, newY);
|
|
// spriteShapeController.spline.InsertPointAt(i, points[i]);
|
|
InsertNewPoint(points[i]);
|
|
|
|
if(i % GoalDistance == 0){
|
|
InsertNewPoint(points[i] + new Vector3(0, -1f));
|
|
InsertNewPoint(points[i] + new Vector3(1f, -1f));
|
|
InsertNewPoint(points[i] + new Vector3(1f, 0f));
|
|
}
|
|
|
|
}
|
|
|
|
points[LevelCount] = new Vector3(points[LevelCount-1].x, groundLevel);
|
|
InsertNewPoint( points[LevelCount]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
void InsertNewPoint(Vector3 point){
|
|
spriteShapeController.spline.InsertPointAt(spriteShapeController.spline.GetPointCount(), point);
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|