public void Dig(int x, int z) { if (!LevelHelpers.TileIsInBounds(Model, x, z)) { return; } LevelTile tile = Model.Tiles[x, z]; if (tile.Opened) { return; } tile.Opened = true; UpdateTileDigMarker(tile); List <LevelTile> surroundingTiles = LevelHelpers.GetSurroundingTiles(Model, x, z); foreach (LevelTile t in surroundingTiles) { Model.EvaluateTile(t.X, t.Z); UpdateObjectsForTile(t); } Model.UpdateContiguousTilesFrom(x, z); UpdateCeilingMask(); }
public GameObject GetNearestNonBusyMinion(LevelTile tile) { float closestDist = Mathf.Infinity; GameObject closest = null; foreach (GameObject minion in minions) { if (minion.GetComponent <ActionQueue>().IsBusy()) { continue; } Vector3 pos = LevelHelpers.WorldPosFromTilePos(tile.X, tile.Z); float dist = (minion.transform.position - pos).sqrMagnitude; if (dist < closestDist) { closestDist = dist; closest = minion; } } return(closest); }
IEnumerator ProcessDigList() { while (true) { digList.RemoveAll(tile => tile.Opened); digList.ForEach(tile => { // Do we have surrounding tiles in Hell? List <LevelTile> surrounding = LevelHelpers.GetAdjacentTiles(LevelController.Instance.Model, tile.X, tile.Z); LevelTile found = surrounding.Find(obj => (obj.Opened && LevelHelpers.IsTileInHell(LevelController.Instance.Model, obj.X, obj.Z))); // If so, dig them with some minions if (found != null) { for (int i = 0; i < 5; i++) { GameObject minion = GetNearestNonBusyMinion(tile); if (minion) { minion.GetComponent <ActionQueue>().InsertBeforeCurrent(new DigAction(minion, new Vector2(tile.X, tile.Z))); } } } }); yield return(new WaitForSeconds(1)); } }
public void UpdateTileDigMarker(LevelTile tile) { // If there is a marker already... if (tile.DigMarker != null) { // and the tile isn't marked for digging, or it's opened now - then remove it if (!tile.MarkedForDigging || tile.Opened) { GameObject.Destroy(tile.DigMarker); } } // If there is no marker yet... else { // and the tile is marked for digging - the add it if (tile.MarkedForDigging) { tile.DigMarker = GameObject.Instantiate(DigMarkerPrefab); tile.DigMarker.transform.position = LevelHelpers.WorldPosFromTilePosSetY( tile.X, tile.Z, LevelHelpers.TileDigMarkerPositionY); tile.DigMarker.transform.parent = transform; } } }
public void PaintDig(DestinationMarkerEventArgs args) { if (!IsDigging) { return; } // TODO: improve by using raycast to dig marker height Vector3 target = new Vector3(args.destinationPosition.x, DigMarkerWorldPositionY, args.destinationPosition.z); LevelTile tile = LevelHelpers.GetTileAtWorldPos(LevelController.Instance.Model, target); if (TileIsDiggable(tile)) { if (paintMode == PaintModes.ERASE) { tile.MarkedForDigging = false; MinionManager.Instance.RemoveDigTile(tile); } else if (paintMode == PaintModes.PAINT) { tile.MarkedForDigging = true; MinionManager.Instance.AddDigTile(tile); } LevelController.Instance.UpdateTileDigMarker(tile); } }
public static List <LevelTile> GetAdjacentTiles(LevelModel model, int xPosition, int zPosition) { List <LevelTile> tiles = new List <LevelTile>(); for (int x = (int)xPosition - 1; x <= (int)xPosition + 1; ++x) { if (!LevelHelpers.TileIsInBounds(model, x, zPosition)) { continue; } tiles.Add(model.Tiles[x, zPosition]); } for (int z = (int)zPosition - 1; z <= (int)zPosition + 1; ++z) { if (!LevelHelpers.TileIsInBounds(model, xPosition, z)) { continue; } tiles.Add(model.Tiles[xPosition, z]); } return(tiles); }
private bool TileIsDiggable(LevelTile tile) { // tile is not opened AND (tile is adjacent to room OR tile is adjacent to highlighted tile) return(!tile.Opened && (LevelHelpers.IsTileAdjacentToDigMarkedTile(LevelController.Instance.Model, tile.X, tile.Z) || LevelHelpers.IsTileAdjacentToHell(LevelController.Instance.Model, tile.X, tile.Z))); }
public DigAction(GameObject owner, Vector2 position) : base(owner, LevelHelpers.WorldPosFromTilePos((int)position.x, (int)position.y) + new Vector3(LevelHelpers.TileSize / 2, 0, LevelHelpers.TileSize / 2)) { stoppingDistance = LevelHelpers.TileSize / 2; digPosition = position; agent = owner.GetComponent <NavMeshAgent>(); }
public void SpawnPlayer() { LevelModel model = LevelController.Instance.Model; Vector3 spawnPosition = LevelHelpers.WorldPosFromTilePos((int)model.HellSpawn.x, (int)model.HellSpawn.y); SpawnPlayer(spawnPosition); }
public void SetPlayerPosition(Vector3 position) { // HACK - APPEARS TO BE UNNECESSARY NOW FOR [INSERT DARK MAGIC REASONS HERE]. float playerHeightOffset = 0f; float terrainHeight = LevelHelpers.GetTerrainHeightAtWorldPos(position); PlayArea.position = new Vector3(position.x, terrainHeight + playerHeightOffset, position.z); }
public static void FillListRecursive(string dirPath, List <ILevel> list, string excludeFilename = null, string includeOnlyFilename = null) { DirectoryInfo dir = new DirectoryInfo(dirPath); LevelHelpers.FromFolder(dir.FullName, list, excludeFilename, includeOnlyFilename); foreach (var childDir in dir.EnumerateDirectories()) { FillListRecursive(childDir.FullName, list, excludeFilename, includeOnlyFilename); } }
private void FloodFill(int x, int z, LevelTile[,] tileList) { if (tileList[x, z] == null && Tiles[x, z].Opened) { tileList[x, z] = Tiles[x, z]; List <LevelTile> surroundingTiles = LevelHelpers.GetAdjacentTiles(this, x, z); surroundingTiles.ForEach(tile => FloodFill(tile.X, tile.Z, tileList)); } }
private GameObject CreateObjectOnTile(LevelTile tile, GameObject prefab, Transform parent = null, bool isWall = false) { GameObject created = GameObject.Instantiate(prefab); Vector3 worldPosition = isWall ? LevelHelpers.WorldPosFromTilePosSetY(tile.X, tile.Z, LevelHelpers.WallPositionY) : LevelHelpers.WorldPosFromTilePos(tile.X, tile.Z); created.transform.position = worldPosition; created.transform.parent = (parent == null) ? transform : parent; return(created); }
public void SpawnStartingMinions(int num, Vector3 centerPosition) { float interval = (2 * Mathf.PI) / num; for (int i = 0; i < num; ++i) { float angle = interval * i; float x = MinionSpawnDistance * Mathf.Cos(angle); float z = MinionSpawnDistance * Mathf.Sin(angle); float y = LevelHelpers.GetTerrainHeightAtWorldPos(new Vector3(x, 0f, z)); Vector3 position = (new Vector3(x + centerPosition.x, y, z + centerPosition.z)); MinionManager.Instance.SpawnMinion(position); } }
public void Start() { int amount = Random.Range(2, 5); float radius = 15; for (int i = 0; i < amount; i++) { Vector2 offset = radius * Random.insideUnitCircle; Vector3 spawnPos = transform.position; spawnPos.x = spawnPos.x + offset.x; spawnPos.z = spawnPos.z + offset.y; spawnPos.y = LevelHelpers.GetTerrainHeightAtWorldPos(spawnPos); GameObject.Instantiate(goblin, spawnPos, Quaternion.identity); } }
public void Dig(DestinationMarkerEventArgs args) { // TODO: improve by using raycast to dig marker height Vector3 target = new Vector3(args.destinationPosition.x, DigMarkerWorldPositionY, args.destinationPosition.z); // Debug.LogWarning("START DIG"); IsDigging = true; LevelTile tile = LevelHelpers.GetTileAtWorldPos(LevelController.Instance.Model, target); paintMode = tile.MarkedForDigging ? PaintModes.ERASE : PaintModes.PAINT; if (TileIsDiggable(tile)) { PaintDig(args); } }
void Update() { if (Input.GetMouseButton(1)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Vector2 tilePos = LevelHelpers.TilePosFromWorldPos(hit.point); LevelTile tile = LevelController.Instance.Model.Tiles[(int)tilePos.x, (int)tilePos.y]; if (tile != null && !digList.Contains(tile)) { AddDigTile(tile); } } } }
public void PunchHole(Vector2 origin, int size) { float radius = (float)size / 2f; int halfSize = Mathf.CeilToInt(radius); for (int z = (int)origin.y - halfSize; z < (int)origin.y + halfSize; ++z) { for (int x = (int)origin.x - halfSize; x < (int)origin.x + halfSize; ++x) { if (!LevelHelpers.TileIsInBounds(this, x, z)) { continue; } if (Vector2.Distance(origin, new Vector2(x, z)) < radius) { Tiles[x, z].Opened = true; } } } }
IEnumerator CheckDig() { while (true) { Vector3 tileInFront = transform.position + transform.forward * DigDistance; Vector2 tilePosition = LevelHelpers.TilePosFromWorldPos(tileInFront); LevelTile tile = LevelController.Instance.Model.Tiles[(int)tilePosition.x, (int)tilePosition.y]; if (!tile.Opened) { ActionQueue queue = GetComponent <ActionQueue>(); queue.InsertBeforeCurrent(new DigAction(gameObject, tilePosition)); yield return(new WaitForSeconds(DigTime)); } yield return(0); } }
public void UpdateContiguousTilesFrom(int x, int z) { List <LevelTile> surroundingTiles = LevelHelpers.GetAdjacentTiles(this, x, z); LevelTile foundHell = surroundingTiles.Find(tile => HellContiguousTiles[tile.X, tile.Z] != null); LevelTile foundHeaven = surroundingTiles.Find(tile => HeavenContiguousTiles[tile.X, tile.Z] != null); // if we're about to join, just copy everything to save a painful flood fill. if (foundHell != null && foundHeaven != null) { for (int iz = 0; iz < Length; ++iz) { for (int ix = 0; ix < Width; ++ix) { if (HellContiguousTiles[ix, iz] != null) { HeavenContiguousTiles[ix, iz] = HellContiguousTiles[ix, iz]; } else if (HeavenContiguousTiles[ix, iz] != null) { HellContiguousTiles[ix, iz] = HeavenContiguousTiles[ix, iz]; } } } } if (foundHell != null) { FloodFill(x, z, HellContiguousTiles); } if (foundHeaven != null) { FloodFill(x, z, HeavenContiguousTiles); } }
public bool PositionIsValidLandingZone(Vector3 destination) { Vector2 tilePos = LevelHelpers.TilePosFromWorldPos(destination); LevelModel model = LevelController.Instance.Model; int x = (int)tilePos.x; int z = (int)tilePos.y; if (!LevelHelpers.TileIsInBounds(model, x, z)) { return(false); } LevelTile tile = model.Tiles[x, z]; if (tile.Opened) { return(true); } return(false); }
public static List <ILevel> MediumGallery3() { return(LevelHelpers.FromFolder(@"LevelImages\MediumGallery3\")); }
public static List <ILevel> HardGallery1() { return(LevelHelpers.FromFolder(@"LevelImages\HardGallery1\")); }
public static List <ILevel> EasyGallery4() { return(LevelHelpers.FromFolder(@"LevelImages\EasyGallery4\")); }
public static List <ILevel> Bonus2Gallery3() { return(LevelHelpers.FromFolder(@"LevelImages\Bonus2Gallery3\")); }
public static List <ILevel> ExpertGallery2() { return(LevelHelpers.FromFolder(@"LevelImages\ExpertGallery2\")); }