public void TestCreateFrom3() { var rectangle = MercatorRectangle.Earth; var tiles = TileRectangle.CreateFrom(rectangle, 2); tiles.X.Should().Be(0); tiles.Y.Should().Be(0); tiles.Z.Should().Be(2); tiles.Width.Should().Be(4); tiles.Height.Should().Be(4); tiles.Count.Should().Be(16); }
public void Update() { var p = this.collider.Position; var r = this.collider.Radius; var d = new Difference2(r, r); var tiles = this.game.Level.RectangleIntersecting(p - d, d * 2); if (tiles == this.currentTiles) return; this.clearTuples(); this.tileCount = tiles.Tiles; this.ensureTuples(); this.fillTiles(tiles); this.currentTiles = tiles; }
protected override void OnLeftMouseButtonDown(LevelMapEditor editor, TileLocation location, Keys modifierKeys) { editor.Selection = (modifierKeys & Keys.Shift) == Keys.Shift ? TileRectangle.FromLTRB(editor.Selection.Left, editor.Selection.Top, location.X, location.Y) : new TileRectangle(location, 1, 1); }
protected override void OnLeftMouseButtonMove(LevelMapEditor editor, TileLocation location, Keys modifierKeys) { editor.Selection = TileRectangle.FromLTRB(editor.Selection.Left, editor.Selection.Top, location.X, location.Y); }
public IEnumerable<Tile<TileInfo>> TilesIn(TileRectangle rectangle) { var x0 = rectangle.X0; var y0 = rectangle.Y0; var x1 = rectangle.X1; var y1 = rectangle.Y1; for (var y = y0; y <= y1; y++) for (var x = x0; x <= x1; x++) { yield return new Tile<TileInfo>(this.tilemap, x, y); } }
public void Paste() { if (NativeMethods.OpenClipboard(new HandleRef(this, Handle))) { try { var hMem = NativeMethods.GetClipboardData(NativeMethods.RegisterClipboardFormat(Level.ChipEditMapSectFormat)); if (hMem != IntPtr.Zero) { unsafe { var mapSect = (NativeMethods.CHIPEDIT_MAPSECT *)NativeMethods.GlobalLock(hMem); try { _history.BeginCompoundCommand("Paste"); var width = mapSect->width; var height = mapSect->height; var buffer = (byte *)(&mapSect->marker + 1); var upperLength = *(ushort *)buffer; buffer += sizeof(ushort); var upperLayer = new TileMap(buffer, upperLength); buffer += upperLength; var lowerLength = *(ushort *)buffer; buffer += sizeof(ushort); var lowerLayer = new TileMap((byte *)buffer, lowerLength); buffer += lowerLength; switch (_owner.LayerMode) { case LayerMode.UpperLayer: for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (x + selection.X < 32 && y + selection.Y < 32) { SetUpperLayerTile(new TileLocation(x + selection.X, y + selection.Y), upperLayer[x, y]); } } } break; case LayerMode.LowerLayer: for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (x + selection.X < 32 && y + selection.Y < 32) { SetLowerLayerTile(new TileLocation(x + selection.X, y + selection.Y), lowerLayer[x, y]); } } } break; case LayerMode.Both: for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (x + selection.X < 32 && y + selection.Y < 32) { SetUpperLayerTile(new TileLocation(x + selection.X, y + selection.Y), upperLayer[x, y]); SetLowerLayerTile(new TileLocation(x + selection.X, y + selection.Y), lowerLayer[x, y]); } } } break; default: break; } Selection = new TileRectangle(selection.X, selection.Y, width, height); } finally { NativeMethods.GlobalUnlock(hMem); _history.EndCompoundCommand(); } } } } finally { NativeMethods.CloseClipboard(); } } Invalidate(new Rectangle(selection.X * _owner.TileSize, selection.Y * _owner.TileSize, selection.Width * _owner.TileSize, selection.Height * _owner.TileSize)); }
private void fillTiles(TileRectangle tiles) { var i = 0; foreach (var tile in this.game.Level.TilesIn(tiles)) { var node = this.nodes[i++]; node.Tile = tile; tile.Value.ProjectileColliders.AddLast(node.Node); } }
public void AddRectangle(TileRectangle rect) { _rectangles.Add(rect); }