Skip to content
Snippets Groups Projects
Commit e8c1d0cf authored by Robin Ruud Kristensen's avatar Robin Ruud Kristensen
Browse files

refacterd into more functions

parent 5fb051bf
No related branches found
No related tags found
1 merge request!85Merge
...@@ -8,44 +8,30 @@ namespace Bigsock ...@@ -8,44 +8,30 @@ namespace Bigsock
{ {
public class FollowPlayer : MonoBehaviour public class FollowPlayer : MonoBehaviour
{ {
[SerializeField] [SerializeField] NeighbourMapGenerator neighborMapGenerator;
private NeighbourMapGenerator neighborMapGenerator; [SerializeField] CinemachineConfiner2D cameraMap;
[SerializeField] [SerializeField] GameObject victoryScreen;
private CinemachineConfiner2D cameraMap;
[SerializeField] GameObject VictoryScreen;
private int levels = 0; //Unity varibles
private GameObject[] boss;
private GameObject player;
Vector3 offset = new Vector3(0, 0, -10); private GameObject[] enemies;
int i = 0; private GameObject[] Chest;
private List<GameObject> chests;
private GameObject stair;
GameObject[] boss; //Normal variables
GameObject player; private int levels = 0;
GameObject[] enemies; private static int LEVEL_CAP = 2;
GameObject[] Chest;
List<GameObject> chests;
GameObject stair;
int finalLevel = 2;
private int roomNr = 0; private int roomNr = 0;
bool stairs_down; private bool stairs_down;
int h = 0; private int victoryHold = 0;
void Start() void Start()
{ {
chests = new List<GameObject>(); chests = new List<GameObject>();
neighborMapGenerator.RunProceduralGeneration();
player = GameObject.Find("BigSock"); player = GameObject.Find("BigSock");
stair = GameObject.Find("Stairs(Clone)"); InitializeLevel();
Chest = GameObject.FindGameObjectsWithTag("Chest");
foreach(GameObject c in Chest)
{
chests.Add(c);
c.SetActive(false);
}
stairs_down = stair.GetComponent<Stairs>().stairs_touch;
stair.SetActive(false);
} }
void LateUpdate() void LateUpdate()
...@@ -53,63 +39,30 @@ namespace Bigsock ...@@ -53,63 +39,30 @@ namespace Bigsock
boss = GameObject.FindGameObjectsWithTag("Boss"); boss = GameObject.FindGameObjectsWithTag("Boss");
enemies = GameObject.FindGameObjectsWithTag((roomNr).ToString()); enemies = GameObject.FindGameObjectsWithTag((roomNr).ToString());
if (boss.Length == 0 && levels < 2) if (boss.Length == 0 && levels < LEVEL_CAP)
{ {
if (!stair.activeInHierarchy) if (!stair.activeInHierarchy)
{ {
Debug.Log("hei");
levels++; levels++;
} }
stair.SetActive(true); stair.SetActive(true);
stairs_down = stair.GetComponent<Stairs>().stairs_touch; stairs_down = stair.GetComponent<Stairs>().stairs_touch;
} }
if (levels == finalLevel && h == 0) if (levels == LEVEL_CAP && victoryHold == 0)
{ {
Time.timeScale = 0; VictoryScreen();
GameObject canvas = GameObject.Find("Canvas"); victoryHold++;
if(canvas != null)
{
Instantiate(VictoryScreen, canvas.transform);
h++;
}
} }
if (stairs_down) if (stairs_down)
{ {
roomNr = 0; ClearScene();
foreach (GameObject c in chests)
{
DestroyImmediate(c);
}
DestroyImmediate(stair);
chests.Clear();
TilemapGenerator.resetMaps();
TilemapGenerator.SetRoomIDZero();
player.transform.position = new Vector3(9,5,0); player.transform.position = new Vector3(9,5,0);
neighborMapGenerator.RunProceduralGeneration(); InitializeLevel();
Chest = GameObject.FindGameObjectsWithTag("Chest");
stair = GameObject.Find("Stairs(Clone)");
stairs_down = stair.GetComponent<Stairs>().stairs_touch;
foreach (GameObject c in Chest)
{
if(c != null)
{
c.SetActive(false);
chests.Add(c);
}
}
stair.SetActive(false);
} }
int i = 0; cameraMap.InvalidateCache();
if(i == 0) {
cameraMap.InvalidateCache();
}
if (enemies.Length == 0) if (enemies.Length == 0)
{ {
...@@ -126,16 +79,57 @@ namespace Bigsock ...@@ -126,16 +79,57 @@ namespace Bigsock
} }
private void OnDestroy() private void OnDestroy()
{
ClearScene();
}
/*
*Deletes all game objects from the scene that is not the player
*and also resets all arrays that have been made*/
private void ClearScene()
{ {
roomNr = 0; roomNr = 0;
foreach (GameObject c in chests) foreach (GameObject c in chests)
{ {
DestroyImmediate(c); DestroyImmediate(c);
} }
chests.Clear();
DestroyImmediate(stair); DestroyImmediate(stair);
NeighbourMapGenerator.ClearRoomList(); NeighbourMapGenerator.ClearRoomList();
TilemapGenerator.SetRoomIDZero(); TilemapGenerator.SetRoomIDZero();
TilemapGenerator.resetMaps(); TilemapGenerator.resetMaps();
} }
/*
*Initializes the victory screen*/
private void VictoryScreen()
{
Time.timeScale = 0;
GameObject canvas = GameObject.Find("Canvas");
if (canvas != null)
{
Instantiate(victoryScreen, canvas.transform);
}
}
/*
*Creates a level and adds objects to the different arrays */
private void InitializeLevel()
{
neighborMapGenerator.RunProceduralGeneration();
Chest = GameObject.FindGameObjectsWithTag("Chest");
stair = GameObject.Find("Stairs(Clone)");
stairs_down = stair.GetComponent<Stairs>().stairs_touch;
foreach (GameObject c in Chest)
{
if (c != null)
{
c.SetActive(false);
chests.Add(c);
}
}
stairs_down = stair.GetComponent<Stairs>().stairs_touch;
stair.SetActive(false);
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment