Commit 93a18e68 authored by 18손재민's avatar 18손재민

고스트 오류 수정

parent d12b1be8
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GhostManager : MonoBehaviour {
MapManager MM;
public bool IsRightGhost(Tetrimino te)
{
for (int i = 0; i < te.rooms.Length; i++)
{
if (te.rooms[i].mapCoord.y < 0)
return false;
else if (MapManager.mapGrid[(int)te.rooms[i].mapCoord.x, (int)te.rooms[i].mapCoord.y] != null)
return false;
}
return true;
}
public void GhostDown(Tetrimino ghost, Tetrimino te)
{
while (IsRightGhost(ghost))
{
MM.MoveTetriminoMapCoord(ghost, new Vector3(0, -1, 0));
}
MM.MoveTetriminoMapCoord(ghost, new Vector3(0, 1, 0));
}
private void Awake()
{
MM = GameObject.Find("MapManager").GetComponent<MapManager>();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
MM.currentGhost.mapCoord = MM.currentTetrimino.mapCoord;
for (int i = 0; i < MM.currentGhost.rooms.Length; i++)
{
MM.currentGhost.rooms[i].mapCoord = MM.currentTetrimino.rooms[i].mapCoord;
MM.currentGhost.rooms[i].transform.position = (MM.currentGhost.rooms[i].mapCoord - MM.currentGhost.mapCoord) * MM.tetrisMapSize + MM.currentGhost.transform.position;
}
GhostDown(MM.currentGhost, MM.currentTetrimino);
}
}
fileFormatVersion: 2
guid: 925d029b76b3b254b81e73583f901369
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -110,6 +110,22 @@ public class MapManager : MonoBehaviour { ...@@ -110,6 +110,22 @@ public class MapManager : MonoBehaviour {
return 0; return 0;
} }
/// <summary> /// <summary>
/// Check if ghost is at right place.
/// </summary>
/// <param name="te">Ghost to check</param>
/// <returns>True for right place, false for wrong place</returns>
public bool IsRightGhost(Tetrimino te)
{
for (int i = 0; i < te.rooms.Length; i++)
{
if (te.rooms[i].mapCoord.y < 0)
return false;
else if (MapManager.mapGrid[(int)te.rooms[i].mapCoord.x, (int)te.rooms[i].mapCoord.y] != null)
return false;
}
return true;
}
/// <summary>
/// Make Tetrimino in right X coordinate. /// Make Tetrimino in right X coordinate.
/// </summary> /// </summary>
/// <param name="te">Tetrimino.</param> /// <param name="te">Tetrimino.</param>
...@@ -273,12 +289,22 @@ public class MapManager : MonoBehaviour { ...@@ -273,12 +289,22 @@ public class MapManager : MonoBehaviour {
if (te.rooms[i].mapCoord.y < minY) if (te.rooms[i].mapCoord.y < minY)
minY = te.rooms[i].mapCoord.y; minY = te.rooms[i].mapCoord.y;
} }
te.mapCoord = new Vector3(te.rotatedPosition[te.rotatedAngle], te.mapCoord.y, te.mapCoord.z);
for (int i = 0; i < te.rooms.Length; i++) for (int i = 0; i < te.rooms.Length; i++)
{ {
//te.rooms[i].mapCoord += new Vector3(-(minX - te.mapCoord.x), -(minY - te.mapCoord.y), 0);
te.rooms[i].mapCoord += new Vector3(-(minX - te.mapCoord.x), -(minY - te.mapCoord.y), 0); te.rooms[i].mapCoord += new Vector3(-(minX - te.mapCoord.x), -(minY - te.mapCoord.y), 0);
te.rooms[i].transform.position = (te.rooms[i].mapCoord - te.mapCoord) * tetrisMapSize + te.transform.position; te.rooms[i].transform.position = (te.rooms[i].mapCoord - te.mapCoord) * tetrisMapSize + te.transform.position;
} }
te.mapCoord = new Vector3(te.rotatedPosition[te.rotatedAngle], te.mapCoord.y, te.mapCoord.z); /*for(int i = 0; i < te.rooms.Length; i++)
{
if(te.rooms[i].mapCoord.x > 9)
{
for (int j = 0; j < te.rooms.Length; j++)
te.rooms[i].mapCoord += new Vector3(0, -1, 0);
i = 0;
}
}*/
} }
/// <summary> /// <summary>
/// Move tetrimino as the amount of coord. /// Move tetrimino as the amount of coord.
...@@ -336,11 +362,29 @@ public class MapManager : MonoBehaviour { ...@@ -336,11 +362,29 @@ public class MapManager : MonoBehaviour {
yield return null; yield return null;
} }
} }
//완성해야됨 /// <summary>
/// Get ghost down.
/// </summary>
/// <param name="ghost">Which ghost to move.</param>
/// <param name="te">Which tetrimino you'd like to sink with ghost.</param>
public void GhostDown(Tetrimino ghost, Tetrimino te)
{
/*if(ghost.rotatedAngle != te.rotatedAngle)
TetriminoRotate(ghost, te.rotatedAngle - ghost.rotatedAngle);*/
currentGhost.mapCoord = currentTetrimino.mapCoord;
for (int i = 0; i < currentGhost.rooms.Length; i++)
{
currentGhost.rooms[i].mapCoord = currentTetrimino.rooms[i].mapCoord;
currentGhost.rooms[i].transform.position = (currentGhost.rooms[i].mapCoord - currentGhost.mapCoord) * tetrisMapSize + currentGhost.transform.position;
}
while (IsRightGhost(ghost))
{
MoveTetriminoMapCoord(ghost, new Vector3(0, -1, 0));
}
MoveTetriminoMapCoord(ghost, new Vector3(0, 1, 0));
}
//완성해야됨
...@@ -405,6 +449,7 @@ public class MapManager : MonoBehaviour { ...@@ -405,6 +449,7 @@ public class MapManager : MonoBehaviour {
/* /*
* Test * Test
* */ * */
void Awake() void Awake()
{ {
Tetrimino.rotationInformation[0].horizontalLength = new int[4] { 1, 4, 1, 4 }; //I Tetrimino.rotationInformation[0].horizontalLength = new int[4] { 1, 4, 1, 4 }; //I
...@@ -432,7 +477,7 @@ public class MapManager : MonoBehaviour { ...@@ -432,7 +477,7 @@ public class MapManager : MonoBehaviour {
currentTetrimino.transform.position = new Vector3(currentTetrimino.mapCoord.x * tetrisMapSize, tetrisYCoord[(int)currentTetrimino.mapCoord.y], currentTetrimino.mapCoord.z * tetrisMapSize); currentTetrimino.transform.position = new Vector3(currentTetrimino.mapCoord.x * tetrisMapSize, tetrisYCoord[(int)currentTetrimino.mapCoord.y], currentTetrimino.mapCoord.z * tetrisMapSize);
if(currentGhost != null) if(currentGhost != null)
{ {
//GhostDown(currentGhost, currentTetrimino); GhostDown(currentGhost, currentTetrimino);
currentGhost.transform.position = new Vector3(currentGhost.mapCoord.x * tetrisMapSize, tetrisYCoord[(int)currentGhost.mapCoord.y], currentGhost.mapCoord.z * tetrisMapSize); currentGhost.transform.position = new Vector3(currentGhost.mapCoord.x * tetrisMapSize, tetrisYCoord[(int)currentGhost.mapCoord.y], currentGhost.mapCoord.z * tetrisMapSize);
} }
//currentTetrimino.transform.position = currentTetrimino.mapCoord * tetrisMapSize + tetrisMapCoord; //currentTetrimino.transform.position = currentTetrimino.mapCoord * tetrisMapSize + tetrisMapCoord;
......
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