//OnTriggerEnter or OnCollisionEnter? private void OnTriggerEnter(UnityEngine.Collider other) { if (other.gameObject.tag == "Tile") { GameTile t = other.gameObject.GetComponent <GameTile>(); if (t && this.target_tile.Equals(t)) { this.current_tile = t; StayOnTile(); if (this.moves_remaining > 0 || t.GetType().ToString() == "ForkTile") { this.current_tile.OnTransit(this); } else { this.current_tile.OnFinalLand(this); if (current_tile is TeleportationTile) { Invoke("EndTurn", 2.0f); } else { EndTurn(); } } } } }
public bool CheckTileCollision(GameTile checkingTile, Vector2 checkPos, params Type[] includeTypes) { Rectangle checkingRect = new Rectangle((int)checkingTile.Position.X, (int)checkingTile.Position.Y, (int)checkingTile.Size.X, (int)checkingTile.Size.Y); for (int i = 0; i < GameTileList.Count; i++) { GameTile tile = GameTileList[i]; bool isValidTile = false; for (int j = 0; j < includeTypes.Length; j++) { if (includeTypes[j] == tile.GetType()) { isValidTile = true; break; } } if (!isValidTile || checkingTile == tile) { continue; } Rectangle targetRect = new Rectangle((int)tile.Position.X, (int)tile.Position.Y, (int)tile.Size.X, (int)tile.Size.Y); if (GameObject.RectangleInRectangle(checkingRect, targetRect)) { return(true); } } return(false); }
private void LinkBoard() { for (int i = 0; i < boardWidth; i++) { for (int j = 0; j < boardHeight; j++) { GameTile tile = _tiles[i + j * boardWidth]; // Don't link empty tiles if (tile.GetType() == typeof(EmptyTile)) { continue; } for (int x = i - 1; x <= i + 1; x++) { for (int y = j - 1; y <= j + 1; y++) { // Check for valid board space if ((x < 0 || x >= boardWidth) || (y < 0 || y >= boardHeight)) { continue; } GameTile tileLink = _tiles[x + y * boardWidth]; // Don't link empty tiles if (tileLink.GetType() == typeof(EmptyTile)) { continue; } // Don't link same type tiles (number => number / symbol => symbol) if (tile.GetType() == tileLink.GetType()) { continue; } StartCoroutine(LinkTile(tile, tileLink)); } } } } }
public void UnlinkTile() { GameTile removedTile = _tileStack.Pop(); if (removedTile.GetType() != typeof(NumberTile)) { PathTotal = (int)_stf.Eval(_equationGenerator.GetEquationString(this, true)); } removedTile.EmptyTile(_goalTotal); _goalTotal.CheckComplete(); pathUpdatedEvent.Invoke(); }
public void LinkTile(GameTile nextTile) { PreviousTile = (_tileStack.Count > 0) ? _tileStack.Peek() : null; _tileStack.Push(nextTile); nextTile.FillTile(_goalTotal, PreviousTile); if (nextTile.GetType() == typeof(NumberTile)) { PathTotal = (int)_stf.Eval(_equationGenerator.GetEquationString(this, true)); _goalTotal.CheckComplete(); } pathUpdatedEvent.Invoke(); }