Commit 125f9cfe authored by 18신대성's avatar 18신대성

이제 잭슨도 잘 복사되고 없어지고 한다.

parent 613a0acd
...@@ -64,40 +64,59 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -64,40 +64,59 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
yield return null; yield return null;
} }
} }
Dictionary<Vector2Int, Floor> copyFloorGrid = new Dictionary<Vector2Int, Floor>(MapManager.inst.currentMap.floorGrid); 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<Vector2Int, IObject> copyObjGrid = new Dictionary<Vector2Int, IObject>(MapManager.inst.currentMap.objectGrid);
Dictionary<Vector2, Wall> copyWallGrid = new Dictionary<Vector2, Wall>(MapManager.inst.currentMap.wallGrid); Dictionary<Vector2, Wall> copyWallGrid = new Dictionary<Vector2, Wall>(MapManager.inst.currentMap.wallGrid);
List<GameObject> copyPlayers = new List<GameObject>(MapManager.inst.players);
// remove backside of mirror // remove backside of mirror
for (int j = iBack; Mathf.Abs(j) < MapManager.inst.currentMap.maxMapSize; j -= side) for (int j = iBack; Mathf.Abs(j) < MapManager.inst.currentMap.maxMapSize; j -= side)
{ {
foreach (var floor in copyFloorGrid) Debug.Log(j);
foreach (var obj in copyObjGrid)
{ {
if ((dir ? floor.Key.y : floor.Key.x) == j) if ((dir ? obj.Key.y : obj.Key.x) == j)
{ {
if (IsInRay(parRay, PointToParRay(stPos, floor.Key, false))) if (IsInRay(parRay, PointToParRay(stPos, obj.Key, false)))
{ {
/*remove floor*/ /*remove object*/
MapManager.inst.currentMap.RemoveFloor(floor.Key); MapManager.inst.currentMap.RemoveObject(obj.Key);
yield return null; yield return null;
} }
} }
} }
//Debug.Log(i + "th Floor End"); foreach (var ply in copyPlayers)
foreach (var obj in copyObjGrid)
{ {
if ((dir ? obj.Key.y : obj.Key.x) == j) if (ply)
{ {
if (IsInRay(parRay, PointToParRay(stPos, obj.Key, false))) Floor plyFloor = ply.GetComponent<Player>().currentFloor;
if ((dir ? plyFloor.mapPos.y : plyFloor.mapPos.x) == j)
{ {
/*remove object*/
MapManager.inst.currentMap.RemoveObject(obj.Key); if (IsInRay(parRay, PointToParRay(stPos, plyFloor.mapPos, false)))
yield return null; {
/*remove player*/
PlayerController.inst.RemovePlayer(plyFloor.mapPos);
yield return null;
}
} }
} }
} }
//Debug.Log(i + "th Object End"); //Debug.Log(i + "th Object End");
foreach (var floor in copyFloorGrid)
{
if ((dir ? floor.Key.y : floor.Key.x) == j)
{
if (IsInRay(parRay, PointToParRay(stPos, floor.Key, false)))
{
/*remove floor*/
MapManager.inst.currentMap.RemoveFloor(floor.Key);
yield return null;
}
}
}
//Debug.Log(i + "th Floor End");
float rangeL = j - 0.25f * side; float rangeL = j - 0.25f * side;
float rangeR = j + 0.25f * side; float rangeR = j + 0.25f * side;
foreach (var wall in copyWallGrid) foreach (var wall in copyWallGrid)
...@@ -106,6 +125,8 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -106,6 +125,8 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
if (wall.Value.GetInstanceID() != GetInstanceID() && (side < 0 ? wallPos < rangeL && wallPos > rangeR : wallPos > rangeL && wallPos < rangeR)) 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, false), PointToParRay(stPos, wall.Value.rdPos, false)); 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.Swap();
if (IsInRay(parRay, pair.l) && IsInRay(parRay, pair.r)) if (IsInRay(parRay, pair.l) && IsInRay(parRay, pair.r))
{ {
/*remove wall*/ /*remove wall*/
...@@ -136,6 +157,7 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -136,6 +157,7 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
copyFloorGrid = new Dictionary<Vector2Int, Floor>(MapManager.inst.currentMap.floorGrid); copyFloorGrid = new Dictionary<Vector2Int, Floor>(MapManager.inst.currentMap.floorGrid);
copyObjGrid = new Dictionary<Vector2Int, IObject>(MapManager.inst.currentMap.objectGrid); copyObjGrid = new Dictionary<Vector2Int, IObject>(MapManager.inst.currentMap.objectGrid);
copyWallGrid = new Dictionary<Vector2, Wall>(MapManager.inst.currentMap.wallGrid); copyWallGrid = new Dictionary<Vector2, Wall>(MapManager.inst.currentMap.wallGrid);
copyPlayers = new List<GameObject>(MapManager.inst.players);
Debug.Log("Start Reflecting."); Debug.Log("Start Reflecting.");
// check after reflect, if obj or floor, copy else if wall or mirror, Subtract // check after reflect, if obj or floor, copy else if wall or mirror, Subtract
...@@ -172,6 +194,22 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -172,6 +194,22 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
} }
} }
} }
foreach (var ply in copyPlayers)
{
Floor plyFloor = ply.GetComponent<Player>().currentFloor;
if ((dir ? plyFloor.mapPos.y : plyFloor.mapPos.x) == i)
{
if (IsInRay(parRay, PointToParRay(stPos, plyFloor.mapPos, true)))
{
/*copy player*/
int nextx = dir ? plyFloor.mapPos.x : Mathf.RoundToInt(2 * ldPos.x - plyFloor.mapPos.x);
int nexty = dir ? Mathf.RoundToInt(2 * ldPos.y - plyFloor.mapPos.y) : plyFloor.mapPos.y;
PlayerController.inst.CreatePlayer(new Vector2Int(nextx, nexty));
yield return null;
}
}
}
//Debug.Log(i + "th Object End"); //Debug.Log(i + "th Object End");
float rangeL = i - 0.25f * side; float rangeL = i - 0.25f * side;
float rangeR = i + 0.25f * side; float rangeR = i + 0.25f * side;
......
...@@ -29,6 +29,14 @@ public class PlayerController : SingletonBehaviour<PlayerController> ...@@ -29,6 +29,14 @@ public class PlayerController : SingletonBehaviour<PlayerController>
public void CreatePlayer(Floor floor) public void CreatePlayer(Floor floor)
{ {
foreach (var obj in MapManager.inst.players)
{
if (obj.GetComponent<Player>().currentFloor == floor)
{
Debug.Log("there are player on that floor.");
return;
}
}
GameObject player = Instantiate(MapManager.inst.player, floor.transform.position + new Vector3(0, 0.1f, 0), Quaternion.identity); GameObject player = Instantiate(MapManager.inst.player, floor.transform.position + new Vector3(0, 0.1f, 0), Quaternion.identity);
player.GetComponent<Player>().currentFloor = floor; player.GetComponent<Player>().currentFloor = floor;
MapManager.inst.players.Add(player); MapManager.inst.players.Add(player);
...@@ -39,6 +47,54 @@ public class PlayerController : SingletonBehaviour<PlayerController> ...@@ -39,6 +47,54 @@ public class PlayerController : SingletonBehaviour<PlayerController>
} }
CheckCurrentFloors(); CheckCurrentFloors();
} }
public void CreatePlayer(Vector2Int floorPos)
{
if (MapManager.inst.currentMap.floorGrid.TryGetValue(floorPos, out Floor floor))
{
CreatePlayer(floor);
}
else
{
Debug.Log("there are no floor");
}
}
public void RemovePlayer(Floor floor)
{
if (!floor)
{
Debug.Log("there are no floor");
return;
}
List<GameObject> copyPlayers = new List<GameObject>(MapManager.inst.players);
foreach (var obj in copyPlayers)
{
if (obj.GetComponent<Player>().currentFloor == floor)
{
MapManager.inst.players.Remove(obj);
if (GameManager.nPlayer >= 0)
{
MapManager.inst.currentMap.clearConditions[GameManager.nPlayer].count = MapManager.inst.players.Count;
MapManager.inst.currentMap.clearConditions[GameManager.nPlayer].IsDone();
}
Destroy(obj);
CheckCurrentFloors();
return;
}
}
}
public void RemovePlayer(Vector2Int floorPos)
{
if (MapManager.inst.currentMap.floorGrid.TryGetValue(floorPos, out Floor floor))
{
RemovePlayer(floor);
}
else
{
Debug.Log("there are no floor");
}
}
public void CheckCurrentFloors() public void CheckCurrentFloors()
{ {
......
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