private void Spawn() { spawnWaiting = false; int x; int y; while (true) { x = Random.Range(0, 4); y = Random.Range(0, 4); if (grid[x, y] == null) { break; } } int startValue = (Random.value < 0.2f) ? 4 : 2; GameObject tempTile = Instantiate(tileFab, CoordinatesUtil.FromGridToCoordinates(x, y), Quaternion.Euler(0, 0, 0)); grid[x, y] = tempTile.GetComponent <Tile>(); grid[x, y].tileValue = startValue; grid[x, y].manager = this; }
private GeoPointList decodeWayNodesDoubleDelta(int numberOfWayNodes) { GeoPointList waySegment = new GeoPointList(numberOfWayNodes); // get the first way node latitude offset (VBE-S) double wayNodeLatitude = this.tilePosition.Latitude + CoordinatesUtil.microdegreesToDegrees(this.readBuffer.ReadSignedInt()); // get the first way node longitude offset (VBE-S) double wayNodeLongitude = this.tilePosition.Longitude + CoordinatesUtil.microdegreesToDegrees(this.readBuffer.ReadSignedInt()); if (wayNodeLatitude > 90) { wayNodeLatitude = 90; } if (wayNodeLatitude < -90) { wayNodeLatitude = -90; } // store the first way node waySegment.Add(new GeoPoint(wayNodeLatitude, wayNodeLongitude)); double previousSingleDeltaLatitude = 0; double previousSingleDeltaLongitude = 0; for (int wayNodesIndex = 1; wayNodesIndex < numberOfWayNodes; ++wayNodesIndex) { // get the way node latitude double-delta offset (VBE-S) double doubleDeltaLatitude = CoordinatesUtil.microdegreesToDegrees(this.readBuffer.ReadSignedInt()); // get the way node longitude double-delta offset (VBE-S) double doubleDeltaLongitude = CoordinatesUtil.microdegreesToDegrees(this.readBuffer.ReadSignedInt()); double singleDeltaLatitude = doubleDeltaLatitude + previousSingleDeltaLatitude; double singleDeltaLongitude = doubleDeltaLongitude + previousSingleDeltaLongitude; wayNodeLatitude = wayNodeLatitude + singleDeltaLatitude; wayNodeLongitude = wayNodeLongitude + singleDeltaLongitude; if (wayNodeLatitude > 90) { wayNodeLatitude = 90; } if (wayNodeLatitude < -90) { wayNodeLatitude = -90; } waySegment.Add(new GeoPoint(wayNodeLatitude, wayNodeLongitude)); previousSingleDeltaLatitude = singleDeltaLatitude; previousSingleDeltaLongitude = singleDeltaLongitude; } return(waySegment); }
private void ReadMapStartPosition(BufferStream readBuffer) { if (this.hasStartPosition) { double mapStartLatitude = CoordinatesUtil.microdegreesToDegrees(readBuffer.ReadInt()); double mapStartLongitude = CoordinatesUtil.microdegreesToDegrees(readBuffer.ReadInt()); try { this.startPosition = new GeoPoint(mapStartLatitude, mapStartLongitude); } catch (ArgumentException e) { throw new System.IO.InvalidDataException(e.Message); } } }
public static void ReadBoundingBox(BufferStream readBuffer, MapFileInfoBuilder mapFileInfoBuilder) { double minLatitude = CoordinatesUtil.microdegreesToDegrees(readBuffer.ReadInt()); double minLongitude = CoordinatesUtil.microdegreesToDegrees(readBuffer.ReadInt()); double maxLatitude = CoordinatesUtil.microdegreesToDegrees(readBuffer.ReadInt()); double maxLongitude = CoordinatesUtil.microdegreesToDegrees(readBuffer.ReadInt()); try { mapFileInfoBuilder.boundingBox = new BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude); } catch (ArgumentException e) { throw new System.IO.InvalidDataException(e.Message, e); } }
private GeoPoint readOptionalLabelPosition(bool featureLabelPosition) { if (featureLabelPosition) { // get the label position latitude offset (VBE-S) double latitude = this.tilePosition.Latitude + CoordinatesUtil.microdegreesToDegrees(this.readBuffer.ReadSignedInt()); // get the label position longitude offset (VBE-S) double longitude = this.tilePosition.Longitude + CoordinatesUtil.microdegreesToDegrees(this.readBuffer.ReadSignedInt()); return(new GeoPoint(latitude, longitude)); } return(null); }
public bool Move(int x, int y) { movePosition = CoordinatesUtil.FromGridToCoordinates(x, y); if (transform.position != (Vector3)movePosition) { if (manager.grid[x, y] != null) { combine = true; combined = true; cTile = manager.grid[x, y]; manager.grid[x, y] = null; } manager.grid[x, y] = GetComponent <Tile>(); manager.grid[Mathf.RoundToInt(CoordinatesUtil.FromCoordinatesToGrid(transform.position.x, transform.position.y).x), Mathf.RoundToInt(CoordinatesUtil.FromCoordinatesToGrid(transform.position.x, transform.position.y).y)] = null; return(true); } return(false); }
private List <Node> processNodes(int numberOfNodes) { List <Node> nodes = new List <Node>(); Tag[] NODETags = this.mapFileHeader.MapFileInfo.NodeTags; for (int elementCounter = numberOfNodes; elementCounter != 0; --elementCounter) { if (this.mapFileHeader.MapFileInfo.DebugFile) { // get and check the NODE signature this.signatureNode = this.readBuffer.ReadUTF8Encodedstring(SIGNATURE_LENGTH_NODE); if (!this.signatureNode.StartsWith("***nodestart")) { System.Diagnostics.Debug.WriteLine("invalid NODE signature: " + this.signatureNode); System.Diagnostics.Debug.WriteLine(DEBUG_SIGNATURE_BLOCK + this.signatureBlock); return(null); } } // get the NODE latitude offset (VBE-S) double latitude = this.tilePosition.Latitude + CoordinatesUtil.microdegreesToDegrees(this.readBuffer.ReadSignedInt()); // get the NODE longitude offset (VBE-S) double longitude = this.tilePosition.Longitude + CoordinatesUtil.microdegreesToDegrees(this.readBuffer.ReadSignedInt()); // get the special byte which encodes multiple flags byte specialbyte = (byte)this.readBuffer.ReadByte(); // bit 1-4 represent the layer byte layer = (byte)((specialbyte & NODE_LAYER_BITMASK) >> NODE_LAYER_SHIFT); // bit 5-8 represent the number of tag IDs byte numberOfTags = (byte)(specialbyte & NODE_NUMBER_OF_TAGS_BITMASK); List <Tag> tags = new List <Tag>(); // get the tag IDs (VBE-U) for (byte tagIndex = numberOfTags; tagIndex != 0; --tagIndex) { int tagId = this.readBuffer.ReadUnsignedInt(); if (tagId < 0 || tagId >= NODETags.Length) { System.Diagnostics.Debug.WriteLine("invalid node tag ID: " + tagId); if (this.mapFileHeader.MapFileInfo.DebugFile) { System.Diagnostics.Debug.WriteLine(DEBUG_SIGNATURE_NODE + this.signatureNode); System.Diagnostics.Debug.WriteLine(DEBUG_SIGNATURE_BLOCK + this.signatureBlock); } return(null); } tags.Add(NODETags[tagId]); } // get the feature bitmask (1 byte) byte featurebyte = (byte)this.readBuffer.ReadByte(); // bit 1-3 enable optional features bool featureName = (featurebyte & NODE_FEATURE_NAME) != 0; bool featureHouseNumber = (featurebyte & NODE_FEATURE_HOUSE_NUMBER) != 0; bool featureElevation = (featurebyte & NODE_FEATURE_ELEVATION) != 0; // check if the NODE has a name if (featureName) { tags.Add(new Tag(TAG_KEY_NAME, this.readBuffer.ReadUTF8Encodedstring())); } // check if the NODE has a house number if (featureHouseNumber) { tags.Add(new Tag(TAG_KEY_HOUSE_NUMBER, this.readBuffer.ReadUTF8Encodedstring())); } // check if the NODE has an elevation if (featureElevation) { tags.Add(new Tag(TAG_KEY_ELE, this.readBuffer.ReadSignedInt().ToString())); } if (latitude < 90 && latitude > -90) { nodes.Add(new Node(layer, tags, new GeoPoint(latitude, longitude))); } } return(nodes); }