public IEnumerator Swap(Block b1, Block b2) { POSITION b1Dest = b2.GetPosition(); POSITION b2Dest = b1.GetPosition(); Vector3 b1DestV3 = Util.ConvertMapCoordToWorldCoord(b1Dest, this); Vector3 b2DestV3 = Util.ConvertMapCoordToWorldCoord(b2Dest, this); b1.SetPosition(b1Dest); b2.SetPosition(b2Dest); Map[b1Dest.y, b1Dest.x] = b1; Map[b2Dest.y, b2Dest.x] = b2; while (true) { bool b1Arrived = b1DestV3 == b1.GetMonoBlock().transform.position; bool b2Arrived = b2DestV3 == b2.GetMonoBlock().transform.position; if (b1Arrived && b2Arrived) { yield break; } b1.MoveMonoBlockToTarget(b1DestV3); b2.MoveMonoBlockToTarget(b2DestV3); yield return(null); } }
public static Vector3 ConvertMapCoordToWorldCoord(POSITION mapCoord, MapGenerater mg) { Vector3 result; result.x = mg.MapStartPosition.x + mapCoord.x * mg.CellSize.x; result.y = mg.MapStartPosition.y + mapCoord.y * mg.CellSize.y; result.z = 0f; return(result); }
public void SwapBlock(POSITION first, POSITION second) { Block temp = mg.map[first.y, first.x]; mg.map[first.y, first.x] = mg.map[second.y, second.x]; mg.map[second.y, second.x] = temp; //IngameDebugger.AddLog($"Swap ({first.y},{first.x}) , ({second.y},{second.x} ) "); //swapedBlock[0] = first; //swapedBlock[1] = second; }
public bool IsOutOfRange(POSITION value) { return((value.x < 0 || width >= value.x) && (value.y < 0 || height >= value.y)); }
private void Update() { if (!EnableInput) { return; } if (Input.GetButtonDown("Fire1")) { PointerEventData ped = new PointerEventData(null); List <RaycastResult> rayResults = new List <RaycastResult>(); ped.position = Input.mousePosition; gr.Raycast(ped, rayResults); Block selectedBlock = null; for (int i = 0; i < rayResults.Count; i++) { var monoBlock = rayResults[i].gameObject.GetComponent <MonoBlock>(); if (null != monoBlock) { selectedBlock = monoBlock.parent; break; } } if (null == selectedBlock) { return; } //var worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); POSITION mapPos = selectedBlock.GetPosition(); if (null != mg.Map[mapPos.y, mapPos.x]) { if (null == first) { first = mg.Map[mapPos.y, mapPos.x]; cursor.transform.position = first.GetMonoBlock().transform.position; cursor.gameObject.SetActive(true); } else { int deltaAbsX = Math.Abs(mapPos.x - first.GetPosition().x); int deltaAbsY = Math.Abs(mapPos.y - first.GetPosition().y); //대각선 이동은 허용하지 않는다. if (deltaAbsX == 1 && deltaAbsY == 1) { return; } if (first.GetPosition() == mapPos) { //cursor reset first = null; second = null; cursor.gameObject.SetActive(false); return; } second = mg.Map[mapPos.y, mapPos.x]; cursor.gameObject.SetActive(false); } } } }
HashSet <POSITION> GetRemovedPositions() { willBeRemovedBlocks.Clear(); //check line //will be optimized positions.Clear(); for (int y = 0; y < mg.Height; y++) { for (int x = 0; x < mg.Width; x++) { if (null == mg.Map[y, x]) { continue; } positions.Add(mg.Map[y, x].GetPosition()); } } for (int i = 0; i < positions.Count; i++) { for (int x = 0; x < mg.Width - 2; ++x) { POSITION px1 = new POSITION(x, positions[i].y); POSITION px2 = new POSITION(x + 1, positions[i].y); POSITION px3 = new POSITION(x + 2, positions[i].y); if (null == mg.Map[px1.y, px1.x] || null == mg.Map[px2.y, px2.x] || null == mg.Map[px3.y, px3.x]) { continue; } //yield return new WaitForSeconds(debugDelay); mg.Map[px1.y, px1.x].SetMarking(true); mg.Map[px2.y, px2.x].SetMarking(true); mg.Map[px3.y, px3.x].SetMarking(true); E_TileType t1 = mg.Map[px1.y, px1.x].GetTileType(); E_TileType t2 = mg.Map[px2.y, px2.x].GetTileType(); E_TileType t3 = mg.Map[px3.y, px3.x].GetTileType(); if (t1 == t2 && t1 == t3) { willBeRemovedBlocks.Add(px1); willBeRemovedBlocks.Add(px2); willBeRemovedBlocks.Add(px3); } //yield return new WaitForSeconds(debugDelay); mg.Map[px1.y, px1.x].SetMarking(false); mg.Map[px2.y, px2.x].SetMarking(false); mg.Map[px3.y, px3.x].SetMarking(false); } //check column for (int y = 0; y < mg.Height - 2; ++y) { POSITION p1 = new POSITION(positions[i].x, y); POSITION p2 = new POSITION(positions[i].x, y + 1); POSITION p3 = new POSITION(positions[i].x, y + 2); if (null == mg.Map[p1.y, p1.x] || null == mg.Map[p2.y, p2.x] || null == mg.Map[p3.y, p3.x]) { continue; } //yield return new WaitForSeconds(debugDelay); mg.Map[p1.y, p1.x].SetMarking(true); mg.Map[p2.y, p2.x].SetMarking(true); mg.Map[p3.y, p3.x].SetMarking(true); E_TileType t1 = mg.map[p1.y, p1.x].GetTileType(); E_TileType t2 = mg.map[p2.y, p2.x].GetTileType(); E_TileType t3 = mg.map[p3.y, p3.x].GetTileType(); if (t1 == t2 && t1 == t3) { willBeRemovedBlocks.Add(p1); willBeRemovedBlocks.Add(p2); willBeRemovedBlocks.Add(p3); } //yield return new WaitForSeconds(debugDelay); mg.Map[p1.y, p1.x].SetMarking(false); mg.Map[p2.y, p2.x].SetMarking(false); mg.Map[p3.y, p3.x].SetMarking(false); } } return(willBeRemovedBlocks); }
public void SetPosition(POSITION pos) { mapPosition.x = pos.x; mapPosition.y = pos.y; }