void RandomiseTiles() { if (emptySlot == null) { emptySlot = tiles[UnityEngine.Random.Range(0, 9)]; emptySlot.tile.gameObject.SetActive(false); } int blockedDir = -1; do { for (int i = 0; i < difficulties[difficulty].movements; i += 1) { int direction; do { direction = UnityEngine.Random.Range(0, 4); } while (!emptySlot.neighbours.ContainsKey((Direction)direction) || direction == blockedDir); SlideTile(emptySlot, (Direction)direction); emptySlot = emptySlot.neighbours[(Direction)direction]; blockedDir = (direction + 2) % 4; } }while (GetTileDisplacements() < difficulties[difficulty].posChanges); }
// Use this for initialization void Start() { GameState.Message("PlayerBoardUI.Start()"); float xpos, ypos, zpos, deltax, deltay; Collider col = tilePrefab.GetComponent <Collider>(); deltax = col.bounds.size.x + space_width; deltay = col.bounds.size.y + space_height; ypos = 0.0f; zpos = 0.0f; for (int y = 0; y < cols; y++) { xpos = 0.0f; for (int x = 0; x < rows; x++) { GameObject slotInst = Instantiate(slotPrefab.gameObject); slotInst.transform.parent = this.transform; slotInst.transform.localPosition = new Vector3(xpos, ypos, zpos); TileSlot ts = slotInst.GetComponent <TileSlot>(); slotList.Add(ts); xpos += deltax; } ypos += deltay; } }
public void PressedConfirmBuildingButton() { if (!isBuildingAttached || tileSlotCache == null || currentTileHit == null) { return; } if (wasFloorLayer) { gridManager.SetTile(tileSlotCache, Position[2], TileMapLayer.Floor, true); } else { gridManager.SetTile(tileSlotCache, Position[2], TileMapLayer.Buildings, true); } var itemSlotCache = new ItemSlot(tileSlotCache.GetTileAbst, 1); Inventory.GetInstance.RemoveItemFromInventory(0, itemSlotCache); amountOfCurrentItem--; if (amountOfCurrentItem >= 1) { SetBuildingTile(itemSlotCache.item as TileAbstSO); } else { PlayerStateMachine.GetInstance.SwitchState(InputState.DefaultState); UIManager._instance.ButtonCancel(); tileSlotCache = null; } Debug.Log("Placed"); }
public void Matched() { TraySlot.Matched(); TraySlot = null; TileSlot = null; QueueFree(); }
public bool Contains(TileSlot testTile) { bool leftB = testTile.Equals(left); bool rightB = testTile.Equals(right); bool aboveB = testTile.Equals(above); bool belowB = testTile.Equals(below); return(leftB | rightB | aboveB | belowB); }
void UpdateEmptySlot() { for (int i = 0; i < tiles.Count; i += 1) { if (!tiles[i].tile.gameObject.activeSelf) { emptySlot = tiles[i]; } } }
public bool CheckTile(TileSlot tile) { EquipManager equipManager = EquipManager.GetInstance; if (tile.GetTileAbst is GatherableTileSO gatherable) { return(equipManager.GetToolActive(gatherable.GetToolType) && gatherable.GetSourceTier <= equipManager.GetTierByEnum(gatherable.GetToolType) && tile.IsGatherable); } return(false); }
public void RandomTest() { if (emptySlot != null) { emptySlot.tile.gameObject.SetActive(true); emptySlot = null; } ResetTiles(); RandomiseTiles(); }
public void InitialPress(Vector3 pressLocation) { TileSlot tileSlot = RaycastForTileSlot(pressLocation); if (tileSlot == null || tileSlot.GetItemType() == ColorPalette.None) { return; } lastHoverHeld = tileSlot; pathModel.SetInitialSlot(tileSlot); }
public override void Init() { islandsNoise.GenerateSeed(); buildingsRandom.GenerateSeed(); CameraController._instance.UpdateView(); SetTile(new TileSlot(craftingTable1), new Vector2Int(-7, 0), TileMapLayer.Buildings, true); SetTile(new TileSlot(craftingTable2), new Vector2Int(-6, 0), TileMapLayer.Buildings, true); TileSlot tree = new TileSlot(buildingsGeneration[0].tile); tree.Init(new Vector2Int(4, 0), TileMapLayer.Buildings, true); SetTile(tree, new Vector2Int(4, 0), TileMapLayer.Buildings, true); }
public void AttemptAddPath(TileSlot newTile) { ResetPathColor(); // Don't add to empty path if (path.Count == 0) { return; } // No doubling back if (path.Count > 1 && path[path.Count - 2] == newTile) { return; } ColorPalette itemType = newTile.GetItemType(); TileSlot lastSlot = path[path.Count - 1]; // Item must be the same color as the path, or must be 'all' if (itemType != ColorPalette.All && (itemType != pathColor && pathColor != ColorPalette.All)) { return; } // If last item, remove last item if (lastSlot == newTile && path.Count > 1) { path.RemoveAt(path.Count - 1); ResetPathColor(); AndroidVibrate.Vibrate(40); return; } // Don't add more items on loop if (ContainsLoop()) { return; } // Check if the new tile is adjacent our current one. if (!lastSlot.adjacentTiles.Contains(newTile)) { return; } AddToPath(newTile); if (ContainsLoop()) { specialActions.EmphasizeColor(pathColor); AndroidVibrate.Vibrate(new long [] { 0, 40, 20, 40 }, -1); } // if(ContainsLoop()) AndroidVibrate.Vibrate(70); else { AndroidVibrate.Vibrate(30); } }
public bool ContainsLoop() { if (path.Count < 2) { return(false); } TileSlot lastSlot = path[path.Count - 1]; List <TileSlot> butLast = new List <TileSlot>(path); butLast.RemoveAt(butLast.Count - 1); return(butLast.Contains(lastSlot)); }
public TileSlot GetTileFromGrid(Vector2Int gridPosition, TileMapLayer buildingLayer) { if (TryGetChunk(GridToChunkCoordinates(gridPosition), out Chunk chunk)) { TileSlot tile = chunk.GetTile(gridPosition, buildingLayer); return(tile); } else { return(null); } }
private bool CheckTilesOnPos(Vector2 pos) { Vector2Int gridPos = gridManager.WorldToGridPosition(pos, TileMapLayer.Floor); if (gridPos == currentGridPos) { return(true); } TileSlot buildingTile = gridManager.GetTileFromGrid(gridPos, TileMapLayer.Buildings); TileSlot floorTile = gridManager.GetTileFromGrid(gridPos, TileMapLayer.Floor); return((buildingTile == null || !buildingTile.GetIsSolid) && floorTile != null); }
internal void SetTile(TileSlot tile, Vector2Int gridPosition, TileMapLayer buildingLayer, bool countsAsEdit = true, bool generation = false) { switch (buildingLayer) { case TileMapLayer.Floor: SetTileByRef(tile, gridPosition, buildingLayer, countsAsEdit, ref floorArr, ref _instance.floor, generation); break; case TileMapLayer.Buildings: SetTileByRef(tile, gridPosition, buildingLayer, countsAsEdit, ref buildingsArr, ref _instance.buildings, generation); break; } }
public void SetInitialSlot(TileSlot initialSlot) { ColorPalette itemType = initialSlot.GetItemType(); path.Clear(); if (itemType == ColorPalette.None) { return; } AddToPath(initialSlot); pathColor = itemType; AndroidVibrate.Vibrate(40); }
IEnumerator MoveToNewSlot(TileSlot tileSlot) { Vector3 targetLocation = tileSlot.transform.position; float timeSinceInitial = 0f; while (Vector3.Distance(transform.position, targetLocation) > Mathf.Epsilon) { timeSinceInitial += Time.fixedDeltaTime; float distance = acceleration * timeSinceInitial * Time.fixedDeltaTime; transform.position = Vector3.MoveTowards(transform.position, targetLocation, distance); yield return(new WaitForFixedUpdate()); } transform.position = targetLocation; }
public void SetTile(TileSlot tile, Vector2Int gridPosition, TileMapLayer buildingLayer, bool playerAction = true, Color?color = null) { Vector2Int chunkPos = GridToChunkCoordinates(gridPosition); SetTileColor(gridPosition, buildingLayer, (color != null) ? (Color)color : Color.white); if (TryGetChunk(chunkPos, out Chunk chunk)) { chunk.SetTile(tile, gridPosition, buildingLayer, playerAction, false); } else if (tile != null) { CreateChunk(chunkPos).SetTile(tile, gridPosition, buildingLayer, playerAction, false); } }
// called when clicked // tiles will forget its current slot if ot has one. public void PickedUp() { retPos = startPos; if(myslot) { if(myslot.correctLetter != letter) { myslot.placedTile = null; myslot = null; hasSlot = false; retPos = startPos; } } }
public void OnHeld(Vector3 pressLocation) { TileSlot tileSlot = RaycastForTileSlot(pressLocation); if (lastHoverHeld == tileSlot) { return; } lastHoverHeld = tileSlot; if (tileSlot == null) { return; } pathModel.AttemptAddPath(tileSlot); }
public void ConfirmRemoval() { tileSlotCache = currentTileHit.tile; if (tileSlotCache == null) { return; } if (currentTileHit != null && currentTileHit.tile.GetIsDestructible && Inventory.GetInstance.AddToInventory(0, new ItemSlot(currentTileHit.tile.GetTileAbst, 1))) { gridManager.SetTile(null, currentTileHit.gridPosition, TileMapLayer.Buildings, true); tileSlotCache = null; } }
private TileSlot[,] CreateTileArray() { float xOrigin = tileAmount.columns * 0.5f * -1f + 0.5f; float yOrigin = (tileAmount.rows - 1) * 0.5f * -1f + 0.5f; TileSlot[,] tiles = new TileSlot[tileAmount.columns, tileAmount.rows]; for (int x = 0; x < tileAmount.columns; x++) { for (int y = 0; y < tileAmount.rows; y++) { GameObject tileSlotGameObject = Instantiate(tileSlotPrefab, new Vector3(xOrigin + x, yOrigin + y, 0), Quaternion.identity, transform); tileSlotGameObject.name = "Tile Slot " + x + " " + y; tiles[x, y] = tileSlotGameObject.GetComponent <TileSlot>(); } } return(tiles); }
private void SetTileByRef(TileSlot tile, Vector2Int gridPosition, TileMapLayer tilemapLayer, bool countsAsEdit, ref TileSlot[,] tileArr, ref Tilemap tilemap, bool generation = false) { Vector2Int chunkPosition = GridToChunkPosition(gridPosition); bool tileExists = tileArr != null && tileArr[chunkPosition.x, chunkPosition.y] != null; if (tile != null || tileExists) { if (tileArr == null) { tileArr = new TileSlot[CHUNK_SIZE, CHUNK_SIZE]; } if (tileExists && tile == null) { tileArr[chunkPosition.x, chunkPosition.y].CancelEvent(gridPosition, tilemapLayer); tilemap.SetTile((Vector3Int)gridPosition, null); tileArr[chunkPosition.x, chunkPosition.y] = null; tileCount--; wasEdited |= countsAsEdit; if (tileCount == 0) { tileArr = null; } } else if (!tileExists) { tileCount++; wasEdited |= countsAsEdit; tile.Init(gridPosition, tilemapLayer, generation); tilemap.SetTile((Vector3Int)gridPosition, tile.GetMainTileBase); tileArr[chunkPosition.x, chunkPosition.y] = tile; } else { if (tile != tileArr[chunkPosition.x, chunkPosition.y]) { tileArr[chunkPosition.x, chunkPosition.y].CancelEvent(gridPosition, tilemapLayer); tileArr[chunkPosition.x, chunkPosition.y] = tile; tile.Init(gridPosition, tilemapLayer, generation); } tilemap.SetTile((Vector3Int)gridPosition, tile.GetMainTileBase); wasEdited |= countsAsEdit; } } }
void SlideTile(TileSlot movedTile, Direction direction) { if (!movedTile.neighbours.ContainsKey(direction)) { return; } SlidingTile tileA = movedTile.tile; SlidingTile tileB = movedTile.neighbours[direction].tile; movedTile.tile = tileB; movedTile.neighbours[direction].tile = tileA; SetTileCoords(tileA, movedTile.neighbours[direction].position); SetTileCoords(tileB, movedTile.position); UpdateEmptySlot(); }
public override void MousePos() { touchPosition = CameraController._instance.GetCurrentActiveCamera.ScreenToWorldPoint(Input.mousePosition); currentTileHit = gridManager.GetHitFromWorldPosition(touchPosition, TileMapLayer.Buildings); if (currentTileHit == null || currentTileHit.tile == null || gridManager.GetTileFromGrid(currentTileHit.gridPosition, TileMapLayer.Buildings) == null) { return; } tileSlotCache = currentTileHit.tile; if (Input.GetMouseButtonDown(0)) { ConfirmRemoval(); } }
public void SetDummyTile(TileSlot tile, Vector2Int gridPosition, TileMapLayer buildingLayer, Color?color = null) { Tilemap tilemap = GetTilemap(buildingLayer); if (GetTileFromGrid(gridPosition, buildingLayer) == null) { if (tile == null) { tilemap.SetTile((Vector3Int)gridPosition, null); } else { GetTilemap(buildingLayer).SetTile((Vector3Int)gridPosition, tile.GetMainTileBase); if (color != null) { SetTileColor(gridPosition, buildingLayer, (Color)color); } } } }
private void Start() { bool foundroot = false; search_transform = transform.parent; while (search_transform.parent != search_transform.root && !foundroot) { //Debug.Log(); TileSlot slot = search_transform.parent.GetComponent <TileSlot>(); if (slot != null && slot.isRoot) { slot.blocker.houses.Add(this); foundroot = true; } else { search_transform = search_transform.parent; } } }
public void SetBuildingTile(TileAbstSO Item) { tileSlotCache = null; if (Item == null) { return; } tileSlotCache = new TileSlot(Item); if (amountOfCurrentItem <= 0) { amountOfCurrentItem = Inventory.GetInstance.GetAmountOfItem(0, new ItemSlot(Item, 1)); } currentlyPlacedOnFloor = tileSlotCache.GetTileType == TileType.Block; if (amountOfCurrentItem == 0) { amountOfCurrentItem = Inventory.GetInstance.GetAmountOfItem(0, new ItemSlot(Item, 1)); } isBuildingAttached = true; currentTileHit = null; }
public TileHit Scan(Vector2Int gridStartPosition, DirectionEnum _direction, int _radius, TileMapLayer _buildingLayer, IChecker _checker) { startPosition = gridStartPosition; radius = _radius; buildingLayer = _buildingLayer; checker = _checker; direction = _direction; TileSlot currentTile = gridManager.GetTileFromGrid(startPosition, buildingLayer); if (currentTile != null && checker.CheckTile(currentTile)) { return(new TileHit(currentTile, startPosition)); } for (int i = 1; i <= radius; i++) { TileHit tileHit = GetClosestTileInSquare(i); if (tileHit != null) { return(tileHit); } } return(null); }
public TileHit(TileSlot tile, Vector2Int gridPosition) { this.tile = tile; this.gridPosition = gridPosition; }
// called when tile is touching a slot, slot will be remembered as current // if tile is dropped public void FoundSlot(TileSlot tSlot) { if(!tSlot.placedTile) { if(myslot) { myslot.EndHoverTween(); } slotPos = tSlot.transform.localPosition; retPos = slotPos; hasSlot = true; myslot = tSlot; myslot.BeginHoverTween(); } }
// this removes all slot info if the tile is dragged away from a slot. public void LoseSlot(TileSlot tslot) { tslot.EndHoverTween(); if(myslot == tslot) { retPos = startPos; hasSlot = false; myslot = null; } }
public override void SetTileSlot(TileSlot tileSlot) { base.SetTileSlot(tileSlot); springyMove.StartMove(tileSlot.transform.position); }