Commit 185da338 authored by 18손재민's avatar 18손재민 Committed by 18손재민

게임 오버 및 게임 재시작 구현

parent 5c8e1c1c
......@@ -33,7 +33,7 @@ public class CameraTurret : MonoBehaviour, IObject, IBreakable, IPlayerInteracto
{
if (Position.IsInAdjacentArea(pos, 1) && MapManager.inst.currentMap.GetWallAtPos((Vector2)(Position + pos) / 2) == null)
{
StartCoroutine(GameManager.inst.GameOver());
StartCoroutine(GameManager.inst.RestartStage());
//TODO : Restart Level
}
......
......@@ -12,6 +12,18 @@ public class GameManager : SingletonBehaviour<GameManager>
public int clearCounter = 0;
public static int nFloor, nTurret, nCase, nPlayer, aFloor, aTurret, aCase, white, black;
/// <summary>
/// The index of the current stage.
/// </summary>
public int currentStage;
public void ResetClearIndex()
{
//Reset clear index to -1.
for (int i = 0; i < clearIndex.Length; i++) clearIndex[i] = -1;
nFloor = nTurret = nCase = nPlayer = aFloor = aTurret = aCase = white = black = -1;
}
//Find and set the index of clear conditions of the map to clear type.
public void SetClearIndex(Map map)
{
......@@ -36,35 +48,38 @@ public class GameManager : SingletonBehaviour<GameManager>
Debug.Log("Stage Clear!");
}
public IEnumerator GameOver()
public void GameOver()
{
Debug.Log("Game Over!");
StopAllCoroutines();
yield return new WaitForSeconds(1);
foreach (GameObject child in MapManager.inst.players)
Destroy(child);
Destroy(MapManager.inst.currentMap.gameObject);
}
public void StageRestart()
public IEnumerator RestartStage()
{
Debug.Log("Game Restart!");
yield return new WaitForSeconds(0.5f);
GameOver();
MapManager.inst.LoadMap(MapManager.inst.stage[0]);
MapManager.inst.LoadMap(MapManager.inst.stage[currentStage]);
}
void Awake()
{
//Reset clear index to -1.
for (int i = 0; i < clearIndex.Length; i++) clearIndex[i] = -1;
nFloor = nTurret = nCase = nPlayer = aFloor = aTurret = aCase = white = black = -1;
}
// Start is called before the first frame update
void Start()
{
if (!MapManager.inst.isMapEditingOn)
MapManager.inst.LoadMap(MapManager.inst.stage[0]);
currentStage = 0;
MapManager.inst.LoadMap(MapManager.inst.stage[currentStage]);
if (MapManager.inst.isMapEditingOn)
{
//Reset clear index to -1.
ResetClearIndex();
}
}
}
......@@ -34,6 +34,9 @@ public class MapManager : SingletonBehaviour<MapManager>
var loadedMapData = JsonConvert.DeserializeObject<MapEditor.MapSaveData>(_newMap.ToString());
currentMap = Instantiate(emptyMap, new Vector3(0, 0, 0), Quaternion.identity);
currentMap.InitiateMap();
GameManager.inst.ResetClearIndex();
PlayerController.inst.bulletList.Clear();
players.Clear();
currentMap.maxMapSize = (int)loadedMapData.objects[0].xPos;
int casesIndex = 0;
for(int i = 1; i < loadedMapData.objects.Count; i++)
......@@ -93,7 +96,6 @@ public class MapManager : SingletonBehaviour<MapManager>
private void Awake()
{
players = new List<GameObject>();
bulletFactory = new BulletFactory(truthBullet, fakeBullet, mirrorBullet);
}
......
......@@ -222,7 +222,7 @@ public class Map : MonoBehaviour
switch (objType)
{
case ObjType.Briefcase:
objectGrid.Add(pos, Instantiate(MapManager.inst.briefCase, new Vector3(pos.x, 0.35f, pos.y), Quaternion.identity, objects.transform).GetComponent<IObject>());
objectGrid.Add(pos, Instantiate(MapManager.inst.briefCase, new Vector3(pos.x, 0.5f, pos.y), Quaternion.identity, objects.transform).GetComponent<IObject>());
if (GameManager.aCase >= 0)
clearConditions[GameManager.aCase].IsDone(0, 1);
break;
......@@ -245,7 +245,7 @@ public class Map : MonoBehaviour
public void CreateObject(Vector2Int pos, ObjType objType, BulletCode _dropBullet)
{
CreateObject(pos, objType);
GetObjectAtPos(pos).GetObject().GetComponent<Briefcase>().dropBullet = _dropBullet;
GetObjectAtPos(pos).GetObject().GetComponent<Briefcase>().SetBullet(_dropBullet);
}
/// <summary>
/// Remove Object at position.
......@@ -266,6 +266,8 @@ public class Map : MonoBehaviour
else if (!objectGrid[pos].GetObject().GetComponent<Mannequin>().isWhite && GameManager.black >= 0)
clearConditions[GameManager.black].IsDone(0, -1);
}
if(objectGrid[pos].GetType() != ObjType.Mannequin)
PlayerController.inst.OnPlayerMove -= objectGrid[pos].GetObject().GetComponent<IPlayerInteractor>().Interact;
Destroy(objectGrid[pos].GetObject());
objectGrid.Remove(pos);
StartCoroutine(MapManager.inst.Rebaker());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment