This commit is contained in:
2023-02-10 16:04:36 +05:30
parent 6682748554
commit 8c29a37ac9
11 changed files with 994 additions and 9 deletions

View File

@@ -0,0 +1,71 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class GameManager : MonoBehaviour
{
public Rigidbody2D ball;
public Transform cam;
public Vector3 camTargetPos;
public float cameraSmoothness = 0.1f;
public float inputSensitivity = 100f;
public float BallFriction = 0.1f;
public float StopVelocity = 0.01f;
public float StopTime = 0.1f;
public float curVelocity;
void Start()
{
camTargetPos = ball.transform.position;
}
float stopCooldown = 0;
void FixedUpdate(){
curVelocity = ball.velocity.magnitude;
ball.velocity = Vector2.Lerp(ball.velocity, new Vector2(0, ball.velocity.y), BallFriction);
if(Mathf.Abs(ball.velocity.magnitude) < StopVelocity){
if(stopCooldown > StopTime){
ball.simulated=false;
}else{
stopCooldown+=Time.deltaTime;
}
}else{
stopCooldown=0;
}
}
void Update(){
camTargetPos = ball.transform.position;
}
void LateUpdate()
{
cam.position = Vector3.Lerp(cam.position, new Vector3(camTargetPos.x, cam.position.y,cam.position.z), cameraSmoothness);
}
bool dragging = false;
Vector2 startPos;
public void OnMouseDown(BaseEventData e){
PointerEventData ped = (PointerEventData) e as PointerEventData;
startPos = ped.position;
dragging = true;
}
public void OnMouseUp(BaseEventData e){
PointerEventData ped = (PointerEventData) e as PointerEventData;
if(dragging){
Vector2 v = (ped.position-startPos)/inputSensitivity;
stopCooldown=0;
ball.simulated=true;
ball.AddForce(-v);
}
dragging = false;
}
public void OnMouseDrag(BaseEventData e){
}
}

View File

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

View File

@@ -12,6 +12,8 @@ public class LevelGenerator : MonoBehaviour
public float maxHeight = 5;
public Vector2 minDiff, maxDiff;
public Vector3[] points {get; private set;}
public int GoalDistance= 10;
void Start()
{
spriteShapeController.spline.Clear();
@@ -27,25 +29,37 @@ public class LevelGenerator : MonoBehaviour
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){
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]);
// 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);
spriteShapeController.spline.InsertPointAt(LevelCount, points[LevelCount]);
InsertNewPoint( points[LevelCount]);
}
void InsertNewPoint(Vector3 point){
spriteShapeController.spline.InsertPointAt(spriteShapeController.spline.GetPointCount(), point);
}
void Update()
{