Commit cd735704 authored by 18손재민's avatar 18손재민

포탈 완성

parent bd3ab003
...@@ -51,3 +51,4 @@ MonoBehaviour: ...@@ -51,3 +51,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 97912f0a2214a8a4f8023ed30629bb30, type: 3} m_Script: {fileID: 11500000, guid: 97912f0a2214a8a4f8023ed30629bb30, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
gameOverScreen: {fileID: 0}
...@@ -73,8 +73,10 @@ MonoBehaviour: ...@@ -73,8 +73,10 @@ MonoBehaviour:
type: 2} type: 2}
inGameDoorRight: {fileID: 1668375270989012, guid: fa868e0924825b54896b61a69e93391f, inGameDoorRight: {fileID: 1668375270989012, guid: fa868e0924825b54896b61a69e93391f,
type: 2} type: 2}
portalSelected: {fileID: 1272210399781394, guid: 94f4bf6088d377c4780a5bc55baaabe0, portalSurface: {fileID: 1272210399781394, guid: 94f4bf6088d377c4780a5bc55baaabe0,
type: 2} type: 2}
portalExist: {fileID: 21300000, guid: d2894481921999843ae1800d4b65ded6, type: 3}
portalSelected: {fileID: 21300000, guid: ab953b34dd9966f409d851b274ed4d9f, type: 3}
normalRoomList1: normalRoomList1:
- {fileID: 114452746530220676, guid: 3c35322ac2c308d49aadf20738b69c8b, type: 2} - {fileID: 114452746530220676, guid: 3c35322ac2c308d49aadf20738b69c8b, type: 2}
- {fileID: 114071400998216906, guid: 7fd2833846bb116479bd74d2a5b75487, type: 2} - {fileID: 114071400998216906, guid: 7fd2833846bb116479bd74d2a5b75487, type: 2}
......
...@@ -21,7 +21,7 @@ GameObject: ...@@ -21,7 +21,7 @@ GameObject:
- component: {fileID: 4131413436280266} - component: {fileID: 4131413436280266}
- component: {fileID: 212754017166168550} - component: {fileID: 212754017166168550}
m_Layer: 0 m_Layer: 0
m_Name: PortalSelcted m_Name: PortalSurface
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
......
...@@ -91,7 +91,24 @@ public class CameraController : MonoBehaviour { ...@@ -91,7 +91,24 @@ public class CameraController : MonoBehaviour {
if(gameState == GameState.Tetris) if(gameState == GameState.Tetris)
GameManager.gameState = GameState.Tetris; GameManager.gameState = GameState.Tetris;
else if(gameState == GameState.Portal) else if(gameState == GameState.Portal)
{
GameManager.gameState = GameState.Portal; GameManager.gameState = GameState.Portal;
for (int x = 0; x < MapManager.width; x++)
MapManager.portalDistributedHorizontal[x].Clear();
for (int y = 0; y <= MapManager.realHeight; y++)
MapManager.portalDistributedVertical[y].Clear();
for (int x = 0; x < MapManager.width; x++)
for (int y = 0; y <= MapManager.realHeight; y++)
if (MapManager.mapGrid[x, y] != null && MapManager.mapGrid[x, y].isPortal == true)
{
MapManager.portalGrid[x, y] = true;
MapManager.portalDistributedHorizontal[x].Add(y);
MapManager.portalDistributedVertical[y].Add(x);
}
MapManager.portalDestination = MapManager.currentRoom.mapCoord;
MapManager.mapGrid[(int)MapManager.portalDestination.x, (int)MapManager.portalDestination.y].portalSurface.GetComponent<SpriteRenderer>().sprite =
GameObject.Find("MapManager").GetComponent<MapManager>().portalSelected;
}
StartCoroutine(mapManager.RoomFadeOut(MapManager.currentRoom)); StartCoroutine(mapManager.RoomFadeOut(MapManager.currentRoom));
grid.transform.position = new Vector3(0, 0, 2); grid.transform.position = new Vector3(0, 0, 2);
sizeDestination = tetrisCameraSize; sizeDestination = tetrisCameraSize;
......
...@@ -49,6 +49,8 @@ public class GameManager : MonoBehaviour { ...@@ -49,6 +49,8 @@ public class GameManager : MonoBehaviour {
{ {
GameObject.Find("Player").transform.position = MapManager.mapGrid[(int)MapManager.portalDestination.x, (int)MapManager.portalDestination.y].portal.transform.position + new Vector3(2, 1, 0); GameObject.Find("Player").transform.position = MapManager.mapGrid[(int)MapManager.portalDestination.x, (int)MapManager.portalDestination.y].portal.transform.position + new Vector3(2, 1, 0);
GameObject.Find("MapManager").GetComponent<MapManager>().ChangeRoom(MapManager.mapGrid[(int)MapManager.portalDestination.x, (int)MapManager.portalDestination.y]); GameObject.Find("MapManager").GetComponent<MapManager>().ChangeRoom(MapManager.mapGrid[(int)MapManager.portalDestination.x, (int)MapManager.portalDestination.y]);
MapManager.mapGrid[(int)MapManager.portalDestination.x, (int)MapManager.portalDestination.y].portalSurface.GetComponent<SpriteRenderer>().sprite =
GameObject.Find("MapManager").GetComponent<MapManager>().portalExist;
StartCoroutine(GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraController>().ChangeScene(GameState.Ingame)); StartCoroutine(GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraController>().ChangeScene(GameState.Ingame));
} }
} }
......
...@@ -159,9 +159,17 @@ public class MapManager : MonoBehaviour { ...@@ -159,9 +159,17 @@ public class MapManager : MonoBehaviour {
/// </summary> /// </summary>
public GameObject inGameDoorRight; public GameObject inGameDoorRight;
/// <summary> /// <summary>
/// Indicates the location of the selected portal. /// Indicates the location of the existing portal.
/// </summary> /// </summary>
public GameObject portalSelected; public GameObject portalSurface;
/// <summary>
/// Sprite of existing portals.
/// </summary>
public Sprite portalExist;
/// <summary>
/// Sprite of selected portals.
/// </summary>
public Sprite portalSelected;
/// <summary> /// <summary>
/// Destination of portal player will move. /// Destination of portal player will move.
/// </summary> /// </summary>
...@@ -792,7 +800,6 @@ public class MapManager : MonoBehaviour { ...@@ -792,7 +800,6 @@ public class MapManager : MonoBehaviour {
public void ChangeRoom(Room newRoom) public void ChangeRoom(Room newRoom)
{ {
Room room = currentRoom; Room room = currentRoom;
Debug.Log(room.mapCoord + "prev");
StartCoroutine(RoomFadeOut(room)); StartCoroutine(RoomFadeOut(room));
if (room.specialRoomType == RoomType.Normal) if (room.specialRoomType == RoomType.Normal)
room.GetComponent<SpriteRenderer>().sprite = roomsSpritesDistributed[room.stage][(int)RoomSpriteType.Normal1 + room.roomConcept]; room.GetComponent<SpriteRenderer>().sprite = roomsSpritesDistributed[room.stage][(int)RoomSpriteType.Normal1 + room.roomConcept];
...@@ -800,7 +807,6 @@ public class MapManager : MonoBehaviour { ...@@ -800,7 +807,6 @@ public class MapManager : MonoBehaviour {
room.GetComponent<SpriteRenderer>().sprite = roomsSpritesDistributed[room.stage][(int)room.specialRoomType]; room.GetComponent<SpriteRenderer>().sprite = roomsSpritesDistributed[room.stage][(int)room.specialRoomType];
currentRoom = newRoom; currentRoom = newRoom;
StartCoroutine(RoomFadeIn(newRoom)); StartCoroutine(RoomFadeIn(newRoom));
Debug.Log(newRoom.mapCoord + "current");
newRoom.GetComponent<SpriteRenderer>().sprite = roomsSpritesDistributed[newRoom.stage][(int)RoomSpriteType.Current]; newRoom.GetComponent<SpriteRenderer>().sprite = roomsSpritesDistributed[newRoom.stage][(int)RoomSpriteType.Current];
} }
/// <summary> /// <summary>
...@@ -850,80 +856,89 @@ public class MapManager : MonoBehaviour { ...@@ -850,80 +856,89 @@ public class MapManager : MonoBehaviour {
public void PortalControl() public void PortalControl()
{ {
int difference = 100; int minDifference = 100;
int difference = 0;
Vector2 tempDestination = new Vector2(0, 0);
if (Input.GetKeyDown(KeyCode.UpArrow)) if (Input.GetKeyDown(KeyCode.UpArrow))
{
for (int i = (int)portalDestination.y + 1; i < realHeight + 1; i++) for (int i = (int)portalDestination.y + 1; i < realHeight + 1; i++)
{ {
if(portalDistributedVertical[i].Count != 0) if(portalDistributedVertical[i].Count != 0)
{ {
for(int j = 0; j < portalDistributedVertical[i].Count; j++) mapGrid[(int)portalDestination.x, (int)portalDestination.y].portalSurface.GetComponent<SpriteRenderer>().sprite = portalExist;
for (int j = 0; j < portalDistributedVertical[i].Count; j++)
{ {
if (Mathf.Abs(portalDistributedVertical[i][j] - (int)portalDestination.x) < difference) difference = Mathf.Abs(portalDistributedVertical[i][j] - (int)portalDestination.x);
if (difference < minDifference)
{ {
difference = portalDistributedVertical[i][j] - (int)portalDestination.x; minDifference = difference;
portalDestination = new Vector2(portalDistributedVertical[i][j], i); tempDestination = new Vector2(portalDistributedVertical[i][j], i);
} }
} }
break; portalDestination = tempDestination;
mapGrid[(int)portalDestination.x, (int)portalDestination.y].portalSurface.GetComponent<SpriteRenderer>().sprite = portalSelected;
return;
} }
} }
}
else if (Input.GetKeyDown(KeyCode.DownArrow)) else if (Input.GetKeyDown(KeyCode.DownArrow))
{
for (int i = (int)portalDestination.y - 1; i >= 0; i--) for (int i = (int)portalDestination.y - 1; i >= 0; i--)
{ {
if(portalDistributedVertical[i].Count != 0) if(portalDistributedVertical[i].Count != 0)
{ {
mapGrid[(int)portalDestination.x, (int)portalDestination.y].portalSurface.GetComponent<SpriteRenderer>().sprite = portalExist;
for (int j = 0; j < portalDistributedVertical[i].Count; j++) for (int j = 0; j < portalDistributedVertical[i].Count; j++)
{ {
if (Mathf.Abs(portalDistributedVertical[i][j] - (int)portalDestination.x) < difference) difference = Mathf.Abs(portalDistributedVertical[i][j] - (int)portalDestination.x);
if (difference < minDifference)
{ {
difference = portalDistributedVertical[i][j] - (int)portalDestination.x; minDifference = difference;
portalDestination = new Vector2(portalDistributedVertical[i][j], i); tempDestination = new Vector2(portalDistributedVertical[i][j], i);
} }
} }
break; portalDestination = tempDestination;
mapGrid[(int)portalDestination.x, (int)portalDestination.y].portalSurface.GetComponent<SpriteRenderer>().sprite = portalSelected;
return;
} }
} }
}
else if (Input.GetKeyDown(KeyCode.LeftArrow)) else if (Input.GetKeyDown(KeyCode.LeftArrow))
{
for (int i = (int)portalDestination.x - 1; i >= 0; i--) for (int i = (int)portalDestination.x - 1; i >= 0; i--)
{ {
if(portalDistributedHorizontal[i].Count != 0) if(portalDistributedHorizontal[i].Count != 0)
{ {
mapGrid[(int)portalDestination.x, (int)portalDestination.y].portalSurface.GetComponent<SpriteRenderer>().sprite = portalExist;
for (int j = 0; j < portalDistributedHorizontal[i].Count; j++) for (int j = 0; j < portalDistributedHorizontal[i].Count; j++)
{ {
if (Mathf.Abs(portalDistributedHorizontal[i][j] - (int)portalDestination.y) < difference) difference = Mathf.Abs(portalDistributedHorizontal[i][j] - (int)portalDestination.y);
if (difference < minDifference)
{ {
difference = portalDistributedHorizontal[i][j] - (int)portalDestination.y; minDifference = difference;
portalDestination = new Vector2(i, portalDistributedHorizontal[i][j]); tempDestination = new Vector2(i, portalDistributedHorizontal[i][j]);
} }
} }
break; portalDestination = tempDestination;
mapGrid[(int)portalDestination.x, (int)portalDestination.y].portalSurface.GetComponent<SpriteRenderer>().sprite = portalSelected;
return;
} }
} }
}
else if (Input.GetKeyDown(KeyCode.RightArrow)) else if (Input.GetKeyDown(KeyCode.RightArrow))
{
for (int i = (int)portalDestination.x + 1; i < width; i++) for (int i = (int)portalDestination.x + 1; i < width; i++)
{ {
if(portalDistributedHorizontal[i].Count != 0) if(portalDistributedHorizontal[i].Count != 0)
{ {
mapGrid[(int)portalDestination.x, (int)portalDestination.y].portalSurface.GetComponent<SpriteRenderer>().sprite = portalExist;
for (int j = 0; j < portalDistributedHorizontal[i].Count; j++) for (int j = 0; j < portalDistributedHorizontal[i].Count; j++)
{ {
if (Mathf.Abs(portalDistributedHorizontal[i][j] - (int)portalDestination.y) < difference) difference = Mathf.Abs(portalDistributedHorizontal[i][j] - (int)portalDestination.y);
if (difference < minDifference)
{ {
difference = portalDistributedHorizontal[i][j] - (int)portalDestination.y; minDifference = difference;
portalDestination = new Vector2(i, portalDistributedHorizontal[i][j]); tempDestination = new Vector2(i, portalDistributedHorizontal[i][j]);
} }
} }
break; portalDestination = tempDestination;
mapGrid[(int)portalDestination.x, (int)portalDestination.y].portalSurface.GetComponent<SpriteRenderer>().sprite = portalSelected;
return;
} }
} }
}
Debug.Log(portalDestination);
} }
void Awake() void Awake()
......
...@@ -6,26 +6,8 @@ public class Portal : MonoBehaviour { ...@@ -6,26 +6,8 @@ public class Portal : MonoBehaviour {
private void OnTriggerStay2D(Collider2D collision) private void OnTriggerStay2D(Collider2D collision)
{ {
if (collision.tag.Equals("Player")) if (collision.tag.Equals("Player") && Input.GetKeyDown(KeyCode.F))
{ StartCoroutine(GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraController>().ChangeScene(GameState.Portal));
if (Input.GetKeyDown(KeyCode.F))
{
for (int x = 0; x < MapManager.width; x++)
MapManager.portalDistributedHorizontal[x].Clear();
for (int y = 0; y <= MapManager.realHeight; y++)
MapManager.portalDistributedVertical[y].Clear();
for (int x = 0; x < MapManager.width; x++)
for (int y = 0; y <= MapManager.realHeight; y++)
if (MapManager.mapGrid[x, y] != null && MapManager.mapGrid[x, y].isPortal == true)
{
MapManager.portalGrid[x, y] = true;
MapManager.portalDistributedHorizontal[x].Add(y);
MapManager.portalDistributedVertical[y].Add(x);
}
MapManager.portalDestination = MapManager.currentRoom.mapCoord;
StartCoroutine(GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraController>().ChangeScene(GameState.Portal));
}
}
} }
// Use this for initialization // Use this for initialization
......
...@@ -81,6 +81,10 @@ public class Room : MonoBehaviour ...@@ -81,6 +81,10 @@ public class Room : MonoBehaviour
/// </summary> /// </summary>
public GameObject portal; public GameObject portal;
/// <summary> /// <summary>
/// Portal surface of the room.
/// </summary>
public GameObject portalSurface;
/// <summary>
/// Check if room is clear and escapable. /// Check if room is clear and escapable.
/// </summary> /// </summary>
public bool isRoomCleared; public bool isRoomCleared;
...@@ -380,7 +384,7 @@ public class Room : MonoBehaviour ...@@ -380,7 +384,7 @@ public class Room : MonoBehaviour
fog.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0); fog.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
CreatePortal(); CreatePortal();
if (isPortal == true) if (isPortal == true)
Instantiate(GameObject.Find("MapManager").GetComponent<MapManager>().portalSelected, transform.position + new Vector3(12, 12, 0), Quaternion.identity, transform); portalSurface = Instantiate(GameObject.Find("MapManager").GetComponent<MapManager>().portalSurface, transform.position + new Vector3(12, 12, 0), Quaternion.identity, transform);
isRoomCleared = true; isRoomCleared = true;
if (specialRoomType == RoomType.Boss) if (specialRoomType == RoomType.Boss)
MapManager.currentStage += 1; MapManager.currentStage += 1;
......
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