Commit a6dc40f5 authored by 18신대성's avatar 18신대성

이제 거울 거의 정상적으로 돌아가긴 함.

ldPos 폐기
WIP
parent 0f052b1b
...@@ -92,7 +92,7 @@ BoxCollider: ...@@ -92,7 +92,7 @@ BoxCollider:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1244481854748732982} m_GameObject: {fileID: 1244481854748732982}
m_Material: {fileID: 0} m_Material: {fileID: 0}
m_IsTrigger: 1 m_IsTrigger: 0
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 1.0000005, y: 1.0000002, z: 0.080003634} m_Size: {x: 1.0000005, y: 1.0000002, z: 0.080003634}
......
...@@ -89,7 +89,7 @@ BoxCollider: ...@@ -89,7 +89,7 @@ BoxCollider:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 337530617404887312} m_GameObject: {fileID: 337530617404887312}
m_Material: {fileID: 0} m_Material: {fileID: 0}
m_IsTrigger: 1 m_IsTrigger: 0
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 1.0000005, y: 1.0000002, z: 0.080003634} m_Size: {x: 1.0000005, y: 1.0000002, z: 0.080003634}
......
...@@ -38,6 +38,7 @@ public class Mannequin : MonoBehaviour, IObject, IBulletInteractor ...@@ -38,6 +38,7 @@ public class Mannequin : MonoBehaviour, IObject, IBulletInteractor
_color = value; _color = value;
} }
} }
public bool isWhite;
public void Interact(Bullet bullet) public void Interact(Bullet bullet)
{ {
...@@ -60,6 +61,7 @@ public class Mannequin : MonoBehaviour, IObject, IBulletInteractor ...@@ -60,6 +61,7 @@ public class Mannequin : MonoBehaviour, IObject, IBulletInteractor
public void SetColor(bool isWhite) public void SetColor(bool isWhite)
{ {
Color = isWhite ? Color.white : Color.black; Color = isWhite ? Color.white : Color.black;
this.isWhite = isWhite;
} }
#region IObject Override #region IObject Override
......
...@@ -14,10 +14,9 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -14,10 +14,9 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
{ {
if (bullet is FakeBullet) if (bullet is FakeBullet)
{ {
Debug.Log("ldPos: " + ldPos + ", rdPos: " + rdPos); Debug.Log("ldPos: " + ldPos + ", rdPos: " + rdPos + ", dir: " + dir);
// Make reflected objects // Make reflected objects
StartCoroutine(CopyObjects(PlayerController.inst.currentPlayer)); StartCoroutine(CopyObjects(PlayerController.inst.currentPlayer));
//Destroy(gameObject, 1f);
} }
} }
...@@ -34,76 +33,97 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -34,76 +33,97 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
new Pair<float, float>(0, 1) new Pair<float, float>(0, 1)
}; };
// check before reflect (check walls and mirrors) int side, i, iReset, stCheck;
foreach (var wall in MapManager.inst.currentMap.wallGrid)
{
if (wall.Value.GetInstanceID() != GetInstanceID())
{
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;
}
}
// check after reflect, if obj or floor, copy else if wall or mirror, Subtract
int side, i;
if (dir) // horizontal, parallel with x if (dir) // horizontal, parallel with x
{ {
side = (ldPos.y - stPos.y > 0) ? -1 : 1; side = (mapPos.y - stPos.y > 0) ? -1 : 1;
i = ldPos.y; i = side > 0 ? Mathf.CeilToInt(mapPos.y) : Mathf.FloorToInt(mapPos.y);
iReset = i;
stCheck = (int)stPos.y;
} }
else // vertical, parallel with y else // vertical, parallel with y
{ {
side = (ldPos.x - stPos.x > 0) ? -1 : 1; side = (mapPos.x - stPos.x > 0) ? -1 : 1;
i = ldPos.x; i = side > 0 ? Mathf.CeilToInt(mapPos.x) : Mathf.FloorToInt(mapPos.x);
iReset = i;
stCheck = (int)stPos.x;
} }
yield return null; yield return null;
for (; Mathf.Abs(i) < MapManager.inst.currentMap.maxMapSize; i += side) // check before reflect (check walls and mirrors)
for (; Mathf.Abs(i) < MapManager.inst.currentMap.maxMapSize && (side > 0 ? i < stCheck : i > stCheck); i += side)
{ {
foreach (var floor in MapManager.inst.currentMap.floorGrid) foreach (var wall in MapManager.inst.currentMap.wallGrid)
{
if (wall.Value.GetInstanceID() != GetInstanceID() && (dir ? wall.Key.y : wall.Key.x) == i)
{
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();
Debug.Log("wall at " + wall.Key);
SubtractRay(parRay, pair);
yield return null;
}
}
}
Debug.Log("Start Reflecting.");
// check after reflect, if obj or floor, copy else if wall or mirror, Subtract
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 copyFloorGrid)
{ {
if ((dir ? floor.Key.y : floor.Key.x) == i) if ((dir ? floor.Key.y : floor.Key.x) == i)
{ {
if (IsInRay(parRay, PointToParRay(stPos, floor.Key, true))) if (IsInRay(parRay, PointToParRay(stPos, floor.Key, true)))
{ {
/*copy floor*/ /*copy floor*/
int nextx = dir ? floor.Key.x : 2 * ldPos.x - floor.Key.x; int nextx = dir ? floor.Key.x : Mathf.RoundToInt(2 * ldPos.x - floor.Key.x);
int nexty = dir ? 2 * ldPos.y - floor.Key.y : floor.Key.y; int nexty = dir ? Mathf.RoundToInt(2 * ldPos.y - floor.Key.y) : floor.Key.y;
MapManager.inst.currentMap.CreateFloor(new Vector2Int(nextx, nexty)); MapManager.inst.currentMap.CreateFloor(new Vector2Int(nextx, nexty));
yield return null; yield return null;
} }
} }
} }
foreach (var obj in MapManager.inst.currentMap.objectGrid) foreach (var obj in copyObjGrid)
{ {
if ((dir ? obj.Key.y : obj.Key.x) == i) 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*/ /*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;
} }
} }
} }
Dictionary<Vector2, Wall> copyGrid = new Dictionary<Vector2, Wall>(MapManager.inst.currentMap.wallGrid); foreach (var wall in copyWallGrid)
foreach (var wall in copyGrid)
{ {
if ((dir ? wall.Key.y : wall.Key.x) == i) if ((dir ? wall.Key.y : wall.Key.x) == i)
{ {
Pair<float, float> pair = new Pair<float, float>(PointToParRay(stPos, wall.Value.ldPos, true), PointToParRay(stPos, wall.Value.rdPos, true)); 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 (pair.l > pair.r) pair = pair.Swap();
/*copy wall*/ if (IsInRay(parRay, pair.l) || IsInRay(parRay, pair.r))
float nextx = dir ? wall.Key.x : 2 * ldPos.x - wall.Key.x; {
float nexty = dir ? 2 * ldPos.y - wall.Key.y : wall.Key.y; /*copy wall*/
MapManager.inst.currentMap.CreateWall(new Vector2(nextx, nexty), wall.Value.type); float nextx = dir ? wall.Key.x : 2 * mapPos.x - wall.Key.x;
Debug.Log("created at " + nextx + ", " + nexty); 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;
}
} }
} }
} }
MapManager.inst.currentMap.RemoveWall(mapPos);
} }
/// <summary> /// <summary>
...@@ -153,7 +173,7 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -153,7 +173,7 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
if (_parRay[i].r - _parRay[i].l < 0.001f) _parRay.Remove(_parRay[i]); if (_parRay[i].r - _parRay[i].l < 0.001f) _parRay.Remove(_parRay[i]);
} }
Debug.Log("Ray count: " + _parRay.Count); Debug.Log("ray to subtract: " + _sub.l + "~" + _sub.r + "\nRay count: " + _parRay.Count);
foreach (var ray in _parRay) foreach (var ray in _parRay)
{ {
Debug.Log("Ray: " + ray.l + "~" + ray.r); Debug.Log("Ray: " + ray.l + "~" + ray.r);
......
...@@ -15,13 +15,13 @@ public class Wall : MonoBehaviour ...@@ -15,13 +15,13 @@ public class Wall : MonoBehaviour
/// Position of this floor at the map. /// Position of this floor at the map.
/// </summary> /// </summary>
public Vector2 mapPos; public Vector2 mapPos;
public Vector2Int ldPos // left down pos public Vector2 ldPos // left down pos
{ {
get { return new Vector2Int((int)(mapPos.x + 0.5f), (int)(mapPos.y + 0.5f)); } 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 public bool dir // false: ver, true: hor
{ {
...@@ -29,16 +29,4 @@ public class Wall : MonoBehaviour ...@@ -29,16 +29,4 @@ public class Wall : MonoBehaviour
} }
public int len = 1; // length of wall public int len = 1; // length of wall
public WallType type; public WallType type;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
} }
...@@ -5,13 +5,9 @@ using UnityEngine.AI; ...@@ -5,13 +5,9 @@ using UnityEngine.AI;
public class Player : MonoBehaviour public class Player : MonoBehaviour
{ {
public Vector2Int ldPos
{
get { return new Vector2Int(currentFloor.mapPos.x, currentFloor.mapPos.y); }
}
public Vector2 pos public Vector2 pos
{ {
get { return ldPos + new Vector2(0.5f, 0.5f); } get { return new Vector2(currentFloor.mapPos.x, currentFloor.mapPos.y); }
} }
Coroutine playerArrivalCheck; Coroutine playerArrivalCheck;
......
...@@ -71,13 +71,14 @@ public class PlayerController : SingletonBehaviour<PlayerController> ...@@ -71,13 +71,14 @@ public class PlayerController : SingletonBehaviour<PlayerController>
{ {
prePos = MapPos; prePos = MapPos;
bulletList.Add(BulletCode.Mirror); bulletList.Add(BulletCode.Mirror);
bulletList.Add(BulletCode.Mirror);
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.False);
bulletList.Add(BulletCode.Mirror);
bulletList.Add(BulletCode.False); bulletList.Add(BulletCode.False);
bulletList.Add(BulletCode.Mirror);
bulletList.Add(BulletCode.False); bulletList.Add(BulletCode.False);
bulletList.Add(BulletCode.Mirror);
bulletList.Add(BulletCode.False); bulletList.Add(BulletCode.False);
} }
......
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