public static Bunch <Point> Trace(Point _start, Point _end) { Bunch <Point> @out = new Bunch <Point>(); Point dif = _end - _start; if (dif.X != 0 || dif.Y != 0) { if (Meth.Abs(dif.X) > Meth.Abs(dif.Y)) { for (int x = 0; x <= Meth.Abs(dif.X); x++) { int nx = _start.X + x * Meth.Sign(dif.X); int ny = Meth.Round(_start.Y + dif.Y * (x * Math.Sign(dif.X) / (float)dif.X)); @out.Add(new Point(nx, ny)); } } else { for (int y = 0; y <= Meth.Abs(dif.Y); y++) { int nx = Meth.Round(_start.X + dif.X * (y * Meth.Sign(dif.Y) / (float)dif.Y)); int ny = _start.Y + y * Meth.Sign(dif.Y); @out.Add(new Point(nx, ny)); } } } else { @out.Add(_start); } return(@out); }
public override void OnDrag(Vector _position) { if (!this.StartedDragging && _position != this.Position) { this.StartedDragging = true; } if (this.StartedDragging) { if (this.Type.Lock.HasValue == !Parent.IsKeyPressed(Key.LControl)) { Vector l = (this.Type.Lock.HasValue ? this.Type.Lock.Value : (Vector)this.Parent.TileSize); Point t = new Point(Meth.Round(_position.X / Parent.TileSize.X - l.X), Meth.Round(_position.Y / Parent.TileSize.Y - l.Y)); this.Position = (t + l) * Parent.TileSize; } else { this.Position = (Point)_position; } this.Layer.EntitiesChanged = true; } }