This commit is contained in:
2023-01-23 13:49:56 +05:30
parent 263feed880
commit a9e65bfc72
19 changed files with 7248 additions and 31 deletions

View File

@@ -12,6 +12,9 @@ public class CameraFollower : MonoBehaviour
public float Ysmoothness =1f;
public static Transform Target;
public Vector2 offset;
public Vector3 shakeIntensity;
public GameObject shakeFX_good;
public GameObject shakeFX_bad;
void FixedUpdate()
{
UpdateFrame();
@@ -23,12 +26,19 @@ public class CameraFollower : MonoBehaviour
void updateFrame(){
if(PlayerController.boosting){
//Add boost here
}
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);
if(PlayerController.boosting){
//Add boost here
shakeFX_good.SetActive(PlayerController.instance.isUp);
shakeFX_bad.SetActive(!PlayerController.instance.isUp);
transform.position += new Vector3(Random.Range(-shakeIntensity.x, shakeIntensity.x), Random.Range(-shakeIntensity.y,shakeIntensity.y), Random.Range(-shakeIntensity.z,shakeIntensity.z));
}else{
shakeFX_good.SetActive(false);
shakeFX_bad.SetActive(false);
}
}
}

View File

@@ -1,16 +1,72 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
void Awake(){
instance = this;
}
public Text txt_money;
public float moneyMultiplier = 5;
public Vector3 txtMoneyOffset = Vector2.one;
public GameObject gameOverPanel;
public GameObject startPanel;
public GameObject finishPanel;
public Text finishedScoreTxt;
public Transform CheckeredFlag;
public void StartGame(){
startPanel.SetActive(false);
}
void Update(){
txt_money.text = "$"+(PlayerController.t.position.y*moneyMultiplier).ToString("n4");
txt_money.rectTransform.position = Camera.main.WorldToScreenPoint(PlayerController.t.position + txtMoneyOffset);
if(PlayerController.boosting){
txt_money.rectTransform.localScale = Vector3.Lerp(txt_money.rectTransform.localScale, Vector3.one * 1.5f, 0.05f);
}else{
txt_money.rectTransform.localScale = Vector3.Lerp(txt_money.rectTransform.localScale, Vector3.one , 0.1f);
}
if(PlayerController.t.position.y > 120){
Color curColor = Camera.main.backgroundColor;
Camera.main.backgroundColor = Color.Lerp(curColor, Color.black, 0.001f);
}
if(CheckeredFlag.position.x - PlayerController.t.position.x > 20){
CheckeredFlag.position = new Vector2(CheckeredFlag.position.x,PlayerController.t.position.y);
}else if(CheckeredFlag.position.x - PlayerController.t.position.x < 4){
FinishGame();
}
}
public void gameOver(){
gameOverPanel.SetActive(true);
PlayerController.instance.GameOver();
}
public static void GameOver(){
instance.gameOver();
}
public void FinishGame(){
finishPanel.SetActive(true);
finishedScoreTxt.text = txt_money.text;
PlayerController.instance.GameOver();
}
public void Restart(){
SceneManager.LoadScene("Game");
}
}

View File

@@ -9,6 +9,8 @@ public class OptionsSpawner : MonoBehaviour
{
instance = this;
}
public int goodSpawnRate=2;
public int badSpawnRate=5;
public Transform optionGood;
public Transform optionBad;
public Vector2 SpawnDistanceMin;
@@ -19,6 +21,16 @@ public class OptionsSpawner : MonoBehaviour
void Update()
{
if (!PlayerController.Started) { return; }
if(PlayerController.t.position.y < 100){
goodSpawnRate = 2;
badSpawnRate = 1;
}else if(PlayerController.t.position.y < 500){
goodSpawnRate = 2;
badSpawnRate = 2;
}else{
goodSpawnRate = 1;
badSpawnRate = 3;
}
if (t < SpawnTimer)
{
t += Time.deltaTime;
@@ -27,13 +39,29 @@ public class OptionsSpawner : MonoBehaviour
{
t = 0;
float newGoodRate = 1.05f + GetRandomRateDiff();
SpawnGood(newGoodRate);
for (int i = 0; i < 2; i++)
List<Vector3> positions= new List<Vector3>();
for (int i = 0; i < goodSpawnRate; i++)
{
float newGoodRate = 1.05f + GetRandomRateDiff();
Vector3 position = PlayerController.t.position + new Vector3(PlayerController.t.right.x * Random.Range(SpawnDistanceMin.x, SpawnDistanceMax.x), PlayerController.t.right.y * Random.Range(SpawnDistanceMin.y, SpawnDistanceMax.y));
// foreach(Vector3 pos in positions){
// if(Vector3.Distance(pos, position) < 3){
// position += new Vector3(10,0,0);
// }
// }
SpawnGood(newGoodRate);
}
for (int i = 0; i < badSpawnRate; i++)
{
Vector3 position = PlayerController.t.position + new Vector3(PlayerController.t.right.x * Random.Range(SpawnDistanceMin.x, SpawnDistanceMax.x), PlayerController.t.right.y * Random.Range(SpawnDistanceMin.y, SpawnDistanceMax.y));
// foreach(Vector3 pos in positions){
// if(Vector3.Distance(pos, position) < 3){
// position += new Vector3(10,0,0);
// }
// }
float newBadRate = 0.95f - GetRandomRateDiff();
SpawnBad(newBadRate);
SpawnBad(newBadRate,position);
}
}
}

View File

@@ -29,6 +29,11 @@ public class PlayerController : MonoBehaviour
CameraFollower.Target = transform;
}
public void GameOver(){
Started=false;
spriteRenderer.sprite = downwardSprite;
}
public static bool Started;
// Update is called once per frame
void Update(){
@@ -44,7 +49,9 @@ public class PlayerController : MonoBehaviour
eulerAngles = transform.eulerAngles;
currentTrail.transform.position = transform.position;
if(transform.position.y < 0){
GameManager.GameOver();
}
if(boosting){return;}
Collider2D overlap = Physics2D.OverlapCircle(transform.position, senseRadius);
if(overlap!=null){
@@ -62,16 +69,19 @@ public class PlayerController : MonoBehaviour
boosting=true;
float newY = transform.position.y * perc;
spriteRenderer.sprite = (perc > 1) ? upwardSprite : downwardSprite;
// float boostingSpeed = transform.position.y * (1f/boostSpeed);
float boostingSpeed = boostSpeed;
if(transform.position.y < 250){boostingSpeed = boostSpeed/2f;}
if(perc > 1){
while(transform.position.y < newY){
transform.position += new Vector3(0,boostSpeed,0);
transform.position += new Vector3(0,boostingSpeed,0);
if(!isUp){SwitchSide();}
yield return new WaitForFixedUpdate();
}
}else{
while(transform.position.y > newY){
transform.position -= new Vector3(0,boostSpeed,0);
transform.position -= new Vector3(0,boostingSpeed,0);
if(isUp){SwitchSide();}
yield return new WaitForFixedUpdate();
}
@@ -82,7 +92,11 @@ public class PlayerController : MonoBehaviour
void SwitchSide(){
if(!Started){
GameManager.instance.StartGame();
}
Started=true;
transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, isUp ? -turnAngle : turnAngle);
GameObject newTrail = Instantiate(trailPrefab, transform.position, Quaternion.identity);
@@ -90,7 +104,7 @@ public class PlayerController : MonoBehaviour
newTrail.GetComponent<TrailRenderer>().startColor = newTrail.GetComponent<TrailRenderer>().endColor = (isUp) ? Color.green:Color.red;
// GetComponent<SpriteRenderer>().sprite = (isUp) ? upwardSprite : downwardSprite;
GetComponent<SpriteRenderer>().sprite = (isUp) ? upwardSprite : downwardSprite;
}