Commit 9b987038 authored by 18손재민's avatar 18손재민

카메라 갈아 엎음. 이제 카메라는 벽에 부딪혀서 벽 밖으로는 조금만 보여주게 되고 그 외 기타 자잘한 오류들 고침

parent ac70cdfd
...@@ -23,7 +23,7 @@ GameObject: ...@@ -23,7 +23,7 @@ GameObject:
- component: {fileID: 95049867913064836} - component: {fileID: 95049867913064836}
- component: {fileID: 60595704614928888} - component: {fileID: 60595704614928888}
- component: {fileID: 114295912794569440} - component: {fileID: 114295912794569440}
m_Layer: 8 m_Layer: 12
m_Name: DoorInGameDown m_Name: DoorInGameDown
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
......
...@@ -23,7 +23,7 @@ GameObject: ...@@ -23,7 +23,7 @@ GameObject:
- component: {fileID: 95177593216515702} - component: {fileID: 95177593216515702}
- component: {fileID: 60996771576975244} - component: {fileID: 60996771576975244}
- component: {fileID: 114082229687600582} - component: {fileID: 114082229687600582}
m_Layer: 8 m_Layer: 12
m_Name: DoorInGameLeft m_Name: DoorInGameLeft
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
......
...@@ -23,7 +23,7 @@ GameObject: ...@@ -23,7 +23,7 @@ GameObject:
- component: {fileID: 95627112181051082} - component: {fileID: 95627112181051082}
- component: {fileID: 60158907655368212} - component: {fileID: 60158907655368212}
- component: {fileID: 114434671980411926} - component: {fileID: 114434671980411926}
m_Layer: 8 m_Layer: 12
m_Name: DoorInGameRight m_Name: DoorInGameRight
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
......
...@@ -23,7 +23,7 @@ GameObject: ...@@ -23,7 +23,7 @@ GameObject:
- component: {fileID: 95785122911416600} - component: {fileID: 95785122911416600}
- component: {fileID: 60354718583369946} - component: {fileID: 60354718583369946}
- component: {fileID: 114142621642518908} - component: {fileID: 114142621642518908}
m_Layer: 8 m_Layer: 12
m_Name: DoorInGameUp m_Name: DoorInGameUp
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
......
...@@ -3,33 +3,21 @@ using System.Collections.Generic; ...@@ -3,33 +3,21 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class CameraController : MonoBehaviour { public class CameraController : MonoBehaviour {
public MapManager mapManager; public MapManager mapManager;
public LayerMask roomLayer;
public GameObject player; public GameObject player;
/// <summary> /// <summary>
/// Coroutine controls scene changing.
/// </summary>
public static Coroutine sceneChanger;
/// <summary>
/// Check if scene is changing now. /// Check if scene is changing now.
/// </summary> /// </summary>
public static bool isSceneChanging = false; public static bool isSceneChanging = false;
/// <summary> const float cameraXLimit = 4.5f;
/// Coroutine controls room fade in when camera zoom in. const float cameraYLimit = 3f;
/// </summary>
Coroutine fadeIn;
/// <summary>
/// Coroutine controls room fade out when camera zoom out.
/// </summary>
Coroutine fadeOut;
readonly float camX = 9.5f;
readonly float camY = 4f;
public Vector3 tetrisCameraCoord = new Vector3(108, 240, -1); public Vector3 tetrisCameraCoord = new Vector3(108, 240, -1);
public Vector3 originPos;
public const float tetrisCameraSize = 300f; public const float tetrisCameraSize = 300f;
public const float inGameCameraSize = 4.5f; public const float inGameCameraSize = 4.5f;
public Vector3 originPos;
private void Awake() private void Awake()
{ {
...@@ -43,14 +31,18 @@ public class CameraController : MonoBehaviour { ...@@ -43,14 +31,18 @@ public class CameraController : MonoBehaviour {
} }
// Update is called once per frame // Update is called once per frame
void Update() void LateUpdate()
{ {
GotoDestination();
if (GameManager.gameState == GameState.Ingame) if (GameManager.gameState == GameState.Ingame)
originPos = player.transform.position + new Vector3(0, 0, -1); {
FollowPlayer();
originPos = transform.position;
}
else if (GameManager.gameState == GameState.Tetris) else if (GameManager.gameState == GameState.Tetris)
{
originPos = tetrisCameraCoord; originPos = tetrisCameraCoord;
} }
}
/// <summary> /// <summary>
/// Shake camera. /// Shake camera.
...@@ -62,8 +54,8 @@ public class CameraController : MonoBehaviour { ...@@ -62,8 +54,8 @@ public class CameraController : MonoBehaviour {
float amount = _amount; float amount = _amount;
while (amount > 0) while (amount > 0)
{ {
transform.position = new Vector3(0.2f * Random.insideUnitCircle.x * amount * GetComponent<Camera>().orthographicSize + originPos.x, transform.position = new Vector3(0.2f * Random.insideUnitCircle.x * amount * GetComponent<Camera>().orthographicSize,
Random.insideUnitCircle.y * amount * GetComponent<Camera>().orthographicSize + originPos.y, originPos.z); Random.insideUnitCircle.y * amount * GetComponent<Camera>().orthographicSize, 0) + originPos;
amount -= _amount / 40; amount -= _amount / 40;
yield return null; yield return null;
} }
...@@ -84,132 +76,83 @@ public class CameraController : MonoBehaviour { ...@@ -84,132 +76,83 @@ public class CameraController : MonoBehaviour {
StartCoroutine(mapManager.RoomFadeIn(MapManager.currentRoom)); StartCoroutine(mapManager.RoomFadeIn(MapManager.currentRoom));
grid.transform.position = new Vector3(0, 0, 0); grid.transform.position = new Vector3(0, 0, 0);
sizeDestination = inGameCameraSize; sizeDestination = inGameCameraSize;
while (GetComponent<Camera>().orthographicSize > sizeDestination + 0.01)
{
yield return null;
FollowPlayer();
GetComponent<Camera>().orthographicSize = Mathf.Lerp(GetComponent<Camera>().orthographicSize, sizeDestination, Mathf.Sqrt(Time.deltaTime));
}
} }
else if (GameManager.gameState == GameState.Tetris) else if (GameManager.gameState == GameState.Tetris)
{ {
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;
} while (GetComponent<Camera>().orthographicSize < sizeDestination - 2)
while ((GameManager.gameState == GameState.Tetris && GetComponent<Camera>().orthographicSize < sizeDestination - 5) ||
(GameManager.gameState == GameState.Ingame && GetComponent<Camera>().orthographicSize > sizeDestination + 0.05))
{ {
yield return null; yield return null;
Vector2 coord = Vector2.Lerp(transform.position, originPos, Mathf.Sqrt(Time.deltaTime)); Vector2 coord = Vector2.Lerp(transform.position, tetrisCameraCoord, Mathf.Sqrt(Time.deltaTime));
transform.position = new Vector3(coord.x, coord.y, -1); transform.position = new Vector3(coord.x, coord.y, -1);
GetComponent<Camera>().orthographicSize = Mathf.Lerp(GetComponent<Camera>().orthographicSize, sizeDestination, Mathf.Sqrt(Time.deltaTime)); GetComponent<Camera>().orthographicSize = Mathf.Lerp(GetComponent<Camera>().orthographicSize, sizeDestination, Mathf.Sqrt(Time.deltaTime));
} }
transform.position = originPos; transform.position = tetrisCameraCoord;
}
GetComponent<Camera>().orthographicSize = sizeDestination; GetComponent<Camera>().orthographicSize = sizeDestination;
isSceneChanging = false; isSceneChanging = false;
} }
void GotoDestination() void FollowPlayer()
{
// TODO: Change this.
/*Vector3 pos = GameObject.Find("Player").transform.position;
pos.z = -1;
transform.position = pos;*/
if (GameManager.gameState == GameState.Ingame && isSceneChanging != true)
{
if(MapManager.isRoomFalling != true)
{ {
float posx = player.transform.position.x; float posx = player.transform.position.x;
float posy = player.transform.position.y; float posy = player.transform.position.y;
if (RoomCol("Up") != -1)
if (!MapManager.currentRoom.isRoomCleared) posy = RoomCol("Up") - cameraYLimit;
{ if (RoomCol("Down") != -1)
posy = RoomCol("Down") + cameraYLimit;
if (RoomCol(1) != -1) if (RoomCol("Left") != -1)
{ posx = RoomCol("Left") + cameraXLimit;
posy = RoomCol(1) - camY; if (RoomCol("Right") != -1)
} posx = RoomCol("Right") - cameraXLimit;
if (RoomCol(2) != -1) if (RoomCol("Left") != -1 && RoomCol("Right") != -1)
{
posy = RoomCol(2) + camY;
}
if (RoomCol(3) != -1)
{
posx = RoomCol(3) + camX;
}
if (RoomCol(4) != -1)
{
posx = RoomCol(4) - camX;
}
if (RoomCol(3) != -1 && RoomCol(4) != -1)
{ {
float middle = Player.tx * 24f + 12f; float middle = Player.tx * 24f + 12f;
if (middle - RoomCol(3) > 20f) if (middle - RoomCol("Left") > 20f)
{ posx = RoomCol("Left") + cameraXLimit;
posx = RoomCol(3) + camX; else if (RoomCol("Right") - middle > 20f)
} posx = RoomCol("Right") - cameraXLimit;
else if (RoomCol(4) - middle > 20f)
{
posx = RoomCol(4) - camX;
}
else else
{
posx = player.transform.position.x; posx = player.transform.position.x;
}
//방의 중심과 비교하여 어느게 더 가까운가 //방의 중심과 비교하여 어느게 더 가까운가
} }
if (MapManager.isRoomFalling != true)
transform.position = Vector3.Lerp(transform.position, new Vector3(posx, posy, -1), 4f * Time.deltaTime);
else if (MapManager.isRoomFalling == true)
transform.position = Vector3.Lerp(transform.position, new Vector3(posx, posy, -1), 0.9f);
transform.position = new Vector3(transform.position.x, transform.position.y, -1);
}
float RoomCol(string direction)
{
Vector2 position = player.transform.position;
switch (direction)
{
case "Up":
if (position.y + cameraYLimit >= MapManager.tetrisYCoord[(int)MapManager.currentRoom.mapCoord.y] + 23f)
return MapManager.tetrisYCoord[(int)MapManager.currentRoom.mapCoord.y] + 23f;
break;
case "Down":
if (position.y - cameraYLimit <= MapManager.tetrisYCoord[(int)MapManager.currentRoom.mapCoord.y] + 1f)
return MapManager.tetrisYCoord[(int)MapManager.currentRoom.mapCoord.y] + 1f;
break;
case "Left":
if(position.x - cameraXLimit <= Player.tx * 24f + 1)
return Player.tx * 24f + 1;
break;
case "Right":
if(position.x + cameraXLimit >= (Player.tx + 1) * 24f - 1)
return (Player.tx + 1) * 24f - 1;
break;
} }
transform.position = Vector3.Lerp(transform.position, new Vector3(posx, posy, -1), 2f * Time.deltaTime);
transform.position = new Vector3(transform.position.x, transform.position.y, -1); //카메라를 원래 z축으로 이동
}
else if(MapManager.isRoomFalling == true)
{
transform.position = player.transform.position + new Vector3(0, 0.2f, -1);
}
}
// Camera.main.transform.position = new Vector3(posx, posy, -10);
}
float RoomCol(int dir)
{
//1:up
//2:down
//3:left
//4:right
if (!(dir >= 0 && dir <= 4)) return -1;
float distance = 0f;
Vector2 direction = Vector2.up;
Vector2 position = new Vector2(player.transform.position.x, player.transform.position.y);
if (dir == 1)
{
direction = Vector2.up;
distance = camY;
}
if (dir == 2)
{
direction = Vector2.down;
distance = camY;
}
if (dir == 3)
{
direction = Vector2.left;
distance = camX;
}
if (dir == 4)
{
direction = Vector2.right;
distance = camX;
}
RaycastHit2D hit1 = Physics2D.Raycast(position, direction, distance, roomLayer);
//Debug.DrawRay(position, direction,Color.yellow);
if (hit1.collider != null)
{
if (dir == 1 || dir == 2)
return hit1.point.y;
else return hit1.point.x;
}
return -1; return -1;
} }
} }
\ No newline at end of file
...@@ -16,6 +16,7 @@ public class GameManager : MonoBehaviour { ...@@ -16,6 +16,7 @@ public class GameManager : MonoBehaviour {
GameObject.Find("TetriminoSpawner").GetComponent<TetriminoSpawner>().MakeInitialTetrimino(); GameObject.Find("TetriminoSpawner").GetComponent<TetriminoSpawner>().MakeInitialTetrimino();
Vector2 coord = MapManager.currentRoom.transform.position; Vector2 coord = MapManager.currentRoom.transform.position;
GameObject.Find("Player").transform.position = new Vector2(coord.x, coord.y) + new Vector2(3, 3); GameObject.Find("Player").transform.position = new Vector2(coord.x, coord.y) + new Vector2(3, 3);
GameObject.Find("Main Camera").transform.position = GameObject.Find("Player").transform.position;
} }
// Update is called once per frame // Update is called once per frame
......
fileFormatVersion: 2
guid: 3eeb43e73bfaf1f48901afcdbe4f6d11
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
...@@ -76,11 +76,11 @@ public class MapManager : MonoBehaviour { ...@@ -76,11 +76,11 @@ public class MapManager : MonoBehaviour {
/// <summary> /// <summary>
/// Check if this row is being deleted. /// Check if this row is being deleted.
/// </summary> /// </summary>
private static bool[] isRowDeleting = new bool[20]; public static bool[] isRowDeleting = new bool[20];
/// <summary> /// <summary>
/// Tetris Y axis coordinates on Unity. /// Tetris Y axis coordinates on Unity.
/// </summary> /// </summary>
private static float[] tetrisYCoord = new float[height]; public static float[] tetrisYCoord = new float[height];
/// <summary> /// <summary>
/// Array that saves presses. /// Array that saves presses.
/// </summary> /// </summary>
...@@ -292,6 +292,8 @@ public class MapManager : MonoBehaviour { ...@@ -292,6 +292,8 @@ public class MapManager : MonoBehaviour {
mapGrid[doorCloseCounter, row].CloseDoor("Down", false); mapGrid[doorCloseCounter, row].CloseDoor("Down", false);
mapGrid[width - doorCloseCounter - 1, row].CloseDoor("Up", false); mapGrid[width - doorCloseCounter - 1, row].CloseDoor("Up", false);
mapGrid[width - doorCloseCounter - 1, row].CloseDoor("Down", false); mapGrid[width - doorCloseCounter - 1, row].CloseDoor("Down", false);
mapGrid[doorCloseCounter, row].isRoomDestroyed = true;
mapGrid[width - doorCloseCounter - 1, row].isRoomDestroyed = true;
doorCloseCounter++; doorCloseCounter++;
} }
if(collapseRate - roomDestroyCounter * 0.2f > 0.2f) if(collapseRate - roomDestroyCounter * 0.2f > 0.2f)
...@@ -415,6 +417,7 @@ public class MapManager : MonoBehaviour { ...@@ -415,6 +417,7 @@ public class MapManager : MonoBehaviour {
SetRoomsYCoord(); SetRoomsYCoord();
if(currentRoom.mapCoord.y >= bottom) if(currentRoom.mapCoord.y >= bottom)
player.transform.position += new Vector3(0, - yFallSpeed, 0); player.transform.position += new Vector3(0, - yFallSpeed, 0);
previousPlayerRelativePosition = player.transform.position - currentRoom.transform.position;
} }
if (shakeCamera) if (shakeCamera)
{ {
...@@ -908,6 +911,5 @@ public class MapManager : MonoBehaviour { ...@@ -908,6 +911,5 @@ public class MapManager : MonoBehaviour {
} }
else else
Debug.Log("Game Over"); Debug.Log("Game Over");
} }
} }
...@@ -80,6 +80,10 @@ public class Room : MonoBehaviour ...@@ -80,6 +80,10 @@ public class Room : MonoBehaviour
/// Check if room is clear and escapable. /// Check if room is clear and escapable.
/// </summary> /// </summary>
public bool isRoomCleared; public bool isRoomCleared;
/// <summary>
/// Check if room is destroyed.
/// </summary>
public bool isRoomDestroyed = false;
/* /*
* functions * functions
...@@ -138,7 +142,7 @@ public class Room : MonoBehaviour ...@@ -138,7 +142,7 @@ public class Room : MonoBehaviour
switch (direction) switch (direction)
{ {
case "Up": case "Up":
if (mapCoord.y < MapManager.realHeight && MapManager.mapGrid[(int)mapCoord.x, (int)mapCoord.y + 1] != null) if (mapCoord.y < MapManager.realHeight && MapManager.mapGrid[(int)mapCoord.x, (int)mapCoord.y + 1] != null && MapManager.mapGrid[(int)mapCoord.x, (int)mapCoord.y + 1].isRoomDestroyed != true)
{ {
door = inGameDoorUp; door = inGameDoorUp;
animatorThisRoom = door.GetComponent<Animator>(); animatorThisRoom = door.GetComponent<Animator>();
...@@ -146,7 +150,7 @@ public class Room : MonoBehaviour ...@@ -146,7 +150,7 @@ public class Room : MonoBehaviour
} }
break; break;
case "Down": case "Down":
if (mapCoord.y > 0 && MapManager.mapGrid[(int)mapCoord.x, (int)mapCoord.y - 1] != null) if (mapCoord.y > 0 && MapManager.mapGrid[(int)mapCoord.x, (int)mapCoord.y - 1] != null && MapManager.mapGrid[(int)mapCoord.x, (int)mapCoord.y - 1].isRoomDestroyed != true)
{ {
door = inGameDoorDown; door = inGameDoorDown;
animatorThisRoom = door.GetComponent<Animator>(); animatorThisRoom = door.GetComponent<Animator>();
......
...@@ -85,7 +85,7 @@ public class TetriminoSpawner : MonoBehaviour { ...@@ -85,7 +85,7 @@ public class TetriminoSpawner : MonoBehaviour {
int randomPosition = Random.Range(0, MapManager.width); int randomPosition = Random.Range(0, MapManager.width);
int randomTetrimino = TetriminoRandomizer(); int randomTetrimino = TetriminoRandomizer();
MapManager.currentTetrimino = Instantiate(tetriminoes[randomTetrimino], MapManager.tetrisMapCoord + MapManager.tetrisMapSize * new Vector3(randomPosition, 0, MapManager.tetrisMapCoord.z), Quaternion.identity); MapManager.currentTetrimino = Instantiate(tetriminoes[randomTetrimino], MapManager.tetrisMapCoord + MapManager.tetrisMapSize * new Vector3(randomPosition, 0, MapManager.tetrisMapCoord.z), Quaternion.identity);
MapManager.currentRoom = MapManager.currentTetrimino.rooms[Random.Range(0, MapManager.currentTetrimino.rooms.Length)]; MapManager.currentRoom = MapManager.currentTetrimino.rooms[0];
MapManager.currentRoom.specialRoomType = RoomType.Start; MapManager.currentRoom.specialRoomType = RoomType.Start;
MapManager.currentTetrimino.mapCoord = (MapManager.currentTetrimino.transform.position - MapManager.tetrisMapCoord) / MapManager.tetrisMapSize; MapManager.currentTetrimino.mapCoord = (MapManager.currentTetrimino.transform.position - MapManager.tetrisMapCoord) / MapManager.tetrisMapSize;
mapManager.SetRoomMapCoord(MapManager.currentTetrimino); mapManager.SetRoomMapCoord(MapManager.currentTetrimino);
...@@ -103,6 +103,7 @@ public class TetriminoSpawner : MonoBehaviour { ...@@ -103,6 +103,7 @@ public class TetriminoSpawner : MonoBehaviour {
mapManager.CreateRoom(MapManager.currentTetrimino); mapManager.CreateRoom(MapManager.currentTetrimino);
MapManager.currentRoom.fog.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0); MapManager.currentRoom.fog.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
MapManager.currentRoom.GetComponent<SpriteRenderer>().sprite = mapManager.roomsSpritesDistributed[MapManager.currentStage][(int)RoomSpriteType.Current]; MapManager.currentRoom.GetComponent<SpriteRenderer>().sprite = mapManager.roomsSpritesDistributed[MapManager.currentStage][(int)RoomSpriteType.Current];
MapManager.currentRoom.ClearRoom();
MapManager.tempRoom = MapManager.currentRoom; MapManager.tempRoom = MapManager.currentRoom;
MakeTetrimino(); MakeTetrimino();
} }
......
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