public ITileInfo DoMove(Vector2 direction) { ITileInfo tileInfo = m_World.GetTileInfo(m_Position + direction); if (tileInfo.GetState() == TileState.BorderRight) { if (m_World.gameManager.bPaneCleared || m_World.IsInTuto()) { Debug.Log("Loading Next Pane"); m_World.NextCache(); m_Position.x = 0; m_World.SetObject(this, m_Position); m_World.gameManager.SwitchPane(); return(tileInfo); } else { return(tileInfo); } } else if (tileInfo.GetState() == TileState.Occupied || tileInfo.GetState() == TileState.Ennemy) { return(tileInfo); } else if (tileInfo.GetState() == TileState.Border) { return(tileInfo); } TileState tileState = m_World.MoveObject(m_Position, direction); m_Position += direction; return(tileInfo); }
public void BeginDanceSequence(ITileInfo tileInfo) { //danceSequence.InitializeDanceSequence(); danceSequence.ShowSequence(); currentDanceTargetTile = tileInfo; currentGamePhase = "dance"; }
private static bool IsTileTraversable(ITileInfo tileInfo, ITileOccupant occupant, int traversableThreshold) { bool isTraversable = tileInfo != null; isTraversable |= traversableThreshold > tileInfo.Occupants.Count; isTraversable |= tileInfo.ContainsOccupant(occupant); isTraversable &= !tileInfo.Data.IsSolid; return(isTraversable); }
public void RemoveOccupant(IntVector3 position, ITileOccupant occupant) { if (!IsWithinMap(position)) { CustomLogger.Error(nameof(LevelDataManager), $"Position {position} is out of bounds!"); return; } ITileInfo tileInfo = _tiles[position.x][position.y]; tileInfo.RemoveOccupant(occupant); }
private void InitializeMap() { MapBoundsX = GameLevelDataController.Instance.CurrentGameLevelData.MapData.MapSizeX; MapBoundsY = GameLevelDataController.Instance.CurrentGameLevelData.MapData.MapSizeY; _tiles = new ITileInfo[MapBoundsX][]; for (int x = 0; x < _tiles.Length; x++) { _tiles[x] = new ITileInfo[MapBoundsY]; for (int y = 0; y < _tiles[x].Length; y++) { _tiles[x][y] = new TileInfo(x, y, GameLevelDataController.Instance.CurrentGameLevelData.MapData.DefaultTileData); } } _enemySpawnPoints.Clear(); }
protected virtual void UpdateMapSpacePosition(IntVector3 position) { ITileInfo oldTileInfo = LevelDataManager.Instance.GetTileAt(_mapPosition.x, _mapPosition.y); if (oldTileInfo != null) { oldTileInfo.RemoveOccupant(_unit); } _mapPosition = position; ITileInfo newTileInfo = LevelDataManager.Instance.GetTileAt(_mapPosition.x, _mapPosition.y); if (newTileInfo != null) { newTileInfo.AddOccupant(_unit); } OnMapPositionUpdated?.Invoke(MapPosition); }
// update to the next position in the current path private void UpdateCurrentDestination() { // if we've arrived, clean up if (_currentPath.Count == 0) { ArrivedFinalDestination(); return; } // set the current destination _currentDestination = _currentPath[0]; ITileInfo tileInfo = LevelDataManager.Instance.GetTileAt(_currentDestination.x, _currentDestination.y); // ensure that the current destination is currently traversable if (!_canPassThroughOccupants && tileInfo.Occupants.Count > 0) { ArrivedFinalDestination(); return; } // set the world destination _currentWorldDestination = LevelDataManager.Instance.ArrayToWorldSpace(_currentPath[0].x, _currentPath[0].y); _currentPath.RemoveAt(0); }
private void InitializeTile() { ITileInfo info = LevelDataManager.Instance.GetTileAt(_mapPosition.x, _mapPosition.y); _collider.enabled = info.Data.IsSolid; }
private void _updateCursorForTileSpec(ITileInfo ti, bool mouseClicked, Character c) { switch (ti.Spec) { case TileSpec.Wall: case TileSpec.JammedDoor: case TileSpec.MapEdge: case TileSpec.FakeWall: //hide cursor _hideCursor = true; break; case TileSpec.Chest: //chest click action _cursorSourceRect.Location = new Point(mouseCursor.Width/5, 0); if (mouseClicked && Math.Max(c.X - gridX, c.Y - gridY) <= 1 && (gridX == c.X || gridY == c.Y)) //must be directly adjacent { MapChest chest = MapRef.Chests.Find(_mc => _mc.x == gridX && _mc.y == gridY); if (chest == null) break; string requiredKey = null; switch (World.Instance.MainPlayer.ActiveCharacter.CanOpenChest(chest)) { case ChestKey.Normal: requiredKey = "Normal Key"; break; case ChestKey.Silver: requiredKey = "Silver Key"; break; case ChestKey.Crystal: requiredKey = "Crystal Key"; break; case ChestKey.Wraith: requiredKey = "Wraith Key"; break; default: ChestDialog.Show(m_api, chest.x, chest.y); break; } if (requiredKey != null) { EOMessageBox.Show(DATCONST1.CHEST_LOCKED, XNADialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader); ((EOGame) Game).Hud.SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_WARNING, DATCONST2.STATUS_LABEL_THE_CHEST_IS_LOCKED_EXCLAMATION, " - " + requiredKey); } } break; case TileSpec.BankVault: _cursorSourceRect.Location = new Point(mouseCursor.Width/5, 0); if (mouseClicked && Math.Max(c.X - gridX, c.Y - gridY) <= 1 && (gridX == c.X || gridY == c.Y)) { LockerDialog.Show(m_api, (byte) gridX, (byte) gridY); } break; case TileSpec.ChairDown: case TileSpec.ChairLeft: case TileSpec.ChairRight: case TileSpec.ChairUp: case TileSpec.ChairDownRight: case TileSpec.ChairUpLeft: case TileSpec.ChairAll: case TileSpec.Board1: case TileSpec.Board2: case TileSpec.Board3: case TileSpec.Board4: case TileSpec.Board5: case TileSpec.Board6: case TileSpec.Board7: case TileSpec.Board8: case TileSpec.Jukebox: //highlight cursor _cursorSourceRect.Location = new Point(mouseCursor.Width/5, 0); break; case TileSpec.Jump: case TileSpec.Water: case TileSpec.Arena: case TileSpec.AmbientSource: case TileSpec.SpikesStatic: case TileSpec.SpikesTrap: case TileSpec.SpikesTimed: case TileSpec.None: //normal cursor _cursorSourceRect.Location = new Point(0, 0); break; } }
public static PathStatus GetPathToDestination(IntVector3 startPosition, IntVector3 targetDestination, List <IntVector3> path, ITileOccupant occupant, int traversableThreshold) { // setup for path finding path?.Clear(); List <TileNode> toBeVisited = new List <TileNode>(); List <IntVector3> alreadyVisited = new List <IntVector3>(); // validate the given destination first if (!LevelDataManager.Instance.IsWithinMap(targetDestination)) { CustomLogger.Warn(nameof(MapService), $"Target Destination {targetDestination} is out of bounds!"); return(PathStatus.Invalid); } ITileInfo startingTileInfo = LevelDataManager.Instance.GetTileAt(targetDestination.x, targetDestination.y); if (startingTileInfo != null && (startingTileInfo.Occupants.Count > traversableThreshold || startingTileInfo.Data.IsSolid)) { CustomLogger.Warn(nameof(MapService), $"Target Destination {targetDestination} Invalid!"); return(PathStatus.Invalid); } int startX = startPosition.x; int startY = startPosition.y; int targetX = targetDestination.x; int targetY = targetDestination.y; toBeVisited.Clear(); alreadyVisited.Clear(); // this current node will be the first node that we check TileNode current = new TileNode() { X = startX, Y = startY, DistanceFromStart = 0, TotalCost = 0 }; toBeVisited.Add(current); int count = 0; while (toBeVisited.Count != 0) { // get current node count++; current = GetLowestCostNode(toBeVisited); // remove from to be visited toBeVisited.Remove(current); // if we've hit our destination if (current.X == targetX && current.Y == targetY) { while (current.Parent != null) { path.Insert(0, new IntVector3(current.X, current.Y)); current = current.Parent; } return(PathStatus.Complete); } // checks all directions for valid, unexplored tiles for (int i = 0; i < _directions.Length; i++) { int dirX = _directions[i].x; int dirY = _directions[i].y; int neighborX = current.X + dirX; int neighborY = current.Y + dirY; IntVector3 neighbor = new IntVector3(neighborX, neighborY); // check if we've already looked here if (ContainsIntVector3(neighborX, neighborY, alreadyVisited)) { continue; } // check if this tile is on the map if (!LevelDataManager.Instance.IsWithinMap(neighbor)) { continue; } ITileInfo neighborTileInfo = LevelDataManager.Instance.GetTileAt(neighborX, neighborY); bool _canTraverse = IsTileTraversable(neighborTileInfo, occupant, traversableThreshold); // if this is a corner piece int sumOf = Mathf.Abs(dirX) + Mathf.Abs(dirY); if (sumOf == 2 && _canTraverse) { // check if adjacent sides are open ITileInfo neighborTileX = LevelDataManager.Instance.GetTileAt(current.X + dirX, current.Y); ITileInfo neighborTileY = LevelDataManager.Instance.GetTileAt(current.X, current.Y + dirY); // check if both tiles are available _canTraverse &= IsTileTraversable(neighborTileX, occupant, traversableThreshold); _canTraverse &= IsTileTraversable(neighborTileY, occupant, traversableThreshold); } // if this tile is not traversable, ignore it if (!_canTraverse) { continue; } int distanceFromStart = DistanceFromStart(startX, startY, neighborX, neighborY); // if this node is in "to be visited", check to see if the distance value needs to be updated and skipped bool markedToBeVisited = TryGetNode(neighborX, neighborY, toBeVisited, out int toBeVisitedIndex); if (markedToBeVisited) { TileNode toBeVisitedNode = toBeVisited[toBeVisitedIndex]; if (distanceFromStart < toBeVisitedNode.DistanceFromStart) { toBeVisitedNode.DistanceFromStart = distanceFromStart; } // do not add again to the list continue; } // create a new node and add to open list TileNode newNode = new TileNode() { X = neighborX, Y = neighborY, TotalCost = GetNodeTotalCost(startX, startY, neighborX, neighborY, targetX, targetY), DistanceFromStart = distanceFromStart, Parent = current }; toBeVisited.Add(newNode); } alreadyVisited.Add(new IntVector3(current.X, current.Y)); if (count > NumTriesAbort) { CustomLogger.Error(nameof(MapService), $"In \"{nameof(GetPathToDestination)}\" Failed to path find to {targetDestination}! Aborting..."); break; } } return(PathStatus.Invalid); }
public static List <IntVector3> GetPositionsWithinRadius(int minDistance, IntVector3 start, int radius) { // setup for checks List <TileNode> toBeVisited = new List <TileNode>(); List <IntVector3> alreadyVisited = new List <IntVector3>(); List <IntVector3> traversableTargets = new List <IntVector3>(); if (!LevelDataManager.Instance.IsWithinMap(start)) { CustomLogger.Warn(nameof(MapService), $"Starting position '{start}' is out of bounds!"); return(traversableTargets); } TileNode current = new TileNode() { X = start.x, Y = start.y, DistanceFromStart = 0 }; toBeVisited.Add(current); int count = 0; while (toBeVisited.Count != 0) { count++; current = toBeVisited[0]; TryAddToList(minDistance, traversableTargets, current); toBeVisited.RemoveAt(0); alreadyVisited.Add(new IntVector3(current.X, current.Y)); // check all directions for (int i = 0; i < Directions.Length; i++) { int dirX = Directions[i].x; int dirY = Directions[i].y; int neighborX = current.X + Directions[i].x; int neighborY = current.Y + Directions[i].y; IntVector3 neighbor = new IntVector3(neighborX, neighborY); int distanceFromStart = DistanceFromStart(start.x, start.y, neighborX, neighborY); if (distanceFromStart > radius) { continue; } // stay within the radius if (!LevelDataManager.Instance.IsWithinMap(neighbor)) { continue; } // don't check outside of map if (alreadyVisited.Exists(x => x == neighbor)) { continue; } // don't re-attempt tiles we've already checked // ensure that this tile is traversable ITileInfo neighborTileInfo = LevelDataManager.Instance.GetTileAt(neighborX, neighborY); bool _canTraverse = neighborTileInfo != null && neighborTileInfo.Occupants.Count == 0 && !neighborTileInfo.Data.IsSolid; if (!_canTraverse || ContainsNode(neighborX, neighborY, toBeVisited)) { continue; } // add this tile as a place to check TileNode newNode = new TileNode() { X = neighborX, Y = neighborY, DistanceFromStart = distanceFromStart }; toBeVisited.Add(newNode); } // failsafe in case we end up in an infinite loop if (count > NumTriesAbort) { CustomLogger.Error(nameof(MapService), $"{nameof(GetTraversableTiles)} Aborting after {count} steps!"); break; } } return(traversableTargets); }
public static List <IntVector3> GetTraversableTiles( int radius, IntVector3 start, ITileOccupant occupant, int traversableThreshold, int minDistance = 0) { List <TileNode> toBeVisited = new List <TileNode>(); List <IntVector3> alreadyVisited = new List <IntVector3>(); List <IntVector3> traversableTargets = new List <IntVector3>(); if (!LevelDataManager.Instance.IsWithinMap(start)) { CustomLogger.Warn(nameof(MapService), $"Starting position '{start}' is out of bounds!"); return(traversableTargets); } TileNode current = new TileNode() { X = start.x, Y = start.y, DistanceFromStart = 0 }; toBeVisited.Add(current); int count = 0; while (toBeVisited.Count != 0) { count++; current = toBeVisited[0]; ITileInfo currentTile = LevelDataManager.Instance.GetTileAt(current.X, current.Y); if (current.DistanceFromStart >= minDistance && IsTileTraversable(currentTile, occupant, traversableThreshold)) { traversableTargets.Add(new IntVector3(current.X, current.Y)); } toBeVisited.RemoveAt(0); alreadyVisited.Add(new IntVector3(current.X, current.Y)); for (int i = 0; i < Directions.Length; i++) { int dirX = Directions[i].x; int dirY = Directions[i].y; int neighborX = current.X + Directions[i].x; int neighborY = current.Y + Directions[i].y; IntVector3 neighbor = new IntVector3(neighborX, neighborY); int distanceFromStart = DistanceFromStart(start.x, start.y, neighborX, neighborY); if (distanceFromStart > radius) { continue; } if (ContainsIntVector3(neighborX, neighborY, alreadyVisited) || !LevelDataManager.Instance.IsWithinMap(neighbor)) { continue; } ITileInfo neighborTileInfo = LevelDataManager.Instance.GetTileAt(neighborX, neighborY); bool _canTraverse = IsTileTraversable(neighborTileInfo, occupant, traversableThreshold); // if this is a corner piece int sumOf = Mathf.Abs(dirX) + Mathf.Abs(dirY); if (sumOf == 2 && _canTraverse) { // check if adjacent sides are open ITileInfo neighborTileX = LevelDataManager.Instance.GetTileAt(current.X + dirX, current.Y); ITileInfo neighborTileY = LevelDataManager.Instance.GetTileAt(current.X, current.Y + dirY); // check if both tiles are available _canTraverse &= IsTileTraversable(neighborTileX, occupant, traversableThreshold); _canTraverse &= IsTileTraversable(neighborTileY, occupant, traversableThreshold); } if (ContainsNode(neighborX, neighborY, toBeVisited)) { continue; } TileNode newNode = new TileNode() { X = neighborX, Y = neighborY, DistanceFromStart = distanceFromStart }; toBeVisited.Add(newNode); } if (count > NumTriesAbort) { CustomLogger.Error(nameof(MapService), $"{nameof(GetTraversableTiles)} Aborting after {count} steps!"); break; } } return(traversableTargets); }
private void Move(Vector2 dir) { if (bInputDetectionActive) { bool valid = (gameManager.musicHandler.ValidateBeat() && gameManager.bBeatInput == false); bool obstruction = false; bool enemy = false; bool successfulInput = false; if (gameManager.currentGamePhase == "move") { if (valid) { ITileInfo tileInfo = m_player.DoMove(dir); switch (tileInfo.GetState()) { case TileState.Occupied: obstruction = true; break; case TileState.Ennemy: enemy = true; break; } if (!obstruction) { successfulInput = true; if (enemy) { if (!tileInfo.GetWorldObject().GetComponent <DV_EnemyAnimation>().bWokenUp) { gameManager.BeginDanceSequence(tileInfo); } } } else { gameManager.discoController.OnFailBeat(); } } else { gameManager.discoController.OnFailBeat(); } } else { string moveDirection; if (dir.x == 0f) { if (dir.y > 0f) { moveDirection = "Up"; } else { moveDirection = "Down"; } } else { if (dir.x > 0f) { moveDirection = "Right"; } else { moveDirection = "Left"; } } successfulInput = valid && gameManager.danceSequence.CheckStepValidityAgainstInput(moveDirection, danceStepIndex); if (successfulInput) { gameManager.danceSequence.ValidateStep(danceStepIndex); danceStepIndex++; if (danceStepIndex >= 4) { gameManager.SucceedDanceSequence(); } } else { gameManager.danceSequence.ResetDanceSequence(); danceStepIndex = 0; gameManager.discoController.OnFailBeat(); } } if (successfulInput) { anim.AnimationStep(); } else { gameManager.MissBeatDamage(); } gameManager.ValidateBeat(successfulInput); } }