public void Swipe() { anim.SetTrigger("Attack"); TileClass tile = gameboard.GetTileAtCoordinate(transform.position.x, transform.position.y).GetComponent <TileClass>(); if (!tile.HasWall(TileClass.NORTH)) { Vector3 pos = new Vector2(transform.position.x, transform.position.y + 1); gameboard.AttackTile((int)pos.x, (int)pos.y); Instantiate(meleeobj, new Vector3((int)pos.x, (int)pos.y), Quaternion.Euler(0, 0, 90)); } if (!tile.HasWall(TileClass.EAST)) { Vector3 pos = new Vector2(transform.position.x + 1, transform.position.y); gameboard.AttackTile((int)pos.x, (int)pos.y); Instantiate(meleeobj, new Vector3((int)pos.x, (int)pos.y), Quaternion.identity); } if (!tile.HasWall(TileClass.SOUTH)) { Vector3 pos = new Vector2(transform.position.x, transform.position.y - 1); gameboard.AttackTile((int)pos.x, (int)pos.y); Instantiate(meleeobj, new Vector3((int)pos.x, (int)pos.y), Quaternion.Euler(0, 0, -90)); } if (!tile.HasWall(TileClass.WEST)) { Vector3 pos = new Vector2(transform.position.x - 1, transform.position.y); gameboard.AttackTile((int)pos.x, (int)pos.y); Instantiate(meleeobj, new Vector3((int)pos.x, (int)pos.y), Quaternion.Euler(0, 0, 180)); } }
// Destroy a wall // (x, y) is the coordinate of the tile // direction is the direction from the tile where the wall should be destroyed public void DestroyWall(int x, int y, int direction) { TileClass tile = GetTileAtCoordinate(x, y).GetComponent <TileClass>(); GameObject obj = GetNeighbouringTile(x, y, direction); TileClass otherTile = null; if (obj != null) { otherTile = obj.GetComponent <TileClass>(); } GameObject wall = null; int opposite = TileClass.getOppositeDirection(direction); if (otherTile != null && otherTile.HasWall(opposite)) { wall = otherTile.GetWall(opposite); otherTile.SetWall(opposite, null); } if (tile.HasWall(direction)) { wall = tile.GetWall(direction); otherTile.SetWall(direction, null); } if (wall != null) { Destroy(wall); } }
public void Shoot(int direction) { anim.SetTrigger("Ranged"); audio.PlayOneShot(Camera.main.GetComponent <ObjectStore> ().shootSound); GameObject projectile = (GameObject)Instantiate(projectileobj, transform.position, Quaternion.identity); ProjectileClass pc = projectile.GetComponent <ProjectileClass>(); Vector2 target = pc.transform.position; switch (direction) { case TileClass.NORTH: projectile.transform.Rotate(new Vector3(0, 0, 90)); if (gameboard.GetTileAtCoordinate(transform.position.x, transform.position.y).GetComponent <TileClass>().HasWall(TileClass.NORTH)) { Destroy(projectile); break; } int i = (int)transform.position.y + 1; // Find the target to shoot at while (i < gameboard.height) { GameObject tile = gameboard.GetTileAtCoordinate((int)transform.position.x, i); if (tile != null) { TileClass tc = tile.GetComponent <TileClass>(); if (gameboard.AttackTile(tile)) { target = tile.transform.position; break; } if (tc.HasWall(TileClass.NORTH)) { target = tile.transform.position; break; } } i++; } break; case TileClass.EAST: if (gameboard.GetTileAtCoordinate(transform.position.x, transform.position.y).GetComponent <TileClass>().HasWall(TileClass.EAST)) { Destroy(projectile); break; } int j = (int)transform.position.x + 1; while (j < gameboard.width) { GameObject tile = gameboard.GetTileAtCoordinate(j, transform.position.y); if (tile != null) { TileClass tc = tile.GetComponent <TileClass>(); if (gameboard.AttackTile(tile)) { target = tile.transform.position; break; } if (tc.HasWall(TileClass.EAST)) { target = tile.transform.position; break; } } j++; } transform.localScale = new Vector3(1, 1, 1); break; case TileClass.SOUTH: projectile.transform.Rotate(new Vector3(0, 0, -90)); if (gameboard.GetTileAtCoordinate(transform.position.x, transform.position.y).GetComponent <TileClass>().HasWall(TileClass.SOUTH)) { Destroy(projectile); break; } int k = (int)transform.position.y - 1; while (k >= 0) { GameObject tile = gameboard.GetTileAtCoordinate(transform.position.x, k); if (tile != null) { TileClass tc = tile.GetComponent <TileClass>(); if (gameboard.AttackTile(tile)) { target = tile.transform.position; break; } if (tc.HasWall(TileClass.SOUTH)) { target = tile.transform.position; break; } } k--; } break; case TileClass.WEST: projectile.transform.Rotate(new Vector3(0, 0, 180)); if (gameboard.GetTileAtCoordinate(transform.position.x, transform.position.y).GetComponent <TileClass>().HasWall(TileClass.WEST)) { Destroy(projectile); break; } int l = (int)transform.position.x - 1; while (l >= 0) { GameObject tile = gameboard.GetTileAtCoordinate(l, transform.position.y); if (tile != null) { TileClass tc = tile.GetComponent <TileClass>(); if (gameboard.AttackTile(tile)) { target = tile.transform.position; break; } if (tc.HasWall(TileClass.WEST)) { target = tile.transform.position; break; } } l--; } transform.localScale = new Vector3(-1, 1, 1); break; } // print (pc.transform.position + " :: " + target); if (pc != null) { pc.SetTargetLocation(pc.transform.position, target); } }
// Create a wall // (x, y) is the coordinate of the tile // direction is the direction from the tile where the wall should be created public void CreateWall(int x, int y, int direction) { TileClass tile = GetTileAtCoordinate(x, y).GetComponent <TileClass>(); TileClass otherTile = null; GameObject obj; ObjectStore objStore = Camera.main.GetComponent <ObjectStore>(); GameObject wall; float wallX = x; float wallY = y; switch (direction) { case TileClass.NORTH: obj = GetTileAtCoordinate(x, y + 1); if (obj) { otherTile = obj.GetComponent <TileClass>(); } if (!tile.HasWall(TileClass.NORTH) && otherTile != null && !otherTile.HasWall(TileClass.SOUTH)) { wallY += 0.5f; wall = objStore.CreateHorizontalWall(wallX, wallY); tile.SetWall(TileClass.NORTH, wall); otherTile.SetWall(TileClass.SOUTH, wall); } break; case TileClass.EAST: obj = GetTileAtCoordinate(x + 1, y); if (obj) { otherTile = obj.GetComponent <TileClass>(); } if (!tile.HasWall(TileClass.EAST) && otherTile != null && !otherTile.HasWall(TileClass.WEST)) { wallX -= 0.5f; wall = objStore.CreateVerticalWall(wallX, wallY); tile.SetWall(TileClass.EAST, wall); otherTile.SetWall(TileClass.WEST, wall); } break; case TileClass.SOUTH: obj = GetTileAtCoordinate(x, y - 1); if (obj) { otherTile = obj.GetComponent <TileClass>(); } if (!tile.HasWall(TileClass.SOUTH) && otherTile != null && !otherTile.HasWall(TileClass.NORTH)) { wallY -= 0.5f; wall = objStore.CreateHorizontalWall(wallX, wallY); tile.SetWall(TileClass.SOUTH, wall); otherTile.SetWall(TileClass.NORTH, wall); } break; case TileClass.WEST: obj = GetTileAtCoordinate(x - 1, y); if (obj) { otherTile = obj.GetComponent <TileClass>(); } if (!tile.HasWall(TileClass.WEST) && otherTile != null && !otherTile.HasWall(TileClass.EAST)) { wallX += 0.5f; wall = objStore.CreateVerticalWall(wallX, wallY); tile.SetWall(TileClass.WEST, wall); otherTile.SetWall(TileClass.EAST, wall); } break; } }
public void Move(int direction) { if (isDead) { // no zombies plz return; } t = 0; int x = (int)transform.position.x; int y = (int)transform.position.y; anim.SetTrigger("Walk"); switch (direction) { case TileClass.NORTH: y++; break; case TileClass.EAST: transform.localScale = new Vector3(1, 1, 1); x++; break; case TileClass.SOUTH: y--; break; case TileClass.WEST: transform.localScale = new Vector3(-1, 1, 1); x--; break; } // Reset the tiles to current position TileClass tc = gameboard.GetTileAtCoordinate(transform.position.x, transform.position.y).GetComponent <TileClass>(); if (tc != null) { currentTile = tc; nextTile = tc; } GameObject obj = gameboard.GetTileAtCoordinate(transform.position.x, transform.position.y); TileClass tempCurrentTile = null; if (obj != null) { tempCurrentTile = obj.GetComponent <TileClass>(); } obj = gameboard.GetTileAtCoordinate(x, y); TileClass tempNextTile = null; if (obj != null) { tempNextTile = obj.GetComponent <TileClass>(); } if (tempCurrentTile != null && !tempCurrentTile.HasWall(direction) && tempNextTile != null && !tempNextTile.HasEntity()) { currentTile = tempCurrentTile; nextTile = tempNextTile; currentTile.entity = null; nextTile.entity = gameObject; // Set order in layer renderer.sortingOrder = (int)nextTile.transform.position.y * -2; } }