diff --git a/Assets/Graphics.meta b/Assets/Graphics.meta deleted file mode 100644 index 2c87af9..0000000 --- a/Assets/Graphics.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 9b9db29c441a07342a58667c7825fa08 -folderAsset: yes -timeCreated: 1455386127 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scenes/GenerationTestScene.unity b/Assets/Scenes/GenerationTestScene.unity index 15260fb..0ab9d18 100644 Binary files a/Assets/Scenes/GenerationTestScene.unity and b/Assets/Scenes/GenerationTestScene.unity differ diff --git a/Assets/Scripts/CameraController.cs b/Assets/Scripts/CameraController.cs index b67b7d0..b72a214 100644 --- a/Assets/Scripts/CameraController.cs +++ b/Assets/Scripts/CameraController.cs @@ -3,35 +3,69 @@ public class CameraController : MonoBehaviour { - - public GameObject player; + //Used to disable the CameraController. + public bool follow = true; - public float smoothTime = 0.5f; + //Object to follow. + public GameObject player; + //Smoothness of the Camera when following the player. + public float smoothTime = 0.5f; + //Smoothness of the Camera when zooming out to fit the room or zooming in to follow the player. + public float zoomSmooth = 0.1f; + //Extra Screen Size + public float zoomExtra = 1; + //Game Manager Object in Scene - Need this to get RoomChecker Component + public GameObject gameManager; + //Set relative position to player object + private Vector3 offset; + //Velocity of the camera + private Vector3 currentVelocity; + //Orthographic Size of Camera when following player. + private float originalOrthoSize = 5; - private Vector3 offset; //Set relative position to player object + // Use this for initialization + void Start() + { + //Calculates offset by subtracting player position from camera object position + offset = transform.position; + originalOrthoSize = Camera.main.orthographicSize; + follow = true; + } - private Vector3 currentVelocity; //Velocity of the camera - - // Use this for initialization - void Start() - { - //Calculates offset by subtracting player position from camera object position - offset = transform.position; - } - - // Update is called once per frame - // Changed from LateUpdate to FixedUpdate so that Camera follows character more smoothly. - void FixedUpdate() - { - - if (player == null) - { - player = GameObject.Find("PlayerPlaceholder(Clone)"); - } - else - { - //Camera's new position is the player's position offsetted - transform.position = Vector3.SmoothDamp(transform.position, new Vector3(player.transform.position.x, player.transform.position.y, transform.position.z), ref currentVelocity, smoothTime); - } - } + // Update is called once per frame + // Changed from LateUpdate to FixedUpdate so that Camera follows character more smoothly. + void FixedUpdate() + { + if (follow) + { + if (player == null) + { + player = GameObject.Find("PlayerPlaceholder(Clone)"); + if (player != null) + { + transform.position = new Vector3(player.transform.position.x, player.transform.position.y, offset.z); + } + } + else + { + Room tr = gameManager.GetComponent().getRoomIn(player.transform.position); + //Camera's new position is the player's position offsetted + if (tr == null) + { + Camera.main.orthographicSize = Mathf.Lerp(Camera.main.orthographicSize, originalOrthoSize, zoomSmooth); + transform.position = Vector3.SmoothDamp(transform.position, new Vector3(player.transform.position.x, player.transform.position.y, offset.z), ref currentVelocity, smoothTime); + } + else + { + float screenDist = tr.roomWidth > tr.roomHeight ? tr.roomWidth : tr.roomHeight; + Camera.main.orthographicSize = Mathf.Lerp(Camera.main.orthographicSize, screenDist / 2 + zoomExtra, zoomSmooth); + transform.position = Vector3.SmoothDamp(transform.position, new Vector3(tr.xPos + tr.roomWidth / 2 - 0.5f, tr.yPos + tr.roomHeight / 2 - 0.5f, offset.z), ref currentVelocity, smoothTime); + } + } + } + else + { + Camera.main.orthographicSize = Mathf.Lerp(Camera.main.orthographicSize, originalOrthoSize, zoomSmooth); + } + } } diff --git a/Assets/Scripts/PanButton.cs b/Assets/Scripts/PanButton.cs index c6f9ddc..9468681 100644 --- a/Assets/Scripts/PanButton.cs +++ b/Assets/Scripts/PanButton.cs @@ -30,7 +30,7 @@ void OnTriggerStay2D(Collider2D c) player = c.transform; camPos = Camera.main.transform.position; player.GetComponent().enabled = false; - Camera.main.GetComponent().enabled = false; + Camera.main.GetComponent().follow = false; } } } @@ -57,7 +57,7 @@ void LateUpdate() Camera.main.transform.position = camPos; if (Vector2.Distance(camPos, player.position) < 0.1f) { - Camera.main.GetComponent().enabled = true; + Camera.main.GetComponent().follow = true; panState = state.notpanning; } } diff --git a/Assets/Scripts/ProcGen/BoardCreator.cs b/Assets/Scripts/ProcGen/BoardCreator.cs index 116acca..e02822f 100644 --- a/Assets/Scripts/ProcGen/BoardCreator.cs +++ b/Assets/Scripts/ProcGen/BoardCreator.cs @@ -1,6 +1,7 @@ using System.Collections; using UnityEngine; +[RequireComponent(typeof(RoomChecker))] public class BoardCreator : MonoBehaviour { // The type of tile that will be laid in a specific position. @@ -20,6 +21,7 @@ public enum TileType public GameObject[] wallTiles; // An array of wall tile prefabs. public GameObject[] outerWallTiles; // An array of outer wall tile prefabs. public GameObject player; + public RoomChecker rc; private TileType[][] tiles; // A jagged array of tile types representing the board, like a grid. private Room[] rooms; // All the rooms that are created for this board. @@ -31,6 +33,7 @@ private void Start() { // Create the board holder. boardHolder = new GameObject("BoardHolder"); + rc = transform.GetComponent(); SetupTilesArray(); @@ -41,6 +44,7 @@ private void Start() InstantiateTiles(); InstantiateOuterWalls(); + } @@ -68,20 +72,30 @@ void CreateRoomsAndCorridors() // Create the first room and corridor. rooms[0] = new Room(); - corridors[0] = new Corridor(); + corridors[0] = new Corridor(); // Setup the first room, there is no previous corridor so we do not use one. rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows); + if (rc == null) + { + Debug.Log("Roomchecker doesnt exist"); + } + if (rooms[0] == null) + { + Debug.Log("Room[0] doesnt exist"); + } + rc.RoomList.Add(rooms[0]); - // Setup the first corridor using the first room. - corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true); + // Setup the first corridor using the first room. + corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true); // Set up second room. Check for overlap is not necessary rooms[1] = new Room(); rooms[1].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[0]); + rc.RoomList.Add(rooms[1]); - // Set up the rest of the rooms and corridors, checking for overlaps - for (int i = 2; i < rooms.Length; i++) + // Set up the rest of the rooms and corridors, checking for overlaps + for (int i = 2; i < rooms.Length; i++) { bool goodRoomPlacement = false; @@ -119,7 +133,8 @@ void CreateRoomsAndCorridors() { corridors [i - 1] = corridorToBePlaced; rooms [i] = roomToBePlaced; - } + rc.RoomList.Add(rooms[i]); + } } //Instantiates player in the i-th/2 room created diff --git a/Assets/Scripts/ProcGen/RoomChecker.cs b/Assets/Scripts/ProcGen/RoomChecker.cs new file mode 100644 index 0000000..1822362 --- /dev/null +++ b/Assets/Scripts/ProcGen/RoomChecker.cs @@ -0,0 +1,27 @@ +using UnityEngine; +using System.Collections.Generic; + +public class RoomChecker : MonoBehaviour { + //ArrayList of all the Rooms on the Board. + public List RoomList; + public float bonusThreshhold; + + void Start () { + RoomList = new List(); + } + public void Add(Room r) + { + RoomList.Add(r); + } + public Room getRoomIn(Vector2 pos) + { + foreach(Room r in RoomList) + { + if (pos.x >= r.xPos-bonusThreshhold && pos.x <= r.xPos + r.roomWidth + bonusThreshhold && pos.y >= r.yPos -bonusThreshhold && pos.y <= r.yPos + r.roomHeight + bonusThreshhold) + { + return r; + } + } + return null; + } +} diff --git a/Assets/Scripts/ProcGen/RoomChecker.cs.meta b/Assets/Scripts/ProcGen/RoomChecker.cs.meta new file mode 100644 index 0000000..69b932c --- /dev/null +++ b/Assets/Scripts/ProcGen/RoomChecker.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: cacdf28687c67af4a9143f7238987583 +timeCreated: 1456629712 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 49f55f5..70fdf2d 100644 Binary files a/ProjectSettings/ProjectSettings.asset and b/ProjectSettings/ProjectSettings.asset differ