Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
man-in-the-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MIM
man-in-the-mirror
Commits
8345d690
Commit
8345d690
authored
Jun 19, 2019
by
18신대성
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mirror에서 Ray코드들 손봄, 아직 거짓탄 문제가 좀 있음
parent
28e95c00
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
44 deletions
+49
-44
Mirror.cs
Assets/Scripts/Map/Mirror.cs
+43
-42
Player.cs
Assets/Scripts/Player.cs
+6
-2
No files found.
Assets/Scripts/Map/Mirror.cs
View file @
8345d690
...
...
@@ -14,7 +14,7 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
{
if
(
bullet
is
FakeBullet
)
{
Debug
.
Log
(
l
dPos
);
Debug
.
Log
(
"ldPos: "
+
ldPos
+
", rdPos: "
+
r
dPos
);
// Make reflected objects
StartCoroutine
(
CopyObjects
(
PlayerController
.
inst
.
currentPlayer
));
//Destroy(gameObject, 1f);
...
...
@@ -27,7 +27,8 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
/// <param name="_shooter">transform of shooter</param>
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
)
...
...
@@ -44,10 +45,6 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
yield
return
null
;
}
}
foreach
(
var
ray
in
parRay
)
{
Debug
.
Log
(
"Ray: "
+
ray
.
l
+
"~"
+
ray
.
r
);
}
// check after reflect, if obj or floor, copy else if wall or mirror, Subtract
int
side
,
i
;
...
...
@@ -75,37 +72,35 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
int
nextx
=
dir
?
floor
.
Key
.
x
:
2
*
ldPos
.
x
-
floor
.
Key
.
x
;
int
nexty
=
dir
?
2
*
ldPos
.
y
-
floor
.
Key
.
y
:
floor
.
Key
.
y
;
MapManager
.
inst
.
currentMap
.
CreateFloor
(
new
Vector2Int
(
nextx
,
nexty
));
Debug
.
Log
(
i
+
" "
+
MapManager
.
inst
.
currentMap
.
maxMapSize
);
yield
return
null
;
}
}
}
//foreach (var obj in MapManager.inst.currentMap.objectGrid)
//{
// if ((dir ? obj.Key.y : obj.Key.x) == i)
// {
// if (IsInRay(parRay, PointToParRay(stPos, obj.Value.GetPos(), true)))
// {
// /*copy object*/
// }
// }
//}
//Debug.Log("4");
//foreach (var wall in MapManager.inst.currentMap.wallGrid)
//{
// 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));
// if (pair.l > pair.r) pair = pair.Swap();
foreach
(
var
obj
in
MapManager
.
inst
.
currentMap
.
objectGrid
)
{
if
((
dir
?
obj
.
Key
.
y
:
obj
.
Key
.
x
)
==
i
)
{
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
obj
.
Value
.
GetPos
(),
true
)))
{
/*copy object*/
}
}
}
foreach
(
var
wall
in
MapManager
.
inst
.
currentMap
.
wallGrid
)
{
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
));
if
(
pair
.
l
>
pair
.
r
)
pair
=
pair
.
Swap
();
//
/*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);
/*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);
//
}
//
}
SubtractRay
(
parRay
,
pair
);
}
}
}
}
...
...
@@ -120,39 +115,45 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
{
if
(
pair
.
r
<
_sub
.
l
||
pair
.
l
>
_sub
.
r
)
continue
;
float
[]
arr
=
{
pair
.
l
,
pair
.
r
,
_sub
.
l
,
_sub
.
r
};
float
[]
sortArr
=
new
float
[
4
];
for
(
int
i
=
0
;
i
<
4
;
i
++)
// sort arr
{
float
smallest
=
arr
[
i
]
;
int
smallest
=
i
;
for
(
int
j
=
i
+
1
;
j
<
4
;
j
++)
{
if
(
smallest
>
arr
[
j
])
if
(
arr
[
smallest
]
>
arr
[
j
])
{
smallest
=
arr
[
j
]
;
smallest
=
j
;
}
}
sortArr
[
i
]
=
smallest
;
float
temp
=
arr
[
i
];
arr
[
i
]
=
arr
[
smallest
];
arr
[
smallest
]
=
temp
;
}
// subtract
if
(
sortArr
[
0
]
==
_sub
.
l
&&
sortA
rr
[
2
]
==
_sub
.
r
)
if
(
arr
[
0
]
==
_sub
.
l
&&
a
rr
[
2
]
==
_sub
.
r
)
{
pair
.
l
=
_sub
.
r
;
}
else
if
(
sortArr
[
1
]
==
_sub
.
l
&&
sortA
rr
[
3
]
==
_sub
.
r
)
else
if
(
arr
[
1
]
==
_sub
.
l
&&
a
rr
[
3
]
==
_sub
.
r
)
{
pair
.
r
=
_sub
.
l
;
}
else
if
(
sortArr
[
1
]
==
_sub
.
l
&&
sortA
rr
[
2
]
==
_sub
.
r
)
else
if
(
arr
[
1
]
==
_sub
.
l
&&
a
rr
[
2
]
==
_sub
.
r
)
{
_parRay
.
Add
(
new
Pair
<
float
,
float
>(
_sub
.
r
,
pair
.
r
));
pair
.
r
=
_sub
.
l
;
}
}
Debug
.
Log
(
"Ray count: "
+
_parRay
.
Count
);
foreach
(
var
ray
in
_parRay
)
{
Debug
.
Log
(
"Ray: "
+
ray
.
l
+
"~"
+
ray
.
r
);
}
for
(
int
i
=
0
;
i
<
_parRay
.
Count
;
i
++)
{
if
(
_parRay
[
i
].
r
-
_parRay
[
i
].
l
<
0.01f
)
_parRay
.
Remove
(
_parRay
[
i
]);
if
(
_parRay
[
i
].
r
-
_parRay
[
i
].
l
<
0.0
0
1f
)
_parRay
.
Remove
(
_parRay
[
i
]);
}
}
...
...
@@ -197,13 +198,13 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
{
if
(
dir
)
{
float
px
=
_chPos
.
x
-
((
_chPos
.
y
-
ldPos
.
y
)
*
(
_chPos
.
x
-
_stPos
.
x
)
/
(
3
*
_chPos
.
y
-
2
*
ldPos
.
y
-
_stPos
.
y
))
;
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
(
"PointToParRay x: "
+
(
px
-
ldPos
.
x
)
+
" pos: "
+
_chPos
);
return
px
-
ldPos
.
x
;
}
else
{
float
py
=
_chPos
.
y
-
((
_chPos
.
x
-
ldPos
.
x
)
*
(
_chPos
.
y
-
_stPos
.
y
)
/
(
3
*
_chPos
.
x
-
2
*
ldPos
.
x
-
_stPos
.
x
))
;
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
(
"PointToParRay y: "
+
(
py
-
ldPos
.
y
)
+
" pos: "
+
_chPos
);
return
py
-
ldPos
.
y
;
}
...
...
Assets/Scripts/Player.cs
View file @
8345d690
...
...
@@ -5,9 +5,13 @@ using UnityEngine.AI;
public
class
Player
:
MonoBehaviour
{
public
Vector2Int
p
os
public
Vector2Int
ldP
os
{
get
{
return
new
Vector2Int
((
int
)
transform
.
position
.
x
,
(
int
)
transform
.
position
.
y
);
}
get
{
return
new
Vector2Int
(
currentFloor
.
mapPos
.
x
,
currentFloor
.
mapPos
.
y
);
}
}
public
Vector2
pos
{
get
{
return
ldPos
+
new
Vector2
(
0.5f
,
0.5f
);
}
}
Coroutine
playerArrivalCheck
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment