Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
tetra-tower
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Oenos
tetra-tower
Commits
9b987038
Commit
9b987038
authored
Jan 21, 2019
by
18손재민
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
카메라 갈아 엎음. 이제 카메라는 벽에 부딪혀서 벽 밖으로는 조금만 보여주게 되고 그 외 기타 자잘한 오류들 고침
parent
ac70cdfd
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
90 additions
and
147 deletions
+90
-147
DoorInGameDown.prefab
Assets/Prefabs/Rooms/InGameDoor/DoorInGameDown.prefab
+1
-1
DoorInGameLeft.prefab
Assets/Prefabs/Rooms/InGameDoor/DoorInGameLeft.prefab
+1
-1
DoorInGameRight.prefab
Assets/Prefabs/Rooms/InGameDoor/DoorInGameRight.prefab
+1
-1
DoorInGameUp.prefab
Assets/Prefabs/Rooms/InGameDoor/DoorInGameUp.prefab
+1
-1
CameraController.cs
Assets/Scripts/CameraController.cs
+72
-129
GameManager.cs
Assets/Scripts/GameManager.cs
+1
-0
Addons.meta
Assets/Scripts/Item/Addons.meta
+0
-8
MapManager.cs
Assets/Scripts/TetrisMap/MapManager.cs
+5
-3
Room.cs
Assets/Scripts/TetrisMap/Room.cs
+6
-2
TetriminoSpawner.cs
Assets/Scripts/TetrisMap/TetriminoSpawner.cs
+2
-1
No files found.
Assets/Prefabs/Rooms/InGameDoor/DoorInGameDown.prefab
View file @
9b987038
...
...
@@ -23,7 +23,7 @@ GameObject:
-
component
:
{
fileID
:
95049867913064836
}
-
component
:
{
fileID
:
60595704614928888
}
-
component
:
{
fileID
:
114295912794569440
}
m_Layer
:
8
m_Layer
:
12
m_Name
:
DoorInGameDown
m_TagString
:
Untagged
m_Icon
:
{
fileID
:
0
}
...
...
Assets/Prefabs/Rooms/InGameDoor/DoorInGameLeft.prefab
View file @
9b987038
...
...
@@ -23,7 +23,7 @@ GameObject:
-
component
:
{
fileID
:
95177593216515702
}
-
component
:
{
fileID
:
60996771576975244
}
-
component
:
{
fileID
:
114082229687600582
}
m_Layer
:
8
m_Layer
:
12
m_Name
:
DoorInGameLeft
m_TagString
:
Untagged
m_Icon
:
{
fileID
:
0
}
...
...
Assets/Prefabs/Rooms/InGameDoor/DoorInGameRight.prefab
View file @
9b987038
...
...
@@ -23,7 +23,7 @@ GameObject:
-
component
:
{
fileID
:
95627112181051082
}
-
component
:
{
fileID
:
60158907655368212
}
-
component
:
{
fileID
:
114434671980411926
}
m_Layer
:
8
m_Layer
:
12
m_Name
:
DoorInGameRight
m_TagString
:
Untagged
m_Icon
:
{
fileID
:
0
}
...
...
Assets/Prefabs/Rooms/InGameDoor/DoorInGameUp.prefab
View file @
9b987038
...
...
@@ -23,7 +23,7 @@ GameObject:
-
component
:
{
fileID
:
95785122911416600
}
-
component
:
{
fileID
:
60354718583369946
}
-
component
:
{
fileID
:
114142621642518908
}
m_Layer
:
8
m_Layer
:
12
m_Name
:
DoorInGameUp
m_TagString
:
Untagged
m_Icon
:
{
fileID
:
0
}
...
...
Assets/Scripts/CameraController.cs
View file @
9b987038
...
...
@@ -3,33 +3,21 @@ using System.Collections.Generic;
using
UnityEngine
;
public
class
CameraController
:
MonoBehaviour
{
public
MapManager
mapManager
;
public
LayerMask
roomLayer
;
public
GameObject
player
;
/// <summary>
/// Coroutine controls scene changing.
/// </summary>
public
static
Coroutine
sceneChanger
;
/// <summary>
/// Check if scene is changing now.
/// </summary>
public
static
bool
isSceneChanging
=
false
;
/// <summary>
/// Coroutine controls room fade in when camera zoom in.
/// </summary>
Coroutine
fadeIn
;
/// <summary>
/// Coroutine controls room fade out when camera zoom out.
/// </summary>
Coroutine
fadeOut
;
readonly
float
camX
=
9.5f
;
readonly
float
camY
=
4f
;
const
float
cameraXLimit
=
4.5f
;
const
float
cameraYLimit
=
3f
;
public
Vector3
tetrisCameraCoord
=
new
Vector3
(
108
,
240
,
-
1
);
public
Vector3
originPos
;
public
const
float
tetrisCameraSize
=
300f
;
public
const
float
inGameCameraSize
=
4.5f
;
public
Vector3
originPos
;
private
void
Awake
()
{
...
...
@@ -43,14 +31,18 @@ public class CameraController : MonoBehaviour {
}
// Update is called once per frame
void
Update
()
void
Late
Update
()
{
GotoDestination
();
if
(
GameManager
.
gameState
==
GameState
.
Ingame
)
originPos
=
player
.
transform
.
position
+
new
Vector3
(
0
,
0
,
-
1
);
{
FollowPlayer
();
originPos
=
transform
.
position
;
}
else
if
(
GameManager
.
gameState
==
GameState
.
Tetris
)
{
originPos
=
tetrisCameraCoord
;
}
}
/// <summary>
/// Shake camera.
...
...
@@ -62,8 +54,8 @@ public class CameraController : MonoBehaviour {
float
amount
=
_amount
;
while
(
amount
>
0
)
{
transform
.
position
=
new
Vector3
(
0.2f
*
Random
.
insideUnitCircle
.
x
*
amount
*
GetComponent
<
Camera
>().
orthographicSize
+
originPos
.
x
,
Random
.
insideUnitCircle
.
y
*
amount
*
GetComponent
<
Camera
>().
orthographicSize
+
originPos
.
y
,
originPos
.
z
)
;
transform
.
position
=
new
Vector3
(
0.2f
*
Random
.
insideUnitCircle
.
x
*
amount
*
GetComponent
<
Camera
>().
orthographicSize
,
Random
.
insideUnitCircle
.
y
*
amount
*
GetComponent
<
Camera
>().
orthographicSize
,
0
)
+
originPos
;
amount
-=
_amount
/
40
;
yield
return
null
;
}
...
...
@@ -84,132 +76,83 @@ public class CameraController : MonoBehaviour {
StartCoroutine
(
mapManager
.
RoomFadeIn
(
MapManager
.
currentRoom
));
grid
.
transform
.
position
=
new
Vector3
(
0
,
0
,
0
);
sizeDestination
=
inGameCameraSize
;
while
(
GetComponent
<
Camera
>().
orthographicSize
>
sizeDestination
+
0.01
)
{
yield
return
null
;
FollowPlayer
();
GetComponent
<
Camera
>().
orthographicSize
=
Mathf
.
Lerp
(
GetComponent
<
Camera
>().
orthographicSize
,
sizeDestination
,
Mathf
.
Sqrt
(
Time
.
deltaTime
));
}
}
else
if
(
GameManager
.
gameState
==
GameState
.
Tetris
)
{
StartCoroutine
(
mapManager
.
RoomFadeOut
(
MapManager
.
currentRoom
));
grid
.
transform
.
position
=
new
Vector3
(
0
,
0
,
2
);
sizeDestination
=
tetrisCameraSize
;
}
while
((
GameManager
.
gameState
==
GameState
.
Tetris
&&
GetComponent
<
Camera
>().
orthographicSize
<
sizeDestination
-
5
)
||
(
GameManager
.
gameState
==
GameState
.
Ingame
&&
GetComponent
<
Camera
>().
orthographicSize
>
sizeDestination
+
0.05
))
while
(
GetComponent
<
Camera
>().
orthographicSize
<
sizeDestination
-
2
)
{
yield
return
null
;
Vector2
coord
=
Vector2
.
Lerp
(
transform
.
position
,
originPos
,
Mathf
.
Sqrt
(
Time
.
deltaTime
));
Vector2
coord
=
Vector2
.
Lerp
(
transform
.
position
,
tetrisCameraCoord
,
Mathf
.
Sqrt
(
Time
.
deltaTime
));
transform
.
position
=
new
Vector3
(
coord
.
x
,
coord
.
y
,
-
1
);
GetComponent
<
Camera
>().
orthographicSize
=
Mathf
.
Lerp
(
GetComponent
<
Camera
>().
orthographicSize
,
sizeDestination
,
Mathf
.
Sqrt
(
Time
.
deltaTime
));
}
transform
.
position
=
originPos
;
transform
.
position
=
tetrisCameraCoord
;
}
GetComponent
<
Camera
>().
orthographicSize
=
sizeDestination
;
isSceneChanging
=
false
;
}
void
GotoDestination
()
{
// TODO: Change this.
/*Vector3 pos = GameObject.Find("Player").transform.position;
pos.z = -1;
transform.position = pos;*/
if
(
GameManager
.
gameState
==
GameState
.
Ingame
&&
isSceneChanging
!=
true
)
{
if
(
MapManager
.
isRoomFalling
!=
true
)
void
FollowPlayer
()
{
float
posx
=
player
.
transform
.
position
.
x
;
float
posy
=
player
.
transform
.
position
.
y
;
if
(!
MapManager
.
currentRoom
.
isRoomCleared
)
{
if
(
RoomCol
(
1
)
!=
-
1
)
{
posy
=
RoomCol
(
1
)
-
camY
;
}
if
(
RoomCol
(
2
)
!=
-
1
)
{
posy
=
RoomCol
(
2
)
+
camY
;
}
if
(
RoomCol
(
3
)
!=
-
1
)
{
posx
=
RoomCol
(
3
)
+
camX
;
}
if
(
RoomCol
(
4
)
!=
-
1
)
{
posx
=
RoomCol
(
4
)
-
camX
;
}
if
(
RoomCol
(
3
)
!=
-
1
&&
RoomCol
(
4
)
!=
-
1
)
if
(
RoomCol
(
"Up"
)
!=
-
1
)
posy
=
RoomCol
(
"Up"
)
-
cameraYLimit
;
if
(
RoomCol
(
"Down"
)
!=
-
1
)
posy
=
RoomCol
(
"Down"
)
+
cameraYLimit
;
if
(
RoomCol
(
"Left"
)
!=
-
1
)
posx
=
RoomCol
(
"Left"
)
+
cameraXLimit
;
if
(
RoomCol
(
"Right"
)
!=
-
1
)
posx
=
RoomCol
(
"Right"
)
-
cameraXLimit
;
if
(
RoomCol
(
"Left"
)
!=
-
1
&&
RoomCol
(
"Right"
)
!=
-
1
)
{
float
middle
=
Player
.
tx
*
24f
+
12f
;
if
(
middle
-
RoomCol
(
3
)
>
20f
)
{
posx
=
RoomCol
(
3
)
+
camX
;
}
else
if
(
RoomCol
(
4
)
-
middle
>
20f
)
{
posx
=
RoomCol
(
4
)
-
camX
;
}
if
(
middle
-
RoomCol
(
"Left"
)
>
20f
)
posx
=
RoomCol
(
"Left"
)
+
cameraXLimit
;
else
if
(
RoomCol
(
"Right"
)
-
middle
>
20f
)
posx
=
RoomCol
(
"Right"
)
-
cameraXLimit
;
else
{
posx
=
player
.
transform
.
position
.
x
;
}
//방의 중심과 비교하여 어느게 더 가까운가
}
if
(
MapManager
.
isRoomFalling
!=
true
)
transform
.
position
=
Vector3
.
Lerp
(
transform
.
position
,
new
Vector3
(
posx
,
posy
,
-
1
),
4f
*
Time
.
deltaTime
);
else
if
(
MapManager
.
isRoomFalling
==
true
)
transform
.
position
=
Vector3
.
Lerp
(
transform
.
position
,
new
Vector3
(
posx
,
posy
,
-
1
),
0.9f
);
transform
.
position
=
new
Vector3
(
transform
.
position
.
x
,
transform
.
position
.
y
,
-
1
);
}
float
RoomCol
(
string
direction
)
{
Vector2
position
=
player
.
transform
.
position
;
switch
(
direction
)
{
case
"Up"
:
if
(
position
.
y
+
cameraYLimit
>=
MapManager
.
tetrisYCoord
[(
int
)
MapManager
.
currentRoom
.
mapCoord
.
y
]
+
23f
)
return
MapManager
.
tetrisYCoord
[(
int
)
MapManager
.
currentRoom
.
mapCoord
.
y
]
+
23f
;
break
;
case
"Down"
:
if
(
position
.
y
-
cameraYLimit
<=
MapManager
.
tetrisYCoord
[(
int
)
MapManager
.
currentRoom
.
mapCoord
.
y
]
+
1f
)
return
MapManager
.
tetrisYCoord
[(
int
)
MapManager
.
currentRoom
.
mapCoord
.
y
]
+
1f
;
break
;
case
"Left"
:
if
(
position
.
x
-
cameraXLimit
<=
Player
.
tx
*
24f
+
1
)
return
Player
.
tx
*
24f
+
1
;
break
;
case
"Right"
:
if
(
position
.
x
+
cameraXLimit
>=
(
Player
.
tx
+
1
)
*
24f
-
1
)
return
(
Player
.
tx
+
1
)
*
24f
-
1
;
break
;
}
transform
.
position
=
Vector3
.
Lerp
(
transform
.
position
,
new
Vector3
(
posx
,
posy
,
-
1
),
2f
*
Time
.
deltaTime
);
transform
.
position
=
new
Vector3
(
transform
.
position
.
x
,
transform
.
position
.
y
,
-
1
);
//카메라를 원래 z축으로 이동
}
else
if
(
MapManager
.
isRoomFalling
==
true
)
{
transform
.
position
=
player
.
transform
.
position
+
new
Vector3
(
0
,
0.2f
,
-
1
);
}
}
// Camera.main.transform.position = new Vector3(posx, posy, -10);
}
float
RoomCol
(
int
dir
)
{
//1:up
//2:down
//3:left
//4:right
if
(!(
dir
>=
0
&&
dir
<=
4
))
return
-
1
;
float
distance
=
0f
;
Vector2
direction
=
Vector2
.
up
;
Vector2
position
=
new
Vector2
(
player
.
transform
.
position
.
x
,
player
.
transform
.
position
.
y
);
if
(
dir
==
1
)
{
direction
=
Vector2
.
up
;
distance
=
camY
;
}
if
(
dir
==
2
)
{
direction
=
Vector2
.
down
;
distance
=
camY
;
}
if
(
dir
==
3
)
{
direction
=
Vector2
.
left
;
distance
=
camX
;
}
if
(
dir
==
4
)
{
direction
=
Vector2
.
right
;
distance
=
camX
;
}
RaycastHit2D
hit1
=
Physics2D
.
Raycast
(
position
,
direction
,
distance
,
roomLayer
);
//Debug.DrawRay(position, direction,Color.yellow);
if
(
hit1
.
collider
!=
null
)
{
if
(
dir
==
1
||
dir
==
2
)
return
hit1
.
point
.
y
;
else
return
hit1
.
point
.
x
;
}
return
-
1
;
}
}
\ No newline at end of file
Assets/Scripts/GameManager.cs
View file @
9b987038
...
...
@@ -16,6 +16,7 @@ public class GameManager : MonoBehaviour {
GameObject
.
Find
(
"TetriminoSpawner"
).
GetComponent
<
TetriminoSpawner
>().
MakeInitialTetrimino
();
Vector2
coord
=
MapManager
.
currentRoom
.
transform
.
position
;
GameObject
.
Find
(
"Player"
).
transform
.
position
=
new
Vector2
(
coord
.
x
,
coord
.
y
)
+
new
Vector2
(
3
,
3
);
GameObject
.
Find
(
"Main Camera"
).
transform
.
position
=
GameObject
.
Find
(
"Player"
).
transform
.
position
;
}
// Update is called once per frame
...
...
Assets/Scripts/Item/Addons.meta
deleted
100644 → 0
View file @
ac70cdfd
fileFormatVersion: 2
guid: 3eeb43e73bfaf1f48901afcdbe4f6d11
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/TetrisMap/MapManager.cs
View file @
9b987038
...
...
@@ -76,11 +76,11 @@ public class MapManager : MonoBehaviour {
/// <summary>
/// Check if this row is being deleted.
/// </summary>
p
rivate
static
bool
[]
isRowDeleting
=
new
bool
[
20
];
p
ublic
static
bool
[]
isRowDeleting
=
new
bool
[
20
];
/// <summary>
/// Tetris Y axis coordinates on Unity.
/// </summary>
p
rivate
static
float
[]
tetrisYCoord
=
new
float
[
height
];
p
ublic
static
float
[]
tetrisYCoord
=
new
float
[
height
];
/// <summary>
/// Array that saves presses.
/// </summary>
...
...
@@ -292,6 +292,8 @@ public class MapManager : MonoBehaviour {
mapGrid
[
doorCloseCounter
,
row
].
CloseDoor
(
"Down"
,
false
);
mapGrid
[
width
-
doorCloseCounter
-
1
,
row
].
CloseDoor
(
"Up"
,
false
);
mapGrid
[
width
-
doorCloseCounter
-
1
,
row
].
CloseDoor
(
"Down"
,
false
);
mapGrid
[
doorCloseCounter
,
row
].
isRoomDestroyed
=
true
;
mapGrid
[
width
-
doorCloseCounter
-
1
,
row
].
isRoomDestroyed
=
true
;
doorCloseCounter
++;
}
if
(
collapseRate
-
roomDestroyCounter
*
0.2f
>
0.2f
)
...
...
@@ -415,6 +417,7 @@ public class MapManager : MonoBehaviour {
SetRoomsYCoord
();
if
(
currentRoom
.
mapCoord
.
y
>=
bottom
)
player
.
transform
.
position
+=
new
Vector3
(
0
,
-
yFallSpeed
,
0
);
previousPlayerRelativePosition
=
player
.
transform
.
position
-
currentRoom
.
transform
.
position
;
}
if
(
shakeCamera
)
{
...
...
@@ -908,6 +911,5 @@ public class MapManager : MonoBehaviour {
}
else
Debug
.
Log
(
"Game Over"
);
}
}
Assets/Scripts/TetrisMap/Room.cs
View file @
9b987038
...
...
@@ -80,6 +80,10 @@ public class Room : MonoBehaviour
/// Check if room is clear and escapable.
/// </summary>
public
bool
isRoomCleared
;
/// <summary>
/// Check if room is destroyed.
/// </summary>
public
bool
isRoomDestroyed
=
false
;
/*
* functions
...
...
@@ -138,7 +142,7 @@ public class Room : MonoBehaviour
switch
(
direction
)
{
case
"Up"
:
if
(
mapCoord
.
y
<
MapManager
.
realHeight
&&
MapManager
.
mapGrid
[(
int
)
mapCoord
.
x
,
(
int
)
mapCoord
.
y
+
1
]
!=
null
)
if
(
mapCoord
.
y
<
MapManager
.
realHeight
&&
MapManager
.
mapGrid
[(
int
)
mapCoord
.
x
,
(
int
)
mapCoord
.
y
+
1
]
!=
null
&&
MapManager
.
mapGrid
[(
int
)
mapCoord
.
x
,
(
int
)
mapCoord
.
y
+
1
].
isRoomDestroyed
!=
true
)
{
door
=
inGameDoorUp
;
animatorThisRoom
=
door
.
GetComponent
<
Animator
>();
...
...
@@ -146,7 +150,7 @@ public class Room : MonoBehaviour
}
break
;
case
"Down"
:
if
(
mapCoord
.
y
>
0
&&
MapManager
.
mapGrid
[(
int
)
mapCoord
.
x
,
(
int
)
mapCoord
.
y
-
1
]
!=
null
)
if
(
mapCoord
.
y
>
0
&&
MapManager
.
mapGrid
[(
int
)
mapCoord
.
x
,
(
int
)
mapCoord
.
y
-
1
]
!=
null
&&
MapManager
.
mapGrid
[(
int
)
mapCoord
.
x
,
(
int
)
mapCoord
.
y
-
1
].
isRoomDestroyed
!=
true
)
{
door
=
inGameDoorDown
;
animatorThisRoom
=
door
.
GetComponent
<
Animator
>();
...
...
Assets/Scripts/TetrisMap/TetriminoSpawner.cs
View file @
9b987038
...
...
@@ -85,7 +85,7 @@ public class TetriminoSpawner : MonoBehaviour {
int
randomPosition
=
Random
.
Range
(
0
,
MapManager
.
width
);
int
randomTetrimino
=
TetriminoRandomizer
();
MapManager
.
currentTetrimino
=
Instantiate
(
tetriminoes
[
randomTetrimino
],
MapManager
.
tetrisMapCoord
+
MapManager
.
tetrisMapSize
*
new
Vector3
(
randomPosition
,
0
,
MapManager
.
tetrisMapCoord
.
z
),
Quaternion
.
identity
);
MapManager
.
currentRoom
=
MapManager
.
currentTetrimino
.
rooms
[
Random
.
Range
(
0
,
MapManager
.
currentTetrimino
.
rooms
.
Length
)
];
MapManager
.
currentRoom
=
MapManager
.
currentTetrimino
.
rooms
[
0
];
MapManager
.
currentRoom
.
specialRoomType
=
RoomType
.
Start
;
MapManager
.
currentTetrimino
.
mapCoord
=
(
MapManager
.
currentTetrimino
.
transform
.
position
-
MapManager
.
tetrisMapCoord
)
/
MapManager
.
tetrisMapSize
;
mapManager
.
SetRoomMapCoord
(
MapManager
.
currentTetrimino
);
...
...
@@ -103,6 +103,7 @@ public class TetriminoSpawner : MonoBehaviour {
mapManager
.
CreateRoom
(
MapManager
.
currentTetrimino
);
MapManager
.
currentRoom
.
fog
.
GetComponent
<
SpriteRenderer
>().
color
=
new
Color
(
1
,
1
,
1
,
0
);
MapManager
.
currentRoom
.
GetComponent
<
SpriteRenderer
>().
sprite
=
mapManager
.
roomsSpritesDistributed
[
MapManager
.
currentStage
][(
int
)
RoomSpriteType
.
Current
];
MapManager
.
currentRoom
.
ClearRoom
();
MapManager
.
tempRoom
=
MapManager
.
currentRoom
;
MakeTetrimino
();
}
...
...
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