public void MakestartingPositions() { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { var key = map[y][x]; if (locations.Contains(key.ToString())) { float x1 = x / ((float)width), y1 = 1.0f - y / (float)height; var acc = 1; while (map[y][x + acc] == key) { acc++; } StartingPositions.Add( new Vec2F((2 * x + acc) / (float)width / 2.0f, y1)); // jump to the index after the platform. x += acc + 1; } } } }
private void MakeQuadStartingPositions() { // Go from this: // ... // .@. // ... // to this: // @#@ // ### // @#@ for (int i = StartingPositions.Count - 1; i >= 0; i--) { var startingPosition = StartingPositions[i]; // Check if this starting position's surroundings look like the above var topLeft = startingPosition.MoveLeft(1).MoveUp(1); var topCenter = startingPosition.MoveUp(1); var topRight = startingPosition.MoveRight(1).MoveUp(1); var left = startingPosition.MoveLeft(1); var right = startingPosition.MoveRight(1); var bottomLeft = startingPosition.MoveLeft(1).MoveDown(1); var bottomCenter = startingPosition.MoveDown(1); var bottomRight = startingPosition.MoveRight(1).MoveDown(1); var candidates = new List <GridPoint>() { topLeft, topCenter, topRight, left, right, bottomLeft, bottomCenter, bottomRight }; bool startingPositionMeetsCriteria = candidates.All(c => MazeCellType.Empty.Equals(MazeCells[c].Type) && !StartingPositions.Contains(c)); if (startingPositionMeetsCriteria) { MazeCells[topCenter].SetType(MazeCellType.Wall); MazeCells[left].SetType(MazeCellType.Wall); MazeCells[startingPosition].SetType(MazeCellType.Wall); MazeCells[right].SetType(MazeCellType.Wall); MazeCells[bottomCenter].SetType(MazeCellType.Wall); StartingPositions.RemoveAt(i); StartingPositions.Add(topLeft); StartingPositions.Add(topRight); StartingPositions.Add(bottomLeft); StartingPositions.Add(bottomRight); } } }
/// <summary> /// Parses out both starting positions and movement instructions. /// Items must be weaved so that each starting position is followed by movement instructions. /// For example: 1 2 1 2 1 2 1 2, with 1 being starting position and 2 being movement instruction. /// </summary> /// <param name="args">Ordered sets of positions and movement instructions.</param> public void ParseInstructions(string pathToFile) { try { using (StreamReader sReader = new StreamReader(pathToFile)) { string gridSize = sReader.ReadLine(); // Unused currently. while (sReader.Peek() >= 0) { StartingPositions.Add(sReader.ReadLine()); MovementInstructions.Add(sReader.ReadLine()); } } } catch (Exception ex) { Console.WriteLine($"Could not read the input file {pathToFile}."); Console.WriteLine(ex.Message); } }
private void ReadStartPositions(EndianReader reader) { var section = Sections[Section.StartPositions]; var position = OffsetById(section.Node, FieldId.Position); var orientation = OffsetById(section.Node, FieldId.Orientation); for (int i = 0; i < section.TagBlock.Count; i++) { var startPos = new StartPosition(this); var baseAddress = section.TagBlock.Pointer.Address + section.BlockSize * i; reader.Seek(baseAddress + position, SeekOrigin.Begin); startPos.Position = reader.ReadObject <RealVector3D>(); reader.Seek(baseAddress + orientation, SeekOrigin.Begin); startPos.Orientation = reader.ReadObject <RealVector2D>(); StartingPositions.Add(startPos); } }
public void UpdatePreview(Map map, byte[] imageData) { int width = map.HeightMap.MapWidth; int height = map.HeightMap.MapHeight; double scale = System.Math.Max(width, height) / 300.0; Reset(width, height); Image.WritePixels(new Int32Rect(0, 0, width, height), imageData, width, 0); // copy to array so that the generation can go on in the background var startingPositions = map.Objects.ToArray().Where(o => o.IsWaypoint && Regex.IsMatch(o.GetPropertyValue <string>("waypointName"), "Player_[1-8]_Start")); var resources = map.Objects.ToArray().Where(o => o.IsResource()); foreach (var startingPosition in startingPositions) { StartingPositions.Add(new OverlayViewModel(startingPosition.X / Map.TileWidth, height - startingPosition.Y / Map.TileWidth, scale)); } foreach (var resource in resources) { Resources.Add(new OverlayViewModel(resource.X / Map.TileWidth, height - resource.Y / Map.TileWidth, scale)); } }