Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions Assets/Graphics.meta

This file was deleted.

Binary file modified Assets/Scenes/GenerationTestScene.unity
Binary file not shown.
90 changes: 62 additions & 28 deletions Assets/Scripts/CameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RoomChecker>().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);
}
}
}
4 changes: 2 additions & 2 deletions Assets/Scripts/PanButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void OnTriggerStay2D(Collider2D c)
player = c.transform;
camPos = Camera.main.transform.position;
player.GetComponent<PlayerController>().enabled = false;
Camera.main.GetComponent<CameraController>().enabled = false;
Camera.main.GetComponent<CameraController>().follow = false;
}
}
}
Expand All @@ -57,7 +57,7 @@ void LateUpdate()
Camera.main.transform.position = camPos;
if (Vector2.Distance(camPos, player.position) < 0.1f)
{
Camera.main.GetComponent<CameraController>().enabled = true;
Camera.main.GetComponent<CameraController>().follow = true;
panState = state.notpanning;
}
}
Expand Down
27 changes: 21 additions & 6 deletions Assets/Scripts/ProcGen/BoardCreator.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -31,6 +33,7 @@ private void Start()
{
// Create the board holder.
boardHolder = new GameObject("BoardHolder");
rc = transform.GetComponent<RoomChecker>();

SetupTilesArray();

Expand All @@ -41,6 +44,7 @@ private void Start()

InstantiateTiles();
InstantiateOuterWalls();

}


Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions Assets/Scripts/ProcGen/RoomChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using UnityEngine;
using System.Collections.Generic;

public class RoomChecker : MonoBehaviour {
//ArrayList of all the Rooms on the Board.
public List<Room> RoomList;
public float bonusThreshhold;

void Start () {
RoomList = new List<Room>();
}
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;
}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/ProcGen/RoomChecker.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified ProjectSettings/ProjectSettings.asset
Binary file not shown.