init
This commit is contained in:
29
Assets/Scripts/CameraFollower.cs
Normal file
29
Assets/Scripts/CameraFollower.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraFollower : MonoBehaviour
|
||||
{
|
||||
public static CameraFollower instance;
|
||||
void Awake(){
|
||||
instance = this;
|
||||
}
|
||||
public float Xsmoothness =1f;
|
||||
public float Ysmoothness =1f;
|
||||
public static Transform Target;
|
||||
public Vector2 offset;
|
||||
void Update()
|
||||
{
|
||||
}
|
||||
|
||||
public static void UpdateFrame(){
|
||||
instance.updateFrame();
|
||||
}
|
||||
|
||||
|
||||
void updateFrame(){
|
||||
float newX = Mathf.Lerp(transform.position.x, Target.position.x + offset.x, Xsmoothness);
|
||||
float newY = Mathf.Lerp(transform.position.y, Target.position.y + offset.y, Ysmoothness);
|
||||
transform.position = new Vector3(newX, newY, transform.position.z);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CameraFollower.cs.meta
Normal file
11
Assets/Scripts/CameraFollower.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aecb05e033d71884dbd165bcb677ad96
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Scripts/FuelManager.cs
Normal file
18
Assets/Scripts/FuelManager.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FuelManager : MonoBehaviour
|
||||
{
|
||||
[Range(0f,100f)]
|
||||
public float FuelLevel;
|
||||
|
||||
public float FuelConsumption = 1;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(FuelLevel >0){
|
||||
FuelLevel-=Time.deltaTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/FuelManager.cs.meta
Normal file
11
Assets/Scripts/FuelManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d0e0867e14a0a741bbc8e087471b47a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
7
Assets/Scripts/Helpers.cs
Normal file
7
Assets/Scripts/Helpers.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using UnityEngine;
|
||||
|
||||
public static class Helpers{
|
||||
public static Vector3 MidPoint(this Vector3 startPoint, Vector3 endPoint){
|
||||
return new Vector3((startPoint.x+endPoint.x)/2.0f,(startPoint.y+endPoint.y)/2.0f,(startPoint.z+endPoint.z)/2.0f);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Helpers.cs.meta
Normal file
11
Assets/Scripts/Helpers.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40e3b498233517549801980aacdb24f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
82
Assets/Scripts/LevelGenerator.cs
Normal file
82
Assets/Scripts/LevelGenerator.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.U2D;
|
||||
|
||||
public class LevelGenerator : MonoBehaviour
|
||||
{
|
||||
public GameObject spritePrefab;
|
||||
public int startPoints = 500;
|
||||
public int trendChangeThreshold = 10;
|
||||
public float maxHeightChange = 0;
|
||||
public float xMultiplier = 1;
|
||||
public Vector3[] points {get; private set;}
|
||||
|
||||
bool goingUp = false;
|
||||
int lastIndex =0;
|
||||
SpriteShapeController curSpriteController;
|
||||
void Start()
|
||||
{
|
||||
points = new Vector3[startPoints];
|
||||
for(int i=0; i < startPoints; i++){
|
||||
if(i < 1){
|
||||
points[i] = new Vector3(i, Random.Range(-1f,1f));
|
||||
GameObject initSprite = Instantiate(spritePrefab, Vector3.zero,Quaternion.identity);
|
||||
SpriteShapeController initSpriteController= initSprite.GetComponent<SpriteShapeController>();
|
||||
initSpriteController.spline.Clear();
|
||||
for(int x= 0; x < 10; x++){
|
||||
initSpriteController.spline.InsertPointAt(x, points[i] - new Vector3(x*5 + 0.5f,0));
|
||||
}
|
||||
NewTrend(i);
|
||||
|
||||
}else{
|
||||
float log = Random.Range(0, maxHeightChange);
|
||||
points[i] = new Vector3(i*xMultiplier, points[i-1].y + Random.Range((goingUp)? 0: -maxHeightChange*log,(goingUp) ? maxHeightChange*log : 0));
|
||||
}
|
||||
|
||||
if(i % trendChangeThreshold == 0){
|
||||
bool newGoingUp = Random.Range(0,100) > 50 ? true : false;
|
||||
if(newGoingUp != goingUp){
|
||||
//Gotta change trend
|
||||
goingUp = newGoingUp;
|
||||
NewTrend(i);
|
||||
}
|
||||
}
|
||||
|
||||
curSpriteController.spline.InsertPointAt(i-lastIndex, points[i]);
|
||||
curSpriteController.spline.SetTangentMode(i-lastIndex, ShapeTangentMode.Continuous);
|
||||
curSpriteController.spline.SetLeftTangent(i-lastIndex,new Vector3(0.2f,0));
|
||||
curSpriteController.spline.SetRightTangent(i-lastIndex, new Vector3(0.2f,0));
|
||||
|
||||
// if(i > 1){
|
||||
// spriteShape.spline.SetLeftTangent(i, points[i-1].MidPoint(points[i]));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
void NewTrend(int i){
|
||||
|
||||
if(curSpriteController != null){
|
||||
|
||||
EdgeCollider2D edgeCollider = curSpriteController.GetComponent<EdgeCollider2D>();
|
||||
edgeCollider.points = new Vector2[curSpriteController.spline.GetPointCount()];
|
||||
for(int x=0; x < curSpriteController.spline.GetPointCount(); x++){
|
||||
edgeCollider.points[x] = curSpriteController.spline.GetPosition(x);
|
||||
}
|
||||
curSpriteController.spline.InsertPointAt(i-lastIndex, points[i] - new Vector3(0.5f,0));
|
||||
|
||||
}
|
||||
lastIndex = i;
|
||||
|
||||
GameObject newSpriteController= Instantiate(spritePrefab, Vector3.zero, Quaternion.identity);
|
||||
curSpriteController = newSpriteController.GetComponent<SpriteShapeController>();
|
||||
curSpriteController.spline.Clear();
|
||||
curSpriteController.spriteShapeRenderer.color = goingUp ? Color.green : Color.red;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/LevelGenerator.cs.meta
Normal file
11
Assets/Scripts/LevelGenerator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be742e8ce169fe14484fa9600830f5d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
77
Assets/Scripts/carController.cs
Normal file
77
Assets/Scripts/carController.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class carController : MonoBehaviour
|
||||
{
|
||||
|
||||
public WheelJoint2D frontWheel;
|
||||
public WheelJoint2D rearWheel;
|
||||
|
||||
JointMotor2D motorFront;
|
||||
JointMotor2D motorBack;
|
||||
|
||||
public float speedF;
|
||||
public float speedB;
|
||||
|
||||
public float torqueF;
|
||||
public float torqueB;
|
||||
|
||||
public bool TractionFront = true;
|
||||
public bool TractionBack = true;
|
||||
|
||||
public float carRotationSpeed;
|
||||
|
||||
void Start()
|
||||
{
|
||||
CameraFollower.Target = transform;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetAxisRaw("Vertical") > 0)
|
||||
{
|
||||
if (TractionFront)
|
||||
{
|
||||
motorFront.motorSpeed = speedF * -1;
|
||||
motorFront.maxMotorTorque = torqueF;
|
||||
frontWheel.motor = motorFront;
|
||||
}
|
||||
if (TractionBack)
|
||||
{
|
||||
motorBack.motorSpeed = speedF * -1;
|
||||
motorBack.maxMotorTorque = torqueF;
|
||||
rearWheel.motor = motorBack;
|
||||
}
|
||||
}
|
||||
else if (Input.GetAxisRaw("Vertical") < 0)
|
||||
{
|
||||
if (TractionFront)
|
||||
{
|
||||
motorFront.motorSpeed = speedB * -1;
|
||||
motorFront.maxMotorTorque = torqueB;
|
||||
frontWheel.motor = motorFront;
|
||||
}
|
||||
if (TractionBack)
|
||||
{
|
||||
motorBack.motorSpeed = speedB * -1;
|
||||
motorBack.maxMotorTorque = torqueB;
|
||||
rearWheel.motor = motorBack;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rearWheel.useMotor = false;
|
||||
frontWheel.useMotor = false;
|
||||
}
|
||||
|
||||
if (Input.GetAxisRaw("Vertical") != 0)
|
||||
{
|
||||
GetComponent<Rigidbody2D>().AddTorque(carRotationSpeed * Input.GetAxisRaw("Vertical") * 1);
|
||||
}
|
||||
|
||||
|
||||
CameraFollower.UpdateFrame();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/carController.cs.meta
Normal file
11
Assets/Scripts/carController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 887e1484da0d849cc99147883ee42de2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user