public DropTile GetRandomNextTile(DropTile ignoreTile) { List <DropTile> tileList = new List <DropTile>(); if (nextTileLeft != null && nextTileLeft != ignoreTile) { tileList.Add(nextTileLeft); } if (nextTileRight != null && nextTileRight != ignoreTile) { tileList.Add(nextTileRight); } if (nextTileTop != null && nextTileTop != ignoreTile) { tileList.Add(nextTileTop); } if (nextTileBottom != null && nextTileBottom != ignoreTile) { tileList.Add(nextTileBottom); } if (tileList.Count == 0) { return(null); } System.Random rnd = new System.Random(); // choose a random tile int index = rnd.Next(0, tileList.Count); return(tileList[index]); }
public void TeleportTo(DropTile tile) { Vector3 target = tile.transform.position; target.z = transform.position.z; transform.position = target; tileDestination = tile; }
/// <summary> /// /// </summary> void Update() { if (GameState.isDead) { return; } if (tileDestination == null) { tileDestination = startTile.GetRandomNextTile(startTile) ?? startTile; } if (spawn) { SetAnimation(); return; } _currentSpeed = Speed * Time.deltaTime; Vector3 targetPos = tileDestination.transform.position; targetPos.z = transform.position.z; if (!startTile.IsNextTileValid(tileDestination)) { transform.position = startTile.transform.position; tileDestination.EnemyOnTile = false; startTile.EnemyOnTile = true; tileDestination = startTile; return; } // move to next tile if ((targetPos - transform.position).magnitude < 0.01f) { transform.position = targetPos; DropTile nextStartTile = tileDestination; tileDestination = tileDestination.GetRandomNextTile(startTile); //There is no next tile if (tileDestination == null) { tileDestination = startTile; } startTile.EnemyOnTile = false; startTile = nextStartTile; startTile.EnemyOnTile = true; } else { this.gameObject.transform.position = Vector3.MoveTowards(transform.position, targetPos, _currentSpeed); } SetAnimation(); }
public bool IsNextTileValid(DropTile nextTile) { if (nextTile == null) { return(false); } return(nextTileLeft == nextTile || nextTileRight == nextTile || nextTileTop == nextTile || nextTileBottom == nextTile || this == nextTile); }
protected void OnTileChanged(AbstractBoardPiece sender, AbstractTile tile) { if (tile is DropTile) { DropTile dropTile = tile as DropTile; if (!dropTile.isSwitching && !dropTile.isDropping) { StartCoroutine(dropTile.Drop()); } } }
public void ConnectTiles(bool connectNeighbours) { nextTileTop = null; nextTileBottom = null; nextTileLeft = null; nextTileRight = null; Vector3 euler = this.transform.eulerAngles; this.transform.Rotate(-euler); Vector2 posNoZ = new Vector2(this.transform.position.x, this.transform.position.y); Vector2 left = posNoZ + Vector2.left; Vector2 right = posNoZ + Vector2.right; Vector2 top = posNoZ + Vector2.up; Vector2 bottom = posNoZ + Vector2.down; if (this.Left && level._droppedTiles.ContainsKey(left) && level._droppedTiles[left].Right) { nextTileLeft = level._droppedTiles[left]; if (connectNeighbours) { nextTileLeft.ConnectTiles(false); } } if (this.Right && level._droppedTiles.ContainsKey(right) && level._droppedTiles[right].Left) { nextTileRight = level._droppedTiles[this.transform.position + Vector3.right]; if (connectNeighbours) { nextTileRight.ConnectTiles(false); } } if (this.Bottom && level._droppedTiles.ContainsKey(bottom) && level._droppedTiles[bottom].Top) { nextTileBottom = level._droppedTiles[bottom]; if (connectNeighbours) { nextTileBottom.ConnectTiles(false); } } if (this.Top && level._droppedTiles.ContainsKey(top) && level._droppedTiles[top].Bottom) { nextTileTop = level._droppedTiles[this.transform.position + Vector3.up]; if (connectNeighbours) { nextTileTop.ConnectTiles(false); } } this.transform.Rotate(euler); }
protected void ActionOnDropTileDropped(DropTile dropTile) { // Debug.LogError("!In " + dropTile.name + " --"); //Sync the current number of dropTiles of this color currenly on the board numberOfDropTilesOnBoard[(int)dropTile.TileColor]--; numberOfDropTilesAll--; if (numberOfDropTilesAll <= 0) { numberOfDropTilesAll = 0; nrOfMoves = spawnTurnIndex; } }
protected void ActionOnDropTileDropped(DropTile dropTile) { // Debug.LogError("!In " + dropTile.name + " --"); //Sync the current number of dropTiles of this color currenly on the board numberOfDropTilesOnBoard[(int)dropTile.TileColor]--; numberOfDropTilesAll--; if (numberOfDropTilesAll <= 0) { numberOfDropTilesAll = 0; nrOfMoves = spawnTurnIndex; } }
private bool CheckMine() { if (!activated) { Debug.Log("Not activated"); return(false); } Debug.Log("Colliding"); if (Vector2.Distance(Cursor.instance.transform.position, transform.position) > 1.75f) { Debug.Log("Too far away"); return(false); } //Vector3Int tilePosition = GameManager.instance.grid.WorldToCell(collision.transform.position); Debug.Log("trying to destroy"); Vector3Int location = GameManager.instance.wallMap.WorldToCell(Cursor.instance.transform.position); Debug.Log(location); TileBase tile = GameManager.instance.wallMap.GetTile(location); if (tile != null) { Debug.Log("Tile: " + tile.name); if (tile.name == "StoneWall") { GameManager.instance.wallMap.SetTile(location, null); return(true); } if (tile.GetType() == typeof(DropTile)) { DropTile dropTile = (DropTile)tile; Vector3 centeredLocation = new Vector2(location.x + 0.5f, location.y + 0.5f); Instantiate(dropTile.drop, centeredLocation, Quaternion.identity); GameManager.instance.wallMap.SetTile(location, null); return(true); } } return(false); }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.name == "Walls") { //Vector3Int tilePosition = GameManager.instance.grid.WorldToCell(collision.transform.position); Debug.Log("trying to destroy"); Vector3Int location = GameManager.instance.wallMap.WorldToCell(collision.GetContact(0).point); TileBase tile = GameManager.instance.wallMap.GetTile(location); if (tile != null) { if (tile.name == "StoneWall") { GameManager.instance.wallMap.SetTile(location, null); } if (tile.GetType() == typeof(DropTile)) { DropTile dropTile = (DropTile)tile; Vector3 centeredLocation = new Vector2(location.x + 0.5f, location.y + 0.5f); Instantiate(dropTile.drop, centeredLocation, Quaternion.identity); GameManager.instance.wallMap.SetTile(location, null); } } } if (collision.gameObject.tag == "Enemy") { collision.gameObject.GetComponent <Enemy>().Die(); Destroy(collision.gameObject); } if (collision.gameObject.name != "Player") { Destroy(gameObject); } }
protected void ActionOnDropCreate(DropTile dropTile) { // Debug.LogError("!In " + dropTile.name + " ++"); numberOfDropTilesOnBoard[(int)dropTile.TileColor]++; numberOfDropTilesAll++; }
protected void ActionOnDropCreate(DropTile dropTile) { // Debug.LogError("!In " + dropTile.name + " ++"); numberOfDropTilesOnBoard[(int)dropTile.TileColor]++; numberOfDropTilesAll++; }
public void OnDropTileExited(DropTile dropTile) { sndDropTileExit.PlayQueued(); }
public void OnDropTileExited(DropTile dropTile) { sndDropTileExit.PlayQueued(); }
/// <summary> /// /// </summary> void Update() { if (GameState.isDead) { SetAnimation(); if (AnimationDead.IsFinished()) { GameObject.Find("GameOverUI").gameObject.GetComponent <GameOver>().Show(); } return; } //Wait until the first tile has been placed and the game begins if (!firstTileSet) { tileDestination = startTile?.GetRandomNextTile(startTile); if (tileDestination != null) { firstTileSet = true; tileDestination.CanRotate = false; spawn = false; } else { SetAnimation(); return; } } _currentSpeed = (Speed + SpeedMax * (FearLevel / FearLevelMax)) * Time.deltaTime; Vector3 targetPos = tileDestination.transform.position; targetPos.z = transform.position.z; // move to next tile if ((targetPos - transform.position).magnitude < 0.01f) { transform.position = targetPos; if (tileDestination.isGoal) { winLevel(); return; } tileDestination.AddModifiers(this); DropTile nextStartTile = tileDestination; tileDestination = tileDestination.GetRandomNextTile(startTile); //There is no next tile if (tileDestination == null) { Die(); return; } startTile = nextStartTile; nextStartTile.CanRotate = false; } else { this.gameObject.transform.position = Vector3.MoveTowards(transform.position, targetPos, _currentSpeed); } SetAnimation(); if (this.FearLevel >= this.FearLevelMax) { //TODO: Was soll passieren, wenn FearLevel voll ist?? } }