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
af576cf5
Commit
af576cf5
authored
Jul 01, 2019
by
18신대성
Committed by
18손재민
Jul 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pair를 Generic이 아니게 바꿈
parent
b4394627
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
74 deletions
+82
-74
Pair.cs
Assets/Scripts/Generals/Pair.cs
+11
-6
Floor.cs
Assets/Scripts/Map/Floor.cs
+1
-0
Mirror.cs
Assets/Scripts/Map/Mirror.cs
+70
-68
No files found.
Assets/Scripts/Generals/Pair.cs
View file @
af576cf5
...
...
@@ -2,19 +2,24 @@
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
Pair
<
L
,
R
>
public
class
Pair
{
public
L
l
;
public
R
r
;
public
float
l
;
public
float
r
;
public
Pair
(
L
_l
,
R
_r
)
public
Pair
(
float
_l
,
float
_r
)
{
this
.
l
=
_l
;
this
.
r
=
_r
;
}
public
Pair
<
R
,
L
>
Swap
()
public
Pair
Swap
()
{
return
new
Pair
<
R
,
L
>(
r
,
l
);
return
new
Pair
(
r
,
l
);
}
public
Pair
ApplyMargin
(
float
margin
)
{
return
new
Pair
(
l
-
margin
,
r
+
margin
);
}
}
Assets/Scripts/Map/Floor.cs
View file @
af576cf5
...
...
@@ -9,6 +9,7 @@ public class Floor : MonoBehaviour
/// </summary>
public
Vector2Int
mapPos
;
public
bool
isGoalFloor
=
false
;
public
IObject
objOnFloor
=
null
;
// Start is called before the first frame update
void
Start
()
...
...
Assets/Scripts/Map/Mirror.cs
View file @
af576cf5
...
...
@@ -28,9 +28,9 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
{
Vector2
stPos
=
_shooter
.
pos
;
// position of shooter's cell
//Debug.Log("stPos: " + stPos);
List
<
Pair
<
float
,
float
>>
parRay
=
new
List
<
Pair
<
float
,
float
>
>
List
<
Pair
>
parRay
=
new
List
<
Pair
>
{
new
Pair
<
float
,
float
>
(
0
,
1
)
new
Pair
(
0
,
1
)
};
int
side
,
i
,
iBack
,
stCheck
;
...
...
@@ -58,7 +58,7 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
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
));
Pair
pair
=
new
Pair
(
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
;
...
...
@@ -73,12 +73,12 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
// remove backside of mirror
for
(
int
j
=
iBack
;
Mathf
.
Abs
(
j
)
<
MapManager
.
inst
.
currentMap
.
maxMapSize
;
j
-=
side
)
{
Debug
.
Log
(
j
);
//
Debug.Log(j);
foreach
(
var
obj
in
copyObjGrid
)
{
if
((
dir
?
obj
.
Key
.
y
:
obj
.
Key
.
x
)
==
j
)
{
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
obj
.
Key
,
false
)))
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
obj
.
Key
,
false
)
,
-
0.1f
))
{
/*remove object*/
MapManager
.
inst
.
currentMap
.
RemoveObject
(
obj
.
Key
);
...
...
@@ -94,7 +94,7 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
if
((
dir
?
plyFloor
.
mapPos
.
y
:
plyFloor
.
mapPos
.
x
)
==
j
)
{
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
plyFloor
.
mapPos
,
false
)))
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
plyFloor
.
mapPos
,
false
)
,
-
0.1f
))
{
/*remove player*/
PlayerController
.
inst
.
RemovePlayer
(
plyFloor
.
mapPos
);
...
...
@@ -108,7 +108,7 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
{
if
((
dir
?
floor
.
Key
.
y
:
floor
.
Key
.
x
)
==
j
)
{
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
floor
.
Key
,
false
)))
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
floor
.
Key
,
false
)
,
0
))
{
/*remove floor*/
MapManager
.
inst
.
currentMap
.
RemoveFloor
(
floor
.
Key
);
...
...
@@ -124,10 +124,9 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
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
,
false
),
PointToParRay
(
stPos
,
wall
.
Value
.
rdPos
,
false
));
Pair
pair
=
new
Pair
(
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
,
0
))
{
/*remove wall*/
MapManager
.
inst
.
currentMap
.
RemoveWall
(
wall
.
Key
);
...
...
@@ -142,8 +141,9 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
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
,
false
),
PointToParRay
(
stPos
,
wall
.
Value
.
rdPos
,
false
));
if
(
IsInRay
(
parRay
,
pair
.
l
)
&&
IsInRay
(
parRay
,
pair
.
r
))
Pair
pair
=
new
Pair
(
PointToParRay
(
stPos
,
wall
.
Value
.
ldPos
,
false
),
PointToParRay
(
stPos
,
wall
.
Value
.
rdPos
,
false
));
if
(
pair
.
l
>
pair
.
r
)
pair
.
Swap
();
if
(
IsInRay
(
parRay
,
pair
,
0
))
{
/*remove wall*/
MapManager
.
inst
.
currentMap
.
RemoveWall
(
wall
.
Key
);
...
...
@@ -163,11 +163,54 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
// check after reflect, if obj or floor, copy else if wall or mirror, Subtract
for
(;
Mathf
.
Abs
(
i
)
<
MapManager
.
inst
.
currentMap
.
maxMapSize
;
i
+=
side
)
{
float
rangeL
=
i
-
0.25f
*
side
;
float
rangeR
=
i
+
0.25f
*
side
;
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
pair
=
new
Pair
(
PointToParRay
(
stPos
,
wall
.
Value
.
ldPos
,
true
),
PointToParRay
(
stPos
,
wall
.
Value
.
rdPos
,
true
));
if
(
pair
.
l
>
pair
.
r
)
pair
=
pair
.
Swap
();
if
(
IsInRay
(
parRay
,
pair
,
0
))
{
/*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
);
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
pair
=
new
Pair
(
PointToParRay
(
stPos
,
wall
.
Value
.
ldPos
,
true
),
PointToParRay
(
stPos
,
wall
.
Value
.
rdPos
,
true
));
if
(
pair
.
l
>
pair
.
r
)
pair
=
pair
.
Swap
();
if
(
IsInRay
(
parRay
,
pair
,
0
))
{
/*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
);
yield
return
null
;
}
}
}
//Debug.Log(i + "th Wall End");
foreach
(
var
floor
in
copyFloorGrid
)
{
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
)
,
0.5f
))
{
/*copy floor*/
int
nextx
=
dir
?
floor
.
Key
.
x
:
Mathf
.
RoundToInt
(
2
*
ldPos
.
x
-
floor
.
Key
.
x
);
...
...
@@ -182,7 +225,7 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
{
if
((
dir
?
obj
.
Key
.
y
:
obj
.
Key
.
x
)
==
i
)
{
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
obj
.
Key
,
true
)))
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
obj
.
Key
,
true
)
,
0.5f
))
{
/*copy object*/
int
nextx
=
dir
?
obj
.
Key
.
x
:
Mathf
.
RoundToInt
(
2
*
ldPos
.
x
-
obj
.
Key
.
x
);
...
...
@@ -199,7 +242,7 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
Floor
plyFloor
=
ply
.
GetComponent
<
Player
>().
currentFloor
;
if
((
dir
?
plyFloor
.
mapPos
.
y
:
plyFloor
.
mapPos
.
x
)
==
i
)
{
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
plyFloor
.
mapPos
,
true
)))
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
plyFloor
.
mapPos
,
true
)
,
0.5f
))
{
/*copy player*/
int
nextx
=
dir
?
plyFloor
.
mapPos
.
x
:
Mathf
.
RoundToInt
(
2
*
ldPos
.
x
-
plyFloor
.
mapPos
.
x
);
...
...
@@ -211,49 +254,6 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
}
}
//Debug.Log(i + "th Object End");
float
rangeL
=
i
-
0.25f
*
side
;
float
rangeR
=
i
+
0.25f
*
side
;
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
);
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
);
yield
return
null
;
}
}
}
//Debug.Log(i + "th Wall End");
}
MapManager
.
inst
.
currentMap
.
RemoveWall
(
mapPos
);
}
...
...
@@ -263,10 +263,10 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
/// </summary>
/// <param name="_parRay">ray list to subtracted</param>
/// <param name="_sub">ray to subtract</param>
void
SubtractRay
(
List
<
Pair
<
float
,
float
>>
_parRay
,
Pair
<
float
,
float
>
_sub
)
void
SubtractRay
(
List
<
Pair
>
_parRay
,
Pair
_sub
)
{
Pair
<
float
,
float
>
toAdd
=
null
;
foreach
(
Pair
<
float
,
float
>
pair
in
_parRay
)
Pair
toAdd
=
null
;
foreach
(
Pair
pair
in
_parRay
)
{
if
(
pair
.
r
<
_sub
.
l
||
pair
.
l
>
_sub
.
r
)
continue
;
float
[]
arr
=
{
pair
.
l
,
pair
.
r
,
_sub
.
l
,
_sub
.
r
};
...
...
@@ -297,7 +297,7 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
}
else
if
(
arr
[
1
]
==
_sub
.
l
&&
arr
[
2
]
==
_sub
.
r
)
{
toAdd
=
new
Pair
<
float
,
float
>
(
_sub
.
r
,
pair
.
r
);
toAdd
=
new
Pair
(
_sub
.
r
,
pair
.
r
);
pair
.
r
=
_sub
.
l
;
}
}
...
...
@@ -320,12 +320,13 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
/// <param name="_parRay">ray list to be checked</param>
/// <param name="_range">range to check</param>
/// <returns>if _range is included in _parRay, return true</returns>
bool
IsInRay
(
List
<
Pair
<
float
,
float
>>
_parRay
,
Pair
<
float
,
float
>
_range
)
bool
IsInRay
(
List
<
Pair
>
_parRay
,
Pair
_range
,
float
margin
)
{
bool
output
=
false
;
foreach
(
Pair
<
float
,
float
>
pair
in
_parRay
)
foreach
(
Pair
pair
in
_parRay
)
{
if
(
pair
.
r
<=
_range
.
l
||
pair
.
l
>=
_range
.
r
)
continue
;
Pair
temp
=
pair
.
ApplyMargin
(
margin
);
if
(
temp
.
r
<=
_range
.
l
||
temp
.
l
>=
_range
.
r
)
continue
;
else
{
output
=
true
;
...
...
@@ -335,11 +336,12 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
return
output
;
}
bool
IsInRay
(
List
<
Pair
<
float
,
float
>>
_parRay
,
float
_obj
)
bool
IsInRay
(
List
<
Pair
>
_parRay
,
float
_obj
,
float
margin
)
{
foreach
(
Pair
<
float
,
float
>
pair
in
_parRay
)
foreach
(
Pair
pair
in
_parRay
)
{
if
(
pair
.
l
<=
_obj
&&
pair
.
r
>=
_obj
)
return
true
;
Pair
temp
=
pair
.
ApplyMargin
(
margin
);
if
(
temp
.
l
<=
_obj
&&
temp
.
r
>=
_obj
)
return
true
;
}
return
false
;
}
...
...
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