public WorldBuilder(ShapeHandler shapeHandler, Vector2d Dimensions) { this.shapeHandler = shapeHandler; this.Dimensions = Dimensions; Generate(); }
void SpawnRandomShape(bool firstBlock) { ActiveShape = firstBlock ? ShapeHandler.InstantiateRandomShape(shapeSortingLayer) : NextShape; ActiveShape.gameObject.SetActive(false); ActiveShape.gameObject.transform.position = spawnLocationIndicator != null ? spawnLocationIndicator.transform.position : Vector3.zero; ActiveShape.ShapeLanded = OnActiveShapeLanded; NextShape = ShapeHandler.InstantiateRandomShape(shapeSortingLayer); NextShape.gameObject.transform.position = nextShapeLocationIndicator != null ? nextShapeLocationIndicator.transform.position : Vector3.zero;; if (ActiveShape.OverlapsAnotherShape()) { GameOver(); } else { ActiveShape.gameObject.SetActive(true); if (landingGuideShape) { Destroy(landingGuideShape?.gameObject); } landingGuideShape = ActiveShape.Clone(Color.grey, guideShapeSortingLayer); } }
public COLLISIONWORKEngine(string Title, Vector2d ScreenDimensions, ShapeHandler shapeHandler) { this.ScreenDimensions = ScreenDimensions; this.Title = Title; this.shapeHandler = shapeHandler; this.levelHandler = new LevelHandler(this.shapeHandler); this.Sound = new Sound(); Shape2D playerShape = new Shape2D(new Vector2d(200, 200), new Vector2d(50, 50), Color.Purple, TypeSpec.Player); player = new Player(playerShape, 200, Sound); GameWindow = new Window(); GameWindow.Size = new Size((int)ScreenDimensions.X, (int)ScreenDimensions.Y); GameWindow.FormBorderStyle = FormBorderStyle.FixedToolWindow; GameWindow.Text = this.Title; GameWindow.Paint += Renderer; GameLoopThread = new Thread(GameLoop); GameLoopThread.Start(); Application.Run(GameWindow); }
public override void OnLoad(ShapeHandler shapeHandler, Vector2d dimensions, Window window, LevelHandler levelHandler, Sound Sound, Player player) { this.shapeHandler = shapeHandler; this.levelHandler = levelHandler; shapeHandler.addShape(player.Shape); new WorldBuilder(shapeHandler, dimensions); input = new Input(playerShape, window, shapeHandler, Sound, player, levelHandler); Sound.Play(); }
public Input(Shape2D playerShape, Window window, ShapeHandler shapeHandler, Sound Sound, Player player, LevelHandler levelHandler) { this.playerShape = playerShape; this.shapeHandler = shapeHandler; this.Sound = Sound; this.player = player; this.levelHandler = levelHandler; lastPos = new Vector2d(); window.KeyDown += Window_KeyDown; window.KeyUp += Window_KeyUp; window.MouseClick += Window_MouseClick; }
public ShapeReader(IStreamProviderRegistry streamProviderRegistry) { if (streamProviderRegistry == null) { throw new ArgumentNullException("streamProviderRegistry"); } m_StreamProviderRegistry = streamProviderRegistry; ShapefileHeader = new ShapefileHeader(ShapeReaderStream); m_ShapeHandler = Shapefile.GetShapeHandler(ShapefileHeader.ShapeType); m_ShapeOffsetCache = new Lazy <long[]>(BuildOffsetCache, LazyThreadSafetyMode.ExecutionAndPublication); }
/// <summary> /// Initializes a new instance of the <see cref="ShapefileEnumerator"/> class. /// </summary> /// <param name="shapefile"></param> public ShapefileEnumerator(ShapefileReader shapefile) { _parent = shapefile; // create a file stream for each enumerator that is given out. This allows the same file // to have one or more enumerator. If we used the parents stream - than only one IEnumerator // could be given out. FileStream stream = new FileStream(_parent._filename, FileMode.Open, FileAccess.Read, FileShare.Read); _shpBinaryReader = new BigEndianBinaryReader(stream); // skip header - since parent has already read this. _shpBinaryReader.ReadBytes(100); ShapeGeometryType type = _parent._mainHeader.ShapeType; _handler = Shapefile.GetShapeHandler(type); if (_handler == null) throw new NotSupportedException("Unsuported shape type:" + type); }
public ShapefileWriter(IGeometryFactory geometryFactory, IStreamProviderRegistry streamProviderRegistry, ShapeGeometryType geomType) : this(geometryFactory) { _shpStream = streamProviderRegistry[StreamTypes.Shape].OpenWrite(true); _shxStream = streamProviderRegistry[StreamTypes.Index].OpenWrite(true); _geometryType = geomType; _shpBinaryWriter = new BigEndianBinaryWriter(_shpStream); _shxBinaryWriter = new BigEndianBinaryWriter(_shxStream); WriteShpHeader(_shpBinaryWriter, 0, new Envelope(0, 0, 0, 0)); WriteShxHeader(_shxBinaryWriter, 0, new Envelope(0, 0, 0, 0)); _shapeHandler = Shapefile.GetShapeHandler(geomType); }
/// <summary> /// Adds a shape to the shapefile. You must have used the constrcutor with a filename to use this method! /// </summary> /// <param name="geometry"></param> public void Write(IGeometry geometry) { if (_shpBinaryWriter == null) { throw new NotSupportedException("Writing not started, use the Constructor with a filename!"); } WriteRecordToFile(_shpBinaryWriter, _shxBinaryWriter, _shapeHandler, geometry, _numFeaturesWritten + 1); _numFeaturesWritten++; var env = geometry.EnvelopeInternal; var bounds = ShapeHandler.GetEnvelopeExternal(geometry.PrecisionModel, env); if (_totalEnvelope == null) { _totalEnvelope = bounds; } else { _totalEnvelope.ExpandToInclude(bounds); } }
/// <summary> /// Reads the shapefile and returns a GeometryCollection representing all the records in the shapefile. /// </summary> /// <returns>GeometryCollection representing every record in the shapefile.</returns> public IGeometryCollection ReadAll() { var list = new List <IGeometry>(); ShapeGeometryType type = _mainHeader.ShapeType; ShapeHandler handler = Shapefile.GetShapeHandler(type); if (handler == null) { throw new NotSupportedException("Unsupported shape type:" + type); } int i = 0; foreach (IGeometry geometry in this) { list.Add(geometry); i++; } IGeometry[] geomArray = GeometryFactory.ToGeometryArray(list); return(_geometryFactory.CreateGeometryCollection(geomArray)); }
/// <summary> /// Adds blocks of the shape to the gridHandler gameobject and sets /// their layer to obstacle /// </summary> /// <param name="Shape">Shape to be deconstructed and added to grid</param> public bool AddToGrid(ShapeHandler Shape) { List <Transform> blocksToAdd = new List <Transform>(); foreach (Transform block in Shape.transform) { int candidRow = GetBlockRowIndex(block); if (IsRowValid(candidRow)) { rowDictionary[candidRow].Add(block.gameObject); block.gameObject.layer = LayerMask.NameToLayer("obstacle"); blocksToAdd.Add(block); } else { return(false); } } blocksToAdd.ForEach((block) => block.parent = gridObstacles.transform); return(true); }
public ShapefileWriter(IGeometryFactory geometryFactory, string filename, ShapeGeometryType geomType) : this(geometryFactory) { var folder = Path.GetDirectoryName(filename) ?? "."; var file = Path.GetFileNameWithoutExtension(filename); if (string.IsNullOrEmpty(file)) { throw new ArgumentException(string.Format("Filename '{0}' is not valid", filename), "filename"); } filename = Path.Combine(folder, file); _shpStream = new FileStream(filename + ".shp", FileMode.Create); _shxStream = new FileStream(filename + ".shx", FileMode.Create); _geometryType = geomType; _shpBinaryWriter = new BigEndianBinaryWriter(_shpStream); _shxBinaryWriter = new BigEndianBinaryWriter(_shxStream); WriteShpHeader(_shpBinaryWriter, 0, new Envelope(0, 0, 0, 0), geomType); WriteShxHeader(_shxBinaryWriter, 0, new Envelope(0, 0, 0, 0), geomType); _shapeHandler = Shapefile.GetShapeHandler(geomType); }
public ShapeReader(string shapeFilePath) { if (shapeFilePath == null) { throw new ArgumentNullException("shapeFilePath"); } if (string.IsNullOrWhiteSpace(shapeFilePath)) { throw new ArgumentException("shapeFilePath", "Path to shapefile can't be empty"); } if (!File.Exists(shapeFilePath)) { throw new FileNotFoundException("Given shapefile doesn't exist", shapeFilePath); } m_ShapeFilePath = shapeFilePath; m_ShapeFileHeader = new ShapefileHeader(ShapeReaderStream); m_ShapeHandler = Shapefile.GetShapeHandler(ShapefileHeader.ShapeType); m_ShapeOffsetCache = new Lazy <long[]>(BuildOffsetCache, LazyThreadSafetyMode.ExecutionAndPublication); }
private static /*int*/ void WriteRecordToFile(BigEndianBinaryWriter shpBinaryWriter, BigEndianBinaryWriter shxBinaryWriter, ShapeHandler handler, IGeometry body, int oid) { if (body == null || body.IsEmpty) { WriteNullShapeRecord(shpBinaryWriter, shxBinaryWriter, oid); return; } // Get the length of each record (in bytes) var recordLength = handler.ComputeRequiredLengthInWords(body); // Get the position in the stream var pos = shpBinaryWriter.BaseStream.Position; shpBinaryWriter.WriteIntBE(oid); shpBinaryWriter.WriteIntBE(recordLength); // update shapefile index (position in words, 1 word = 2 bytes) var posWords = pos / 2; shxBinaryWriter.WriteIntBE((int)posWords); shxBinaryWriter.WriteIntBE(recordLength); handler.Write(body, shpBinaryWriter, body.Factory); /*return recordLength;*/ }
private static /*int*/ void WriteRecordToFile(BigEndianBinaryWriter shpBinaryWriter, BigEndianBinaryWriter shxBinaryWriter, ShapeHandler handler, Geometry body, int oid) { if (body == null || body.IsEmpty) { WriteNullShapeRecord(shpBinaryWriter, shxBinaryWriter, oid); return; } // Get the length of each record (in bytes) int recordLength = handler.ComputeRequiredLengthInWords(body); // Get the position in the stream, needed for shxBinaryWriter; since // shpBinaryWriter.BaseStream flushes pending writes, only fetch it // if we're going to actually touch the shx file. long posWords = shxBinaryWriter == null ? 0 : shpBinaryWriter.BaseStream.Position / 2; shpBinaryWriter.WriteIntBE(oid); shpBinaryWriter.WriteIntBE(recordLength); // update shapefile index (position in words, 1 word = 2 bytes) if (shxBinaryWriter != null) { shxBinaryWriter.WriteIntBE((int)posWords); shxBinaryWriter.WriteIntBE(recordLength); } handler.Write(body, shpBinaryWriter, body.Factory); /*return recordLength;*/ }
public void Start() { var win = App.Current.MainWindow as Designer; Polygon poly = new Polygon(); var MapCanvas = win.MapCanvas; MapCanvas.CaptureMouse(); poly.FillRule = FillRule.Nonzero; poly.Fill = win.backgroundColorPanel.Background; poly.Stroke = win.foregroundColorPanel.Background; poly.StrokeThickness = 1; MapCanvas.Children.Add(poly); MapCanvas.PreviewMouseRightButtonDown += (sender, args) => { if (finished) { return; } MapCanvas.ReleaseMouseCapture(); //poly.Points.RemoveAt(poly.Points.Count ); var grd = new Viewbox(); MapCanvas.Children.Remove(poly); grd.Child = (poly); var miny = poly.Points.Min(_ => _.Y); var minx = poly.Points.Min(_ => _.X); Canvas.SetTop(grd, miny); Canvas.SetLeft(grd, minx); PointCollection pc = new PointCollection(); for (int index = 0; index < poly.Points.Count; index++) { var point = poly.Points[index]; point.Y = point.Y - miny; point.X = point.X - minx; pc.Add(point); } poly.Points = pc; poly.Margin = new Thickness(0); poly.VerticalAlignment = VerticalAlignment.Stretch; poly.HorizontalAlignment = HorizontalAlignment.Stretch; MapCanvas.Children.Add(grd); ShapeHandler.SelectedImage = grd; ShapeHandler.InitImageHandlers(ref grd); finished = true; Dispose(); }; MapCanvas.PreviewMouseLeftButtonDown += (sender, args) => { if (finished) { return; } var pos = args.GetPosition(MapCanvas); if (poly.Points.Count == 0) { poly.Points.Add(pos); poly.Points.Add(pos); } else { poly.Points[poly.Points.Count - 1] = pos; poly.Points.Add(pos); } }; MapCanvas.PreviewMouseMove += (sender, args) => { if (finished) { return; } var pos = args.GetPosition(MapCanvas); if (poly.Points.Count != 0) { poly.Points[poly.Points.Count - 1] = pos; } }; }
public abstract void OnLoad(ShapeHandler shapeHandler, Vector2d dimensions, Window GameWindow, LevelHandler levelHandler, Sound sound, Player player);
/// <summary> /// Writes a shapefile to disk. /// </summary> /// <remarks> /// Assumes the type given for the first geometry is the same for all subsequent geometries. /// For example, is, if the first Geometry is a Multi-polygon/ Polygon, the subsequent geometies are /// Muli-polygon/ polygon and not lines or points. /// The dbase file for the corresponding shapefile contains one column called row. It contains /// the row number. /// </remarks> /// <param name="filename">The filename to write to (minus the .shp extension).</param> /// <param name="geometryCollection">The GeometryCollection to write.</param> public void Write(IGeometryCollection geometryCollection) { //FileStream shpStream = new FileStream(filename + ".shp", FileMode.Create); //FileStream shxStream = new FileStream(filename + ".shx", FileMode.Create); shpStream = new MemoryStream(); shxStream = new MemoryStream(); BigEndianBinaryWriter shpBinaryWriter = new BigEndianBinaryWriter(shpStream); BigEndianBinaryWriter shxBinaryWriter = new BigEndianBinaryWriter(shxStream); // assumes ShapeHandler handler = Shapefile.GetShapeHandler(Shapefile.GetShapeType(geometryCollection.Geometries[0])); IGeometry body; int numShapes = geometryCollection.NumGeometries; // calc the length of the shp file, so it can put in the header. int shpLength = 50; for (int i = 0; i < numShapes; i++) { body = (IGeometry)geometryCollection.Geometries[i]; shpLength += 4; // length of header in WORDS shpLength += handler.GetLength(body); // length of shape in WORDS } int shxLength = 50 + (4 * numShapes); // write the .shp header ShapefileHeader shpHeader = new ShapefileHeader(); shpHeader.FileLength = shpLength; // get envelope in external coordinates Envelope env = geometryCollection.EnvelopeInternal as Envelope; Envelope bounds = ShapeHandler.GetEnvelopeExternal(geometryFactory.PrecisionModel, env); shpHeader.Bounds = bounds; // assumes Geometry type of the first item will the same for all other items // in the collection. shpHeader.ShapeType = Shapefile.GetShapeType(geometryCollection.Geometries[0]); shpHeader.Write(shpBinaryWriter); // write the .shx header ShapefileHeader shxHeader = new ShapefileHeader(); shxHeader.FileLength = shxLength; shxHeader.Bounds = shpHeader.Bounds; // assumes Geometry type of the first item will the same for all other items in the collection. shxHeader.ShapeType = Shapefile.GetShapeType(geometryCollection.Geometries[0]); shxHeader.Write(shxBinaryWriter); // write the individual records. int _pos = 50; // header length in WORDS for (int i = 0; i < numShapes; i++) { body = geometryCollection.Geometries[i]; int recordLength = handler.GetLength(body); shpBinaryWriter.WriteIntBE(i + 1); shpBinaryWriter.WriteIntBE(recordLength); shxBinaryWriter.WriteIntBE(_pos); shxBinaryWriter.WriteIntBE(recordLength); _pos += 4; // length of header in WORDS handler.Write(body, shpBinaryWriter, geometryFactory); _pos += recordLength; // length of shape in WORDS } shxBinaryWriter.Flush(); //shxStream.Seek(0, SeekOrigin.Begin); ////shxBinaryWriter.Close(); shpBinaryWriter.Flush(); //shpStream.Seek(0, SeekOrigin.Begin); //shpBinaryWriter.Close(); // WriteDummyDbf(filename + ".dbf", numShapes); }
private void OnEnable() { shapeHandler = (ShapeHandler)target; selectionManager = new SelectionManager(); }
public void Start() { var win = App.Current.MainWindow as Designer; Ellipse ellipse = new Ellipse(); var started = false; var MapCanvas = win.MapCanvas; MapCanvas.CaptureMouse(); ellipse.Fill = win.backgroundColorPanel.Background; ellipse.Stroke = win.foregroundColorPanel.Background; ellipse.StrokeThickness = 1; MapCanvas.Children.Add(ellipse); MapCanvas.PreviewMouseLeftButtonUp += (sender, args) => { if (finished) { return; } MapCanvas.ReleaseMouseCapture(); //poly.Points.RemoveAt(poly.Points.Count ); var grd = new Viewbox(); MapCanvas.Children.Remove(ellipse); grd.Child = (ellipse); var miny = Canvas.GetTop(ellipse); var minx = Canvas.GetLeft(ellipse); Canvas.SetTop(grd, miny); Canvas.SetLeft(grd, minx); ellipse.Margin = new Thickness(0); ellipse.VerticalAlignment = VerticalAlignment.Stretch; ellipse.HorizontalAlignment = HorizontalAlignment.Stretch; MapCanvas.Children.Add(grd); ShapeHandler.SelectedImage = grd; ShapeHandler.InitImageHandlers(ref grd); finished = true; Dispose(); }; Point startPoint = new Point(); MapCanvas.PreviewMouseLeftButtonDown += (sender, args) => { if (finished) { return; } var pos = args.GetPosition(MapCanvas); Canvas.SetTop(ellipse, pos.Y); Canvas.SetLeft(ellipse, pos.X); startPoint = pos; started = true; }; MapCanvas.PreviewMouseMove += (sender, args) => { if (finished || !started) { return; } var pos = args.GetPosition(MapCanvas); var x = Math.Min(pos.X, startPoint.X); var y = Math.Min(pos.Y, startPoint.Y); var w = Math.Max(pos.X, startPoint.X) - x; var h = Math.Max(pos.Y, startPoint.Y) - y; ellipse.Width = w; ellipse.Height = h; Canvas.SetLeft(ellipse, x); Canvas.SetTop(ellipse, y); }; }
/// <summary> /// Reads a record from the specified stream. /// </summary> /// <param name="stream">A System.IO.Stream instance to read</param> /// <param name="recordOffset">An offset of record</param> /// <param name="bounds">An object representing a bounds of the reading area</param> public ShapeFileRecord ReadRecord(Stream stream, int?recordOffset, BoundingRectangle bounds) { #region old //if (recordOffset != null) // stream.Seek(recordOffset.Value, 0); //ShapeFileRecord record = new ShapeFileRecord(); //record.Offset = stream.Position; //// заголовок записи //record.RecordNumber = ShapeFile.ReadInt32_BE(stream); //record.ContentLength = ShapeFile.ReadInt32_BE(stream); //// тип геометрической фигуры //record.ShapeType = ShapeFile.ReadInt32_LE(stream); //bool wasRead = false; //switch (record.ShapeType) //{ // case (int)ShapeType.NullShape: // break; // case (int)ShapeType.Point: // wasRead = ShapeFile.ReadPoint(stream, bounds, record); // break; // case (int)ShapeType.PolyLine: // wasRead = ShapeFile.ReadPolygon(stream, bounds, record); // break; // case (int)ShapeType.Polygon: // wasRead = ShapeFile.ReadPolygon(stream, bounds, record); // break; // case (int)ShapeType.Multipoint: // wasRead = ShapeFile.ReadMultipoint(stream, bounds, record); // break; // default: // { // string msg = String.Format(System.Globalization.CultureInfo.InvariantCulture, "ShapeType {0} is not supported.", (int)record.ShapeType); // throw new InvalidDataException(msg); // } //} //if (wasRead) //{ // this._records.Add(record); // return record; //} //else return null; #endregion #region New if (recordOffset != null) { stream.Seek(recordOffset.Value, 0); } ShapeFileRecord record = new ShapeFileRecord(); record.Offset = stream.Position; // заголовок записи //BigEndianBinaryReader reader = new BigEndianBinaryReader(stream); //record.RecordNumber = reader.ReadInt32BE();// ShapeFile.ReadInt32_BE(stream); //record.ContentLength = reader.ReadInt32BE();// ShapeFile.ReadInt32_BE(stream); record.RecordNumber = stream.ReadInt32BE(); // ShapeFile.ReadInt32_BE(stream); record.ContentLength = stream.ReadInt32BE(); // ShapeFile.ReadInt32_BE(stream); // тип геометрической фигуры record.ShapeType = stream.ReadInt32(); //.ReadInt32BE();// ShapeFile.ReadInt32_LE(stream); ShapeHandler handler = ShapeFile.GetShapeHandler((ShapeType)record.ShapeType); if (handler.Read(stream, bounds, record)) { this._records.Add(record); return(record); } else { return(null); } #endregion }
public LevelHandler(ShapeHandler shapeHandler) { r = new Random(); this.shapeHandler = shapeHandler; }