///Changes tile back to default material if needed and returns reverting tiles back to RemoveAll function private static bool getRevertingTiles(TileMonoBehavior tile) { if (tile.timeToRevert == 0) { tile.GetComponent <SpriteRenderer>().material = tile.defaultMaterial; tile.inList = false; } return(tile.timeToRevert == 0); }
///precondition: newTile does not have an occupying Entity, or occupying Entity must be garbage collected ///moves this Enity to the specified Tile and begins tracking it ///assumes it is already possible for Entity to move to designated Tile (tile is walkable, not occupied) public void goToTile(TileMonoBehavior newTile) { if (occupyingTile != null) { occupyingTile.occupyingEntity = null; //makes old tile not think this Entity is still there } occupyingTile = newTile; occupyingTile.occupyingEntity = this; //may forcefully evict existing entity from tile transform.position = new Vector3(occupyingTile.transform.position.x, occupyingTile.transform.position.y, transform.position.z); //entitites that go to tiles have status effects applied to them if (occupyingTile.GetComponent <SpriteRenderer>().sharedMaterial == Resources.Load("Materials/Red")) //standing in fire { Debug.Log(this + " takes 2 damage for standing in the fire"); this.TakeDamage(2, DamageType.burn); } else if (occupyingTile.GetComponent <SpriteRenderer>().sharedMaterial == Resources.Load("Materials/Yellow")) //standing in... wind? { if (this.speed > 1) { this.speed--; } } else if (occupyingTile.GetComponent <SpriteRenderer>().sharedMaterial == Resources.Load("Materials/Blue")) { while (occupyingTile.GetComponent <SpriteRenderer>().sharedMaterial == Resources.Load("Materials/Blue")) { TileMonoBehavior targetTile; switch (lastDirection) { case (MoveDirection.up): targetTile = occupyingTile.getAbove(); break; case (MoveDirection.down): targetTile = occupyingTile.getBelow(); break; case (MoveDirection.left): targetTile = occupyingTile.getLeft(); break; default: targetTile = occupyingTile.getRight(); break; } if (targetTile == null) { break; } if (targetTile.IsWalkable()) { if (!targetTile.IsOccupied()) { goToTile(targetTile); } else //ALERT! Potential issue here: if occupying entity is shoved into another entity, the other entity will take damage until it dies or its occupying tile changes //thus this spell makes the pushing entity kill any entities it is pushed into { Debug.Log(targetTile.occupyingEntity + " takes " + damageAmount + " " + attackType + " damage from the shoved " + this); targetTile.occupyingEntity.TakeDamage(damageAmount, attackType); break; } } else { break; } } //Debug.Log("Finished sliding"); } }
/// Update is called once per frame ///Change color of spell based on type ///Gets the tile beneath the spell and changes tile material based on spell type ///Spell is destroyed after hitting enemy or going off the board void Update() { if (type == spellType.regular) { GetComponent <SpriteRenderer>().color = Color.white; } else if (type == spellType.fire) { GetComponent <SpriteRenderer>().color = Color.red; damageCaused = 5; } else if (type == spellType.ice) { GetComponent <SpriteRenderer>().color = Color.blue; damageCaused = 5; } else { GetComponent <SpriteRenderer>().color = Color.yellow; damageCaused = 5; } Vector2 topRightLoc = new Vector2(transform.position.x + 0.25f, transform.position.y + 0.25f); Vector2 botLeftLoc = new Vector2(transform.position.x - 0.25f, transform.position.y - 0.25f); Collider2D collider = Physics2D.OverlapArea(topRightLoc, botLeftLoc, TileMonoBehavior.tileLayerMask); //test if a floor tile is under this tile, if so then grab it and check what occupies it if (collider != null) { //Debug.Log("Testing floor collision"); TileMonoBehavior tileBeneathUs = collider.gameObject.GetComponent <TileMonoBehavior>(); if (tileBeneathUs != null) { if (!tileBeneathUs.IsWalkable()) { Destroy(this.gameObject); } else if (tileBeneathUs.IsOccupied()) { Debug.Log(tileBeneathUs.occupyingEntity + " takes " + damageCaused + " poking damage from the spell"); tileBeneathUs.occupyingEntity.TakeDamage(damageCaused, Entity.DamageType.poking); Destroy(this.gameObject); } else { this.occupyingTile = tileBeneathUs; if (type == spellType.regular) { tileBeneathUs.GetComponent <SpriteRenderer>().material = defaultMaterial; tileBeneathUs.timeToRevert = 0; } else if (type == spellType.fire) { tileBeneathUs.GetComponent <SpriteRenderer>().material = Resources.Load("Materials/Red") as Material; if (!tileBeneathUs.inList) { tileBeneathUs.timeToRevert = DungeonManager.turnOrder.Count * 5; DungeonManager.AddToTileList(tileBeneathUs); tileBeneathUs.inList = true; } } else if (type == spellType.ice) { tileBeneathUs.GetComponent <SpriteRenderer>().material = Resources.Load("Materials/Blue") as Material; if (!tileBeneathUs.inList) { tileBeneathUs.timeToRevert = DungeonManager.turnOrder.Count * 5; DungeonManager.AddToTileList(tileBeneathUs); tileBeneathUs.inList = true; } } else { tileBeneathUs.GetComponent <SpriteRenderer>().material = Resources.Load("Materials/Yellow") as Material; if (!tileBeneathUs.inList) { tileBeneathUs.timeToRevert = DungeonManager.turnOrder.Count * 5; DungeonManager.AddToTileList(tileBeneathUs); tileBeneathUs.inList = true; } } } } else { //Debug.Log("Destroying spell by lack of Tile"); Destroy(this.gameObject); } } else { //Debug.Log("Destroying spell by lack of Collider"); Destroy(this.gameObject); } }