private void AttachClumpToGrid(HexPiece clumpPiece) { HexGrid gameGrid = GameManager.Instance.Grid; Vector3 posBeforeSnap = clumpPiece.transform.position; Vector3 collisionStartingPos = _startingPositions[clumpPiece]; HexCell collisionCell = gameGrid.WorldPosToCell(clumpPiece.transform.position); AttachPieceToCell(clumpPiece, collisionCell); Vector3 snapDelta = clumpPiece.transform.position - posBeforeSnap; foreach (HexPiece piece in _pieces) { if (piece == clumpPiece) { continue; } Vector3 targetPos = piece.transform.position + snapDelta; AttachPieceToCell(piece, gameGrid.WorldPosToCell(targetPos)); } }
public void SetHex(int q, int r, GameObject hexObj, bool isScenery) { hexObj.transform.Translate(new Vector3(GetX(q, r), GetY(r), 0f)); HexPiece hex = hexObj.AddComponent <HexPiece>(); hex.Set(q, r, isScenery ? HexPiece.PieceType.Scenery : HexPiece.PieceType.Occupant); Dictionary <int, Dictionary <int, HexPiece> > diagonals = isScenery ? sceneryDiagonals : occupantDiagonals; Dictionary <int, HexPiece> diagonal; if (diagonals.ContainsKey(q)) { diagonal = diagonals[q]; } else { diagonal = new Dictionary <int, HexPiece>(); diagonals.Add(q, diagonal); } if (diagonal.ContainsKey(r)) { diagonal[r] = hex; } else { diagonal.Add(r, hex); } }
private void AttachPieceToCell(HexPiece piece, HexCell cell) { piece.transform.parent = cell.transform; piece.transform.localPosition = Vector3.zero; piece.transform.localRotation = Quaternion.Euler(0, 0, 30); // Flat top hex has z rotation of 30 piece.clump = null; cell.piece = piece; }
private HexPiece AddHexPieceToClump(HexType pieceType, Transform parent) { HexPiece newPiece = Instantiate(HexPiecePrefab, parent); newPiece.Type = pieceType; newPiece.clump = this; _pieces.Add(newPiece); _startingPositions[newPiece] = newPiece.transform.position; return(newPiece); }
private void CreateGridMagnet() { grid.ResetGrid(); HexCell centerCell = grid.GetCenterCell(); HexPiece centerMagnetPiece = Instantiate(gameManager.HexPiecePrefab, centerCell.transform); centerMagnetPiece.Type = HexType.Magnet; centerCell.piece = centerMagnetPiece; //foreach (var neighbour in centerCell.neighbours) //{ // HexPiece magnetPiece = Instantiate(gameManager.HexPiecePrefab, neighbour.transform); // magnetPiece.Type = HexType.Magnet; // neighbour.piece = magnetPiece; //} }
public void CreateLaser() { if (_clumpGrid == null) { InitializeGrid(); } _clumpGrid.ResetGrid(); _isLaser = true; HexPiece laserPiece = Instantiate(HexPiecePrefab, _clumpGrid.GetCenterCell().transform); laserPiece.Type = HexType.Laser; laserPiece.clump = this; _pieces = new List <HexPiece> { laserPiece }; }
public void OnClumpPieceCollision(HexPiece clumpPiece, HexPiece collisionPiece) { _moveTweener.Kill(); _moveTweener = null; if (_isLaser) { HexCell clumpCell = GameManager.Instance.Grid.WorldPosToCell(clumpPiece.transform.position); AttachPieceToCell(clumpPiece, clumpCell); DestructionManager.Instance.DestroyConnectingCellsOfType(clumpCell); } else { AttachClumpToGrid(clumpPiece); } Destroy(_clumpGrid.gameObject); Destroy(this.gameObject); }
private void setDecorations() { //1st (size-1): white top left //2nd (size-1): white bottom right //3rd (size-1): black bottom left //4th (size-1): black top right ContentControl contentControl; HexPiece hexPiece; PointInt pnt; for (int i = 0; i < _decorations.Length; i++) { bool isWhite = (i / ((_hexBoard.Size - 1) * 2)) == 0; pnt = getDecoratorPnt(i); hexPiece = new HexPiece(pnt); hexPiece.State = isWhite ? HexPieceState.White : HexPieceState.Black; contentControl = new Button(); contentControl.Opacity = .3; contentControl.IsEnabled = false; contentControl.DataContext = contentControl.Content = hexPiece; _decorations[i] = contentControl; this.AddVisualChild(contentControl); } }
public void SetTarget(HexPiece target) { this.target = target; }