This commit is contained in:
2023-07-19 00:28:23 +05:30
commit 6918aec205
136 changed files with 15958 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollower : MonoBehaviour
{
public Transform target;
public float smoothness =0.1f;
public Vector3 offset;
void Start()
{
// offset= transform.position - target.position;
}
// Update is called once per frame
void FixedUpdate()
{
transform.position = Vector3.Lerp(transform.position, new Vector3(target.position.x - offset.x, transform.position.y, transform.position.z), smoothness);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8feed348f96742ab6942068e14985993
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

15
Assets/Scripts/Helpers.cs Normal file
View File

@@ -0,0 +1,15 @@
using UnityEngine;
[System.Serializable]
public class Range{
public float min, max;
public Range(float _min, float _max){
min = _min;
max = _max;
}
public float GetRandom(){
return Random.Range(min,max);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7c86f35454ceec3cdb95fa89495abd5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,78 @@
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.U2D;
public class LevelGenerator : MonoBehaviour
{
public GameObject spriteShapecontrollerPrefab;
public int levelCount = 200;
public float bot_groundLevel,bot_topLevel, top_lowLevel,top_ceilingLevel;
public Vector2 minDiff, maxDiff;
public float tangentSmoothness = 3;
void Start()
{
GenerateBlock();
GenerateBlock();
GenerateBlock();
GenerateBlock();
GenerateBlock();
}
// Update is called once per frame
void Update()
{
}
Vector3[] bot_points;
float curBlockOffset=-20;
void GenerateBlock(){
float offset = curBlockOffset;
SpriteShapeController bot_spriteShapeController = Instantiate(spriteShapecontrollerPrefab, new Vector3(offset,0),Quaternion.identity).GetComponent<SpriteShapeController>();
bot_spriteShapeController.spline.Clear();
Vector3[] bot_points = new Vector3[levelCount +1];
InsertNewPoint(bot_spriteShapeController, new Vector3(0,bot_groundLevel *2));
for(int i=0; i < levelCount; i++){
if(i==0){
bot_points[i] = new Vector3(0,bot_groundLevel);
bot_points[i] = new Vector3(0,bot_groundLevel);
// bot_spriteShapeController.spline.InsertPointAt(i,bot_points[i]);
InsertNewPoint(bot_spriteShapeController, bot_points[i]);
continue;
}
Vector3 addition = new Vector3(Random.Range(minDiff.x, maxDiff.x), Random.Range(minDiff.y, maxDiff.y));
float newX = bot_points[i-1].x + addition.x;
float newY = bot_points[i-1].y + addition.y;
while(newY < bot_groundLevel+2){
newY += Mathf.Abs(addition.y);
// await Task.Delay(1);
}
while(newY > bot_topLevel){
newY -= Mathf.Abs(addition.y);
// await Task.Delay(1);
}
bot_points[i] = new Vector3(newX, newY);
// spriteShapeController.spline.InsertPointAt(i, points[i]);
InsertNewPoint(bot_spriteShapeController, bot_points[i]);
}
bot_points[levelCount] = new Vector3(bot_points[levelCount-1].x+maxDiff.x, bot_groundLevel * 2);
curBlockOffset += bot_points[levelCount].x - maxDiff.x;
InsertNewPoint(bot_spriteShapeController, bot_points[levelCount]);
}
void InsertNewPoint(SpriteShapeController spriteShapeController,Vector3 point){
int index= spriteShapeController.spline.GetPointCount();
spriteShapeController.spline.InsertPointAt(index, point);
spriteShapeController.spline.SetTangentMode(index, ShapeTangentMode.Continuous);
spriteShapeController.spline.SetLeftTangent(index, new Vector3(-tangentSmoothness,0));
spriteShapeController.spline.SetRightTangent(index,new Vector3(tangentSmoothness,0));
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bb409958b188083b3858ea3ed7bb7bc9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,116 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;
public class LevelGeneratorV2 : MonoBehaviour
{
public LineRenderer debugLine;
[SerializeField]public Range amplitude = new Range(1,2);
[SerializeField]public Range distance = new Range(2,5);
[SerializeField]public Range height = new Range(3,6);
public float frequency = 0.1f;
[Header("Generation")]
public SpriteShapeController[] shapes;
List<SpriteShapeController> pooled,borrowed = new List<SpriteShapeController>();
public float tangentSmoothness = 1.5f;
// Start is called before the first frame update
void Start()
{
Application.targetFrameRate = 60;
// #if UNITY_EDITOR
// debugLine.gameObject.SetActive(true);
// #else
// debugLine.gameObject.SetActive(false);
// #endif
pooled = new List<SpriteShapeController>();
borrowed = new List<SpriteShapeController>();
foreach(SpriteShapeController shape in shapes){pooled.Add(shape);}
GenerateNext(amount:100);
}
// Update is called once per frame
void Update()
{
if(PlayerController.position.x > lastStart){
GenerateNext();
}
}
float lastStart;
List<Vector3> points = new List<Vector3>();
float a;
void GenerateNext(int amount = 100){
if(points.Count <= 0){points.Add(new Vector3(0,0));}
int startIndex = points.Count-1;
lastStart = points[startIndex].x;
for(int i=0; i < amount; i++){
a+= frequency;
float y = Mathf.Sin(a) * amplitude.GetRandom();
float x = points[points.Count-1].x + distance.GetRandom();
points.Add(new Vector3(x,y));
}
CleanupBorrowed();
SpriteShapeController bot_controller = pooled[0];
borrowed.Add(pooled[0]);
pooled.RemoveAt(0);
bot_controller.spline.Clear();
InsertNewPoint(bot_controller, points[startIndex]- new Vector3(0, 50));
for(int i=startIndex; i < points.Count; i++){
InsertNewPoint(bot_controller, points[i] - new Vector3(0, height.GetRandom()));
}
InsertNewPoint(bot_controller, points[points.Count-1] - new Vector3(0,50));
bot_controller.transform.position = Vector3.zero;
bot_controller.gameObject.SetActive(false);
bot_controller.gameObject.SetActive(true);
SpriteShapeController top_controller = pooled[0];
borrowed.Add(pooled[0]);
pooled.RemoveAt(0);
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, height.GetRandom()));
}
InsertNewPoint(top_controller, points[points.Count-1] + new Vector3(0,50));
top_controller.transform.position = Vector3.zero;
top_controller.gameObject.SetActive(false);
top_controller.gameObject.SetActive(true);
UpdateLine();
}
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){
pooled.Add(borrowed[i]);
borrowed.RemoveAt(i);
}
}
}
void UpdateLine(){
debugLine.positionCount = points.Count;
debugLine.SetPositions(points.ToArray());
}
void InsertNewPoint(SpriteShapeController spriteShapeController,Vector3 point){
int index= spriteShapeController.spline.GetPointCount();
spriteShapeController.spline.InsertPointAt(index, point);
spriteShapeController.spline.SetTangentMode(index, ShapeTangentMode.Continuous);
spriteShapeController.spline.SetLeftTangent(index, new Vector3(-tangentSmoothness,0));
spriteShapeController.spline.SetRightTangent(index,new Vector3(tangentSmoothness,0));
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 354d9248a316dac4ebc09b32b808ce92
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Obstacle : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other){
Debug.Log(other.name);
PlayerController.instance.GameOver();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cbed2ce01a4e59bb89ffbb4064435938
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,72 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
void Awake(){
instance = this;
}
public static PlayerController instance;
public static Transform t => instance.transform;
public static Vector3 position=> instance.transform.position;
public float movingSpeed = 1;
public float speedIncremental = 0.01f;
public float verticalSpeed = 0.5f;
public float rotationRange = 15;
public bool invert= true;
public Text txtScore;
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
transform.Translate(new Vector3(movingSpeed,0), Space.World);
input = Mathf.Lerp(input, dif / inputRange, inputSmoothness);
transform.Translate(new Vector3(0,input * verticalSpeed), Space.World);
transform.localEulerAngles = new Vector3(0,0,input * rotationRange);
txtScore.text = transform.position.x.ToString("n0");
movingSpeed += speedIncremental * Time.deltaTime;
}
public float input = 0;
public float inputSmoothness =0.1f;
public float inputRange = 200;
public float dif = 0;
float startedPos=0;
public void OnPointerDown(BaseEventData e){
PointerEventData ped = (PointerEventData) e as PointerEventData;
startedPos = ped.position.y;
}
public void OnPointerDrag(BaseEventData e){
PointerEventData ped = (PointerEventData) e as PointerEventData;
dif = (invert) ? ped.position.y-startedPos: startedPos - ped.position.y;
}
public void OnPointerUp(BaseEventData e){
dif = 0;
startedPos = 0;
}
public void GameOver(){
Application.LoadLevel(0);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 38618340518ac121cb2ed87183f65a6e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: