Commit 34405def authored by 18손재민's avatar 18손재민

Merge branch 'interact'

# Conflicts:
#	Assets/Scripts/Interactors/Mannequin.cs
parents 6e8b713f 6db8638a
......@@ -92,7 +92,7 @@ BoxCollider:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1244481854748732982}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1.0000005, y: 1.0000002, z: 0.080003634}
......
......@@ -89,7 +89,7 @@ BoxCollider:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 337530617404887312}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1.0000005, y: 1.0000002, z: 0.080003634}
......
......@@ -89,6 +89,7 @@ GameObject:
- component: {fileID: 6001025753464593565}
- component: {fileID: 439939669}
- component: {fileID: 896145114}
- component: {fileID: 3778247420154791817}
m_Layer: 0
m_Name: camera
m_TagString: Untagged
......@@ -144,6 +145,20 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
floor: {fileID: 0}
--- !u!136 &3778247420154791817
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6001025753464815805}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_Enabled: 1
m_Radius: 0.25
m_Height: 0.03
m_Direction: 1
m_Center: {x: 0, y: 0.45, z: 0}
--- !u!1 &6001025753464815807
GameObject:
m_ObjectHideFlags: 0
......
......@@ -38,6 +38,7 @@ public class Mannequin : MonoBehaviour, IObject, IBulletInteractor
_color = value;
}
}
public bool isWhite;
public void Interact(Bullet bullet)
{
......@@ -69,6 +70,7 @@ public class Mannequin : MonoBehaviour, IObject, IBulletInteractor
public void SetColor(bool isWhite)
{
Color = isWhite ? Color.white : Color.black;
this.isWhite = isWhite;
if (GameManager.white >= 0 && isWhite)
MapManager.inst.currentMap.clearConditions[GameManager.white].IsDone(1);
if (GameManager.black >= 0 && !isWhite)
......
......@@ -14,8 +14,9 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
{
if (bullet is FakeBullet)
{
//Debug.Log("ldPos: " + ldPos + ", rdPos: " + rdPos + ", dir: " + dir);
// Make reflected objects
CopyObjects(PlayerController.inst.currentPlayer);
StartCoroutine(CopyObjects(PlayerController.inst.currentPlayer));
}
}
......@@ -23,78 +24,132 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
/// copy objects which reflected by this mirror
/// </summary>
/// <param name="_shooter">transform of shooter</param>
private void CopyObjects(Player _shooter)
IEnumerator CopyObjects(Player _shooter)
{
Vector2Int stPos = _shooter.pos; // position of shooter's cell
Vector2 stPos = _shooter.pos; // position of shooter's cell
//Debug.Log("stPos: " + stPos);
List<Pair<float, float>> parRay = new List<Pair<float, float>>
{
new Pair<float, float>(0, 1)
};
int side, i, iReset, stCheck;
if (dir) // horizontal, parallel with x
{
side = (mapPos.y - stPos.y > 0) ? -1 : 1;
i = side > 0 ? Mathf.CeilToInt(mapPos.y) : Mathf.FloorToInt(mapPos.y);
iReset = i;
stCheck = (int)stPos.y;
}
else // vertical, parallel with y
{
side = (mapPos.x - stPos.x > 0) ? -1 : 1;
i = side > 0 ? Mathf.CeilToInt(mapPos.x) : Mathf.FloorToInt(mapPos.x);
iReset = i;
stCheck = (int)stPos.x;
}
yield return null;
// check before reflect (check walls and mirrors)
float mirrorPos = (dir ? mapPos.y : mapPos.x);
float stPosFix = (dir ? stPos.y : stPos.x);
foreach (var wall in MapManager.inst.currentMap.wallGrid)
{
if (wall.Value.mapPos != mapPos)
float wallPos = (dir ? wall.Key.y : wall.Key.x);
if (wall.Value.GetInstanceID() != GetInstanceID() && (side < 0 ? wallPos < mirrorPos && wallPos > stPosFix : wallPos > mirrorPos && wallPos < stPosFix))
{
Pair<float, float> pair = new Pair<float, float>(PointToParRay(stPos, wall.Value.ldPos, false), PointToParRay(stPos, wall.Value.rdPos, false));
if (pair.l > pair.r) pair = pair.Swap();
SubtractRay(parRay, pair);
yield return null;
}
}
Debug.Log("Start Reflecting.");
// check after reflect, if obj or floor, copy else if wall or mirror, Subtract
int side, i;
if (dir) // horizontal, parallel with x
{
side = (ldPos.y - stPos.y > 0) ? -1 : 1;
i = ldPos.y;
}
else // vertical, parallel with y
{
side = (ldPos.x - stPos.x > 0) ? -1 : 1;
i = ldPos.x;
}
for (; i < MapManager.inst.currentMap.maxMapSize; i += side)
Dictionary<Vector2Int, Floor> copyFloorGrid = new Dictionary<Vector2Int, Floor>(MapManager.inst.currentMap.floorGrid);
Dictionary<Vector2Int, IObject> copyObjGrid = new Dictionary<Vector2Int, IObject>(MapManager.inst.currentMap.objectGrid);
Dictionary<Vector2, Wall> copyWallGrid = new Dictionary<Vector2, Wall>(MapManager.inst.currentMap.wallGrid);
for (i = iReset; Mathf.Abs(i) < MapManager.inst.currentMap.maxMapSize; i += side)
{
foreach (var floor in MapManager.inst.currentMap.floorGrid)
foreach (var floor in copyFloorGrid)
{
if ((dir ? floor.Key.y : floor.Key.x) == i)
{
if (IsInRay(parRay, PointToParRay(stPos, floor.Value.mapPos, true)))
if (IsInRay(parRay, PointToParRay(stPos, floor.Key, true)))
{
/*copy floor*/
int nextx = dir ? floor.Key.x : 2 * ldPos.x - floor.Key.x;
int nexty = dir ? 2 * ldPos.y - floor.Key.y : floor.Key.y;
int nextx = dir ? floor.Key.x : Mathf.RoundToInt(2 * ldPos.x - floor.Key.x);
int nexty = dir ? Mathf.RoundToInt(2 * ldPos.y - floor.Key.y) : floor.Key.y;
MapManager.inst.currentMap.CreateFloor(new Vector2Int(nextx, nexty));
yield return null;
}
}
}
foreach (var obj in MapManager.inst.currentMap.objectGrid)
//Debug.Log(i + "th Floor End");
foreach (var obj in copyObjGrid)
{
if ((dir ? obj.Key.y : obj.Key.x) == i)
{
if (IsInRay(parRay, PointToParRay(stPos, obj.Value.GetPos(), true)))
if (IsInRay(parRay, PointToParRay(stPos, obj.Key, true)))
{
/*copy object*/
int nextx = dir ? obj.Key.x : Mathf.RoundToInt(2 * ldPos.x - obj.Key.x);
int nexty = dir ? Mathf.RoundToInt(2 * ldPos.y - obj.Key.y) : obj.Key.y;
ObjType type = obj.Value.GetType();
MapManager.inst.currentMap.CreateObject(new Vector2Int(nextx, nexty), type, (type == ObjType.Mannequin ? ((Mannequin)(obj.Value)).isWhite : true));
yield return null;
}
}
}
foreach (var wall in MapManager.inst.currentMap.wallGrid)
//Debug.Log(i + "th Object End");
float rangeL = i - 0.25f * side;
float rangeR = i + 0.25f * side;
foreach (var wall in copyWallGrid)
{
if ((dir ? wall.Key.y : wall.Key.x) == i)
float wallPos = (dir ? wall.Key.y : wall.Key.x);
if (wall.Value.GetInstanceID() != GetInstanceID() && (side < 0 ? wallPos < rangeL && wallPos > rangeR : wallPos > rangeL && wallPos < rangeR))
{
Pair<float, float> pair = new Pair<float, float>(PointToParRay(stPos, wall.Value.ldPos, true), PointToParRay(stPos, wall.Value.rdPos, true));
if (pair.l > pair.r) pair = pair.Swap();
if (IsInRay(parRay, pair))
{
/*copy wall*/
float nextx = dir ? wall.Key.x : 2 * mapPos.x - wall.Key.x;
float nexty = dir ? 2 * mapPos.y - wall.Key.y : wall.Key.y;
MapManager.inst.currentMap.CreateWall(new Vector2(nextx, nexty), wall.Value.type);
/*copy wall*/
float nextx = dir ? wall.Key.x : 2 * ldPos.x - wall.Key.x;
float nexty = dir ? 2 * ldPos.y - wall.Key.y : wall.Key.y;
MapManager.inst.currentMap.CreateWall(new Vector2(nextx, nexty), wall.Value.type);
SubtractRay(parRay, pair);
yield return null;
}
}
}
rangeL = i - 0.25f * side + 0.5f;
rangeR = i + 0.25f * side + 0.5f;
foreach (var wall in copyWallGrid)
{
float wallPos = (dir ? wall.Key.y : wall.Key.x);
if (wall.Value.GetInstanceID() != GetInstanceID() && (side < 0 ? wallPos < rangeL && wallPos > rangeR : wallPos > rangeL && wallPos < rangeR))
{
Pair<float, float> pair = new Pair<float, float>(PointToParRay(stPos, wall.Value.ldPos, true), PointToParRay(stPos, wall.Value.rdPos, true));
if (pair.l > pair.r) pair = pair.Swap();
if (IsInRay(parRay, pair))
{
/*copy wall*/
float nextx = dir ? wall.Key.x : 2 * mapPos.x - wall.Key.x;
float nexty = dir ? 2 * mapPos.y - wall.Key.y : wall.Key.y;
MapManager.inst.currentMap.CreateWall(new Vector2(nextx, nexty), wall.Value.type);
SubtractRay(parRay, pair);
SubtractRay(parRay, pair);
yield return null;
}
}
}
//Debug.Log(i + "th Wall End");
}
MapManager.inst.currentMap.RemoveWall(mapPos);
}
/// <summary>
......@@ -104,6 +159,7 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
/// <param name="_sub">ray to subtract</param>
void SubtractRay(List<Pair<float, float>> _parRay, Pair<float, float> _sub)
{
Pair<float, float> toAdd = null;
foreach (Pair<float, float> pair in _parRay)
{
if (pair.r < _sub.l || pair.l > _sub.r) continue;
......@@ -111,19 +167,17 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
for (int i = 0; i < 4; i++) // sort arr
{
float smallest = arr[i];
int smallIdx = i;
int smallest = i;
for (int j = i + 1; j < 4; j++)
{
if (smallest > arr[j])
if (arr[smallest] > arr[j])
{
smallest = arr[j];
smallIdx = j;
smallest = j;
}
}
float temp = arr[i];
arr[i] = smallest;
arr[smallIdx] = temp;
arr[i] = arr[smallest];
arr[smallest] = temp;
}
// subtract
......@@ -137,10 +191,21 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
}
else if (arr[1] == _sub.l && arr[2] == _sub.r)
{
_parRay.Add(new Pair<float, float>(pair.r, _sub.r));
toAdd = new Pair<float, float>(_sub.r, pair.r);
pair.r = _sub.l;
}
}
if (toAdd != null) _parRay.Add(toAdd);
for (int i = 0; i < _parRay.Count; i++)
{
if (_parRay[i].r - _parRay[i].l < 0.001f) _parRay.Remove(_parRay[i]);
}
//Debug.Log("ray to subtract: " + _sub.l + "~" + _sub.r + "\nRay count: " + _parRay.Count);
//foreach (var ray in _parRay)
//{
// Debug.Log("Ray: " + ray.l + "~" + ray.r);
//}
}
/// <summary>
......@@ -182,19 +247,17 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
/// <returns>float value of _chPos is posed</returns>
float PointToParRay(Vector2 _stPos, Vector2 _chPos, bool _isRefl)
{
if (dir) // horizontal
if (dir)
{
float dist = _chPos.y - _stPos.y + (_isRefl ? (ldPos.y - _chPos.y) * 2 : 0);
float spreadLen = len * dist / (ldPos.y - _stPos.y);
float rayStPos = _stPos.x + (ldPos.x - _stPos.x) * dist / (ldPos.y - _stPos.y);
return (_chPos.x - rayStPos) / spreadLen;
float px = (_chPos.x-_stPos.x)*(ldPos.y-_stPos.y)/(_isRefl ? 2*ldPos.y-_chPos.y-_stPos.y : _chPos.y-_stPos.y) + _stPos.x;
//Debug.Log("chPos: " + _chPos + ", output: " + (px - ldPos.x));
return px - ldPos.x;
}
else // vertical
else
{
float dist = _chPos.x - _stPos.x + (_isRefl ? (ldPos.x - _chPos.x) * 2 : 0);
float spreadLen = len * dist / (ldPos.x - _stPos.x);
float rayStPos = _stPos.y + (ldPos.y - _stPos.y) * dist / (ldPos.x - _stPos.x);
return (_chPos.y - rayStPos) / spreadLen;
float py = (_chPos.y - _stPos.y) * (ldPos.x - _stPos.x) / (_isRefl ? 2 * ldPos.x - _chPos.x - _stPos.x : _chPos.x - _stPos.x) + _stPos.y;
//Debug.Log("chPos: " + _chPos + ", output: " + (py - ldPos.y));
return py - ldPos.y;
}
}
}
......@@ -15,13 +15,13 @@ public class Wall : MonoBehaviour
/// Position of this floor at the map.
/// </summary>
public Vector2 mapPos;
public Vector2Int ldPos // left down pos
public Vector2 ldPos // left down pos
{
get { return new Vector2Int((int)mapPos.x, (int)mapPos.y); }
get { return new Vector2(dir ? mapPos.x - 0.5f : mapPos.x , !dir ? mapPos.y - 0.5f : mapPos.y); }
}
public Vector2Int rdPos // right down pos
public Vector2 rdPos // right down pos
{
get { return ldPos + (dir ? new Vector2Int(len, 0) : new Vector2Int(0, len)); }
get { return ldPos + (dir ? new Vector2(len, 0) : new Vector2(0, len)); }
}
public bool dir // false: ver, true: hor
{
......@@ -29,16 +29,4 @@ public class Wall : MonoBehaviour
}
public int len = 1; // length of wall
public WallType type;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
......@@ -5,9 +5,9 @@ using UnityEngine.AI;
public class Player : MonoBehaviour
{
public Vector2Int pos
public Vector2 pos
{
get { return new Vector2Int((int)transform.position.x, (int)transform.position.y); }
get { return new Vector2(currentFloor.mapPos.x, currentFloor.mapPos.y); }
}
Coroutine playerArrivalCheck;
......
......@@ -70,21 +70,16 @@ public class PlayerController : SingletonBehaviour<PlayerController>
void Start()
{
prePos = MapPos;
bulletList.Add(BulletCode.True);
bulletList.Add(BulletCode.True);
bulletList.Add(BulletCode.True);
bulletList.Add(BulletCode.True);
bulletList.Add(BulletCode.True);
bulletList.Add(BulletCode.False);
bulletList.Add(BulletCode.False);
bulletList.Add(BulletCode.False);
bulletList.Add(BulletCode.False);
bulletList.Add(BulletCode.False);
bulletList.Add(BulletCode.Mirror);
bulletList.Add(BulletCode.False);
bulletList.Add(BulletCode.Mirror);
bulletList.Add(BulletCode.False);
bulletList.Add(BulletCode.Mirror);
bulletList.Add(BulletCode.False);
bulletList.Add(BulletCode.Mirror);
bulletList.Add(BulletCode.False);
bulletList.Add(BulletCode.Mirror);
bulletList.Add(BulletCode.False);
}
// Update is called once per frame
......
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