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
28e95c00
Commit
28e95c00
authored
Jun 13, 2019
by
18손재민
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
거울 코드 체크중 WIP
parent
e4373b4d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
59 deletions
+64
-59
Mirror.cs
Assets/Scripts/Map/Mirror.cs
+58
-47
Wall.cs
Assets/Scripts/Map/Wall.cs
+2
-2
PlayerController.cs
Assets/Scripts/PlayerController.cs
+4
-10
No files found.
Assets/Scripts/Map/Mirror.cs
View file @
28e95c00
...
...
@@ -14,8 +14,10 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
{
if
(
bullet
is
FakeBullet
)
{
Debug
.
Log
(
ldPos
);
// Make reflected objects
CopyObjects
(
PlayerController
.
inst
.
currentPlayer
);
StartCoroutine
(
CopyObjects
(
PlayerController
.
inst
.
currentPlayer
));
//Destroy(gameObject, 1f);
}
}
...
...
@@ -23,7 +25,7 @@ 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
List
<
Pair
<
float
,
float
>>
parRay
=
new
List
<
Pair
<
float
,
float
>>
...
...
@@ -34,13 +36,18 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
// check before reflect (check walls and mirrors)
foreach
(
var
wall
in
MapManager
.
inst
.
currentMap
.
wallGrid
)
{
if
(
wall
.
Value
.
mapPos
!=
mapPos
)
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
;
}
}
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
;
...
...
@@ -54,46 +61,51 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
side
=
(
ldPos
.
x
-
stPos
.
x
>
0
)
?
-
1
:
1
;
i
=
ldPos
.
x
;
}
for
(;
i
<
MapManager
.
inst
.
currentMap
.
maxMapSize
;
i
+=
side
)
yield
return
null
;
for
(;
Mathf
.
Abs
(
i
)
<
MapManager
.
inst
.
currentMap
.
maxMapSize
;
i
+=
side
)
{
foreach
(
var
floor
in
MapManager
.
inst
.
currentMap
.
floorGrid
)
{
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
;
MapManager
.
inst
.
currentMap
.
CreateFloor
(
new
Vector2Int
(
nextx
,
nexty
));
}
}
}
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
();
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();
/*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);
//
}
//
}
}
}
...
...
@@ -108,39 +120,40 @@ 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
smallIdx
=
i
;
for
(
int
j
=
i
+
1
;
j
<
4
;
j
++)
{
if
(
smallest
>
arr
[
j
])
{
smallest
=
arr
[
j
];
smallIdx
=
j
;
}
}
float
temp
=
arr
[
i
];
arr
[
i
]
=
smallest
;
arr
[
smallIdx
]
=
temp
;
sortArr
[
i
]
=
smallest
;
}
// subtract
if
(
arr
[
0
]
==
_sub
.
l
&&
a
rr
[
2
]
==
_sub
.
r
)
if
(
sortArr
[
0
]
==
_sub
.
l
&&
sortA
rr
[
2
]
==
_sub
.
r
)
{
pair
.
l
=
_sub
.
r
;
}
else
if
(
arr
[
1
]
==
_sub
.
l
&&
a
rr
[
3
]
==
_sub
.
r
)
else
if
(
sortArr
[
1
]
==
_sub
.
l
&&
sortA
rr
[
3
]
==
_sub
.
r
)
{
pair
.
r
=
_sub
.
l
;
}
else
if
(
arr
[
1
]
==
_sub
.
l
&&
a
rr
[
2
]
==
_sub
.
r
)
else
if
(
sortArr
[
1
]
==
_sub
.
l
&&
sortA
rr
[
2
]
==
_sub
.
r
)
{
_parRay
.
Add
(
new
Pair
<
float
,
float
>(
pair
.
r
,
_sub
.
r
));
_parRay
.
Add
(
new
Pair
<
float
,
float
>(
_sub
.
r
,
pair
.
r
));
pair
.
r
=
_sub
.
l
;
}
}
for
(
int
i
=
0
;
i
<
_parRay
.
Count
;
i
++)
{
if
(
_parRay
[
i
].
r
-
_parRay
[
i
].
l
<
0.01f
)
_parRay
.
Remove
(
_parRay
[
i
]);
}
}
/// <summary>
...
...
@@ -182,19 +195,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
-
((
_chPos
.
y
-
ldPos
.
y
)
*
(
_chPos
.
x
-
_stPos
.
x
)
/
(
3
*
_chPos
.
y
-
2
*
ldPos
.
y
-
_stPos
.
y
));
Debug
.
Log
(
"PointToParRay x: "
+
(
px
-
ldPos
.
x
)
+
" pos: "
+
_chPos
);
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
-
((
_chPos
.
x
-
ldPos
.
x
)
*
(
_chPos
.
y
-
_stPos
.
y
)
/
(
3
*
_chPos
.
x
-
2
*
ldPos
.
x
-
_stPos
.
x
));
Debug
.
Log
(
"PointToParRay y: "
+
(
py
-
ldPos
.
y
)
+
" pos: "
+
_chPos
);
return
py
-
ldPos
.
y
;
}
}
}
Assets/Scripts/Map/Wall.cs
View file @
28e95c00
...
...
@@ -17,7 +17,7 @@ public class Wall : MonoBehaviour
public
Vector2
mapPos
;
public
Vector2Int
ldPos
// left down pos
{
get
{
return
new
Vector2Int
((
int
)
mapPos
.
x
,
(
int
)
mapPos
.
y
);
}
get
{
return
new
Vector2Int
((
int
)
(
mapPos
.
x
+
0.5f
),
(
int
)(
mapPos
.
y
+
0.5f
)
);
}
}
public
Vector2Int
rdPos
// right down pos
{
...
...
Assets/Scripts/PlayerController.cs
View file @
28e95c00
...
...
@@ -70,21 +70,15 @@ 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
.
Mirror
);
bulletList
.
Add
(
BulletCode
.
Mirror
);
bulletList
.
Add
(
BulletCode
.
False
);
bulletList
.
Add
(
BulletCode
.
False
);
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
.
Mirror
);
bulletList
.
Add
(
BulletCode
.
Mirror
);
bulletList
.
Add
(
BulletCode
.
Mirror
);
bulletList
.
Add
(
BulletCode
.
Mirror
);
}
// Update is called once per frame
...
...
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