Files
Magical-Jumping-Bean/Assets/Scripts/InfinityRunner.cs
T

214 lines
7.6 KiB
C#
Raw Normal View History

2020-01-29 22:59:06 -05:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
[System.Serializable]
public class InfinityRunner : MonoBehaviour
{
public static bool gameOver = false;
public static int escalation = 1;
public static int level = 1;
public static float fullTime;
public float distance;
2020-01-29 22:59:06 -05:00
public GameObject player;
public PlayerController script;
public GameObject[] obstacleList;
public GameObject[] easyObstacleList;
public GameObject[] medObstaclelIst;
2020-02-01 17:56:51 -05:00
public GameObject boundaries;
2020-01-29 22:59:06 -05:00
private int selection;
private int size;
2020-02-10 20:50:51 -05:00
private float countdownTime = 10.0f;
2020-01-29 22:59:06 -05:00
private float spawnTime = 0.0f;
private Transform lastSpawn;
void Awake()
{
script.respawnTime = Time.time;
}
// Start is called before the first frame update
void Start()
{
fullTime = Time.time;
2020-01-29 22:59:06 -05:00
spawnTime = Time.time;
gameOver = false;
script = player.GetComponent<PlayerController>();
level = 1;
escalation = 1;
script.lives = 3;
script.finished = false;
script.transform.position = new Vector3(0, 2, 0);
script.transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
script.pivot.transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
levelBuild();
}
void Update()
{
distance = player.transform.position.z;
if(!lastSpawn)
{
lastSpawn = player.transform;
}
if(distance >= lastSpawn.position.z)
2020-01-29 22:59:06 -05:00
{
level++;
if(level > 3)
{
escalation++;
level = 1;
2020-02-10 20:50:51 -05:00
if(escalation > 5 && countdownTime > 5.0f)
{
2020-02-10 20:50:51 -05:00
countdownTime -= 0.5f;
}
2020-01-29 22:59:06 -05:00
}
GameObject spawn;
2020-02-01 17:56:51 -05:00
GameObject wallOne;
GameObject wallTwo;
2020-01-29 22:59:06 -05:00
2020-02-10 20:50:51 -05:00
if(escalation > 6)
{
2020-02-10 20:50:51 -05:00
size = 6;
} else {
size = escalation;
}
2020-01-29 22:59:06 -05:00
if(level == 1)
{
2020-02-10 20:50:51 -05:00
if(escalation > 3 && escalation < 6)
2020-01-29 22:59:06 -05:00
{
selection = Random.Range(0, medObstaclelIst.Length);
spawn = Instantiate(medObstaclelIst[selection], new Vector3(0, 0, lastSpawn.transform.position.z+(25*size)-12.5f), Quaternion.identity) as GameObject;
2020-02-10 20:50:51 -05:00
} else if(escalation >= 6) {
2020-01-29 22:59:06 -05:00
selection = Random.Range(0, obstacleList.Length);
spawn = Instantiate(obstacleList[selection], new Vector3(0, 0, lastSpawn.transform.position.z+(25*size)-12.5f), Quaternion.identity) as GameObject;
2020-01-29 22:59:06 -05:00
} else {
selection = Random.Range(0, easyObstacleList.Length);
spawn = Instantiate(easyObstacleList[selection], new Vector3(0, 0, lastSpawn.transform.position.z+(25*size)-12.5f), Quaternion.identity) as GameObject;
2020-02-01 17:56:51 -05:00
2020-01-29 22:59:06 -05:00
}
wallOne = Instantiate(boundaries, new Vector3(((25f*(size)))/2, 0, lastSpawn.transform.position.z+(25*size)-12.5f), Quaternion.identity) as GameObject;
wallTwo = Instantiate(boundaries, new Vector3(((25f*(size)))/-2, 0, lastSpawn.transform.position.z+(25*size)-12.5f), Quaternion.identity) as GameObject;
2020-02-01 17:56:51 -05:00
2020-01-29 22:59:06 -05:00
} else {
2020-02-10 20:50:51 -05:00
if(escalation > 3 && escalation < 6)
2020-01-29 22:59:06 -05:00
{
selection = Random.Range(0, medObstaclelIst.Length);
spawn = Instantiate(medObstaclelIst[selection], new Vector3(0, 0, lastSpawn.transform.position.z+(25*size)), Quaternion.identity) as GameObject;
2020-02-10 20:50:51 -05:00
} else if(escalation >= 6) {
2020-01-29 22:59:06 -05:00
selection = Random.Range(0, obstacleList.Length);
spawn = Instantiate(obstacleList[selection], new Vector3(0, 0, lastSpawn.transform.position.z+(25*size)), Quaternion.identity) as GameObject;
2020-01-29 22:59:06 -05:00
} else {
selection = Random.Range(0, easyObstacleList.Length);
spawn = Instantiate(easyObstacleList[selection], new Vector3(0, 0, lastSpawn.transform.position.z+(25*size)), Quaternion.identity) as GameObject;
2020-01-29 22:59:06 -05:00
}
wallOne = Instantiate(boundaries, new Vector3(((25f*(size)))/2, 0, lastSpawn.transform.position.z+(25*size)), Quaternion.identity) as GameObject;
wallTwo = Instantiate(boundaries, new Vector3(((25f*(size)))/-2, 0, lastSpawn.transform.position.z+(25*size)), Quaternion.identity) as GameObject;
2020-02-01 17:56:51 -05:00
2020-01-29 22:59:06 -05:00
}
spawn.transform.localScale = new Vector3(spawn.transform.localScale.x*(0.25f*(size)), 1, spawn.transform.localScale.z*(0.25f*size));
wallOne.transform.localScale = new Vector3(wallOne.transform.localScale.x*(0.25f*(size)), 1, wallOne.transform.localScale.z*(0.25f*size));
wallTwo.transform.localScale = new Vector3(wallTwo.transform.localScale.x*(0.25f*(size)), 1, wallTwo.transform.localScale.z*(0.25f*size));
2020-01-29 22:59:06 -05:00
2020-01-29 22:59:06 -05:00
lastSpawn = spawn.transform;
}
2020-01-29 22:59:06 -05:00
GameObject[] oldObjects = GameObject.FindGameObjectsWithTag("Environment");
if(spawnTime + countdownTime < Time.time)
{
spawnTime = Time.time;
2020-01-29 22:59:06 -05:00
2020-02-01 17:56:51 -05:00
for(int i = 0; i < 3; i++) {
GameObject.Destroy(oldObjects[i]);
}
2020-01-29 22:59:06 -05:00
}
if(script.respawn == true)
{
respawn();
script.lives--;
script.respawn = false;
}
if(script.lives <= 0)
2020-01-29 22:59:06 -05:00
{
script.lives = -1;
fullTime = Time.time - fullTime;
gameOver = true;
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
PauseMenu.GameIsOver = true;
SceneManager.LoadScene("Hub World", LoadSceneMode.Single);
}
}
void respawn()
{
script.transform.position = new Vector3(0, 11, lastSpawn.position.z+1);
script.transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
2020-01-29 22:59:06 -05:00
}
void levelBuild()
{
2020-02-01 17:56:51 -05:00
GameObject walls;
2020-01-29 22:59:06 -05:00
2020-02-01 17:56:51 -05:00
GameObject start = Instantiate(obstacleList[0], new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
2020-01-29 22:59:06 -05:00
start.transform.localScale = new Vector3(25, 1, 25);
2020-02-01 17:56:51 -05:00
walls = Instantiate(boundaries, new Vector3(12.5f, 0, 0), Quaternion.identity) as GameObject;
walls.transform.localScale = new Vector3(0.25f, 1, 0.25f);
walls = Instantiate(boundaries, new Vector3(-12.5f, 0, 0), Quaternion.identity) as GameObject;
walls.transform.localScale = new Vector3(0.25f, 1, 0.25f);
GameObject startOne = Instantiate(obstacleList[0], new Vector3(0, 0, 25), Quaternion.identity) as GameObject;
startOne.transform.localScale = new Vector3(25, 1, 25);
walls = Instantiate(boundaries, new Vector3(12.5f, 0, 25), Quaternion.identity) as GameObject;
walls.transform.localScale = new Vector3(0.25f, 1, 0.25f);
walls = Instantiate(boundaries, new Vector3(-12.5f, 0, 25), Quaternion.identity) as GameObject;
walls.transform.localScale = new Vector3(0.25f, 1, 0.25f);
GameObject startTwo = Instantiate(obstacleList[0], new Vector3(0, 0, 50), Quaternion.identity) as GameObject;
startTwo.transform.localScale = new Vector3(25, 1, 25);
walls = Instantiate(boundaries, new Vector3(12.5f, 0, 50), Quaternion.identity) as GameObject;
walls.transform.localScale = new Vector3(0.25f, 1, 0.25f);
walls = Instantiate(boundaries, new Vector3(-12.5f, 0, 50), Quaternion.identity) as GameObject;
walls.transform.localScale = new Vector3(0.25f, 1, 0.25f);
2020-01-29 22:59:06 -05:00
lastSpawn = startTwo.transform;
script.finished = false;
}
}