Commit 8dfd1a8d authored by 18김민수's avatar 18김민수

Proto update

parent a0f15e00
This diff is collapsed.
......@@ -4,8 +4,13 @@ using UnityEngine;
public class FlatLandObject : MonoBehaviour
{
public Square square;
public Vector2 speedVector = new Vector2(0, 0);
public double gameSpeed = 20;
public double gameSpeed = 0;
public double properTime = 0;
void Awake()
{
square.allObjects.Add(this);
}
}
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;
public class Square : FlatLandObject
{
......@@ -10,6 +11,9 @@ public class Square : FlatLandObject
public List<Vector2> pathList = new List<Vector2>();
public UIManager uiManager;
public List<FlatLandObject> allObjects = new List<FlatLandObject>(); // Evety FlatLandObject is automatically added with Awake().
public FlatLandObject attatchedObject = null;
private Vector2 _currentPathEnd;
// Start is called before the first frame update
......@@ -22,7 +26,6 @@ public class Square : FlatLandObject
{
if(Input.GetMouseButtonDown(1)) // If right mouse button is clicked
{
Debug.Log(getNthPath(0));
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit)) // If the click was on the background
{
......@@ -32,6 +35,12 @@ public class Square : FlatLandObject
CreatePath(hit.point);
}
}
if (Input.GetKeyDown(KeyCode.G))
Grab();
if (Input.GetKeyDown(KeyCode.H))
Detach();
}
public IEnumerator MoveSquare(Vector2 destination)
......@@ -41,6 +50,8 @@ public class Square : FlatLandObject
while (speedVector.x * (destination.x - transform.position.x) > 0 || speedVector.y * (destination.y - transform.position.y) > 0)
{
transform.position += scaledVector;
if (attatchedObject != null)
attatchedObject.gameObject.transform.position += scaledVector;
yield return null;
}
......@@ -69,14 +80,16 @@ public class Square : FlatLandObject
public IEnumerator _StartMovingPath()
{
Vector3[] tomoveList = new Vector3[pathRenderer.positionCount];
Debug.Log(pathRenderer.positionCount);
pathRenderer.GetPositions(tomoveList);
for(int i = 1; i < pathRenderer.positionCount; i++)
{
yield return StartCoroutine(MoveSquare(tomoveList[i]));
}
AddTimes();
ResetPaths();
uiManager.UpdateUI();
uiManager.CheckVictory();
}
public void ResetPaths()
......@@ -113,4 +126,31 @@ public class Square : FlatLandObject
gameSpeed += d;
uiManager.UpdateUI();
}
public void Grab()
{
var lst = Physics.OverlapSphere(transform.position, 10);
if (lst.Length > 0)
attatchedObject = lst[0].gameObject.GetComponent<FlatLandObject>();
}
public void Detach()
{
attatchedObject = null;
}
public void AddTimes()
{
Debug.Log(CalculateEntireMovingTime());
foreach (var v in allObjects)
{
Debug.Log(v.gameObject.name);
v.properTime += CalculateEntireMovingTime();
}
square.properTime -= CalculateEntireMovingTime() - (square.CalculateEntireMovingTime() / Constants.Gamma(square.gameSpeed));
if (attatchedObject != null)
attatchedObject.properTime -= CalculateEntireMovingTime() - (square.CalculateEntireMovingTime() / Constants.Gamma(square.gameSpeed));
}
}
......@@ -6,9 +6,12 @@ public class UIManager : MonoBehaviour
{
public Text properTime;
public Text currentSpeed;
public Text clockText;
public Square square;
public FlatLandObject clock1, clock2;
public GameObject victoryScreen;
public void UpdateUI()
public void UpdateUI() // it just updates UI.
{
string newPropertime, prevPropertime;
......@@ -17,6 +20,14 @@ public class UIManager : MonoBehaviour
prevPropertime = square.CalculateEntireMovingTime().ToString();
newPropertime = (square.CalculateEntireMovingTime() / Constants.Gamma(square.gameSpeed)).ToString();
properTime.text = "New Proper Time : " + newPropertime + "\nPrev Proper Time : " + prevPropertime;
properTime.text = "New Proper Time : +" + newPropertime + " seconds\nPrev Proper Time : +" + prevPropertime + " seconds";
clockText.text = "Clock1 : " + clock1.properTime + " second\nClock2 : " + clock2.properTime + " second";
}
public void CheckVictory()
{
if ((clock1.transform.position - clock2.transform.position).sqrMagnitude < 10 && Mathf.Abs((float)(clock1.properTime - clock2.properTime)) < 1)
victoryScreen.SetActive(true);
}
}
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