public void OnKeydown(IntVector2 dir) { if (!turn) { return; } turn = false; StartCoroutine(Reset()); print(stage.actors.Count); Action next = null; if (dir.Equals(Direction.NORTH)) { next = new WalkAction(stage.hero, stage, Direction.NORTH); } else if (dir.Equals(Direction.EAST)) { next = new WalkAction(stage.hero, stage, Direction.EAST); } else if (dir.Equals(Direction.SOUTH)) { next = new WalkAction(stage.hero, stage, Direction.SOUTH); } else if (dir.Equals(Direction.WEST)) { next = new WalkAction(stage.hero, stage, Direction.WEST); } if (next != null) { stage.hero.setNextAction(next); } TUpdate(); gameBuilder.Display(); //heroTrans.transform.position = new Vector2 (stage.hero.pos.x * dungeon.tileSize.x/100,stage.hero.pos.x * dungeon.tileSize.x/100); }
public override bool Equals(object obj) { if (null == obj) { return(false); } VATConnectionLine vec = (VATConnectionLine)obj; if (vec != null) { return((leftPos.Equals(vec.leftPos) && rightPos.Equals(vec.rightPos)) || (leftPos.Equals(vec.rightPos) && rightPos.Equals(vec.leftPos))); } return(false); }
/// <summary> /// Return a Movement if it exists within the list. /// </summary> private Movement GetMovementIfExists(ArrayList list, IntVector2 originalPos) { if (list == null) { return(null); } foreach (Movement move in list) { if (originalPos.Equals(move.getDestinyPosition())) { return(move); } } return(null); }
public void UpdateCurrentPosition(IntVector2 currentPosition) { if (_currentPosition.Equals(IntVector2Constant.UNASSIGNET)) { UpdateTilesInfoTime(currentPosition); ResetTiles(); return; } int positionDisplacementX = currentPosition.x - _currentPosition.x; int positionDisplacementY = currentPosition.y - _currentPosition.y; if (Math.Abs(positionDisplacementX) >= _mapSectionSize || Math.Abs(positionDisplacementY) >= _mapSectionSize) { UpdateTilesInfoTime(currentPosition); ResetTiles(); } }
private bool IsPositionOccupated(IntVector2 nextPosition) { if (!_occupatedPossitionsMap.IsVacantPosition(nextPosition)) { _nextOccupiedPossition = nextPosition; if (_nextOccupiedPossition.Equals(_destination)) { NoWayToDestination?.Invoke(_nextOccupiedPossition); } else { NextTileOccupied?.Invoke(_nextOccupiedPossition); } return true; } return false; }
private void TryMoveToPosition(IntVector2 position) { var freePointToGo = _freePointToGoResolver.GetFreePoint(position); if (_freePointToGo.Equals(IntVector2Constant.UNASSIGNET)) { _freePointToGo = freePointToGo; BaseMoveToPosition(_freePointToGo); return; } if (freePointToGo.GetEmpiricalValueForPoint(AttackPosition) < _freePointToGo.GetEmpiricalValueForPoint(AttackPosition)) { _freePointToGo = freePointToGo; BaseMoveToPosition(_freePointToGo); } else { Wait(_freePointToGo, AttackPosition); } }
private static List <IntVector2> GetPathBetweenTiles(Tile[,] map, IntVector2 source, IntVector2 target) { //Djikstra Dictionary <IntVector2, int> distancesFromSource = new Dictionary <IntVector2, int>(); //List of distance from the source to tile X Dictionary <IntVector2, IntVector2> previousNodeFromSource = new Dictionary <IntVector2, IntVector2>(); //List of previous node in optimal path from source List <IntVector2> unoptimizedTiles = new List <IntVector2>(); for (int i = 0; i < WIDTH; i++) { for (int k = 0; k < HEIGHT; k++) { unoptimizedTiles.Add(new IntVector2(i, k)); } } foreach (IntVector2 pos in unoptimizedTiles) { distancesFromSource.Add(pos, int.MaxValue); previousNodeFromSource.Add(pos, null); if (pos.Equals(source)) { distancesFromSource[pos] = 0; //Distance from source to itself is 0 } } bool pathFound = false; while (unoptimizedTiles.Count > 0 && !pathFound) { //Get unoptimizedTiles entry with shortest distance in distancesFromSource int shortest = int.MaxValue; IntVector2 nextTile = unoptimizedTiles[0]; foreach (IntVector2 tile in unoptimizedTiles) { if (distancesFromSource[tile] < shortest) { shortest = distancesFromSource[tile]; nextTile = tile; } } if (shortest == int.MaxValue) //If we haven't found a linked node { return(null); //No path exists! } unoptimizedTiles.Remove(nextTile); //Display.SetBackColorOfPos(nextTile, ColorCatalog.lakeColor); //Display.FlushScreen(); if (nextTile.Equals(target)) { pathFound = true; } foreach (IntVector2 n in GetTileNeighbors(nextTile)) { IntVector2 neighbor = n; bool tileFound = false; foreach (IntVector2 t in unoptimizedTiles) { if (t.Equals(neighbor)) { tileFound = true; neighbor = t; break; } } if (tileFound) { if (map[neighbor.X, neighbor.Y].ObstructsActors()) { unoptimizedTiles.Remove(neighbor); } else { int newDistance = distancesFromSource[nextTile] + 1; if (newDistance < distancesFromSource[neighbor]) { distancesFromSource[neighbor] = newDistance; previousNodeFromSource[neighbor] = nextTile; } } } } } List <IntVector2> tilePath = new List <IntVector2>(); IntVector2 nextTileInFinalPath = target; foreach (IntVector2 pos in previousNodeFromSource.Keys) { if (nextTileInFinalPath.Equals(pos)) { nextTileInFinalPath = pos; } } while (previousNodeFromSource[nextTileInFinalPath] != null) { tilePath.Add(nextTileInFinalPath); nextTileInFinalPath = previousNodeFromSource[nextTileInFinalPath]; } tilePath.Add(source); tilePath.Reverse(); return(tilePath); }
// Random cell generating public void Generate() { // Calculate the number of cells int cellCount = (int)((this.fieldWidth * this.fieldLength) * ((double)this.fieldFillRate / 100)); int cellCounter = 0; // Starting point int x = Rnd.Range(0, this.fieldWidth); int y = Rnd.Range(0, this.fieldLength); IntVector2 p = new IntVector2(x, y); // Create the first cell createCell(p); // Increment the cell counter cellCounter++; // Generating operation IntVector2 d = IntVector2.Zero; List <IntVector2> chosenPosition = new List <IntVector2>() { p }; while (cellCounter < cellCount) { // Clone the directions list List <IntVector2> dirs = DirectionGuide.Directions; // Search for the available direction do { // Reset direction d = IntVector2.Zero; // Ceck if the list got empty if (dirs.Count == 0) { break; } // Get a random direction d = DirectionGuide.randomDirection(); // Remove from the cloned list dirs.Remove(d); } // If this position is occupied or out of bounds, keep searching for another direction while(chosenPosition.Contains(p + d)); // If we haven't found any available direction // Let us just find an available position if (d.Equals(IntVector2.Zero)) { do { // Find an available position x = Rnd.Range(0, this.fieldWidth); y = Rnd.Range(0, this.fieldLength); p = new IntVector2(x, y); }while (chosenPosition.Contains(p)); } else { // Create cell createCell(p + d); // Update progress position p += d; // Save this position chosenPosition.Add(p); // Increment counter cellCounter++; } } // Setting edges setEdges(); // Cell Division divideCells(); }