public void Start(List <Level.VisualElement> elements) { int distance = elements.First().Size.Height; int speed = distance / steps; for (int j = 0; j < elements.Count; j++) { Level.VisualElement element = elements[j]; element.Location = new Point(element.Location.X, element.Location.Y - distance); } int last = steps - 1; count = 0; timer = new Timer(); timer.Interval = time / steps; timer.Tick += delegate { if (count > last) { timer.Dispose(); return; } if (count < last) { for (int j = 0; j < elements.Count; j++) { Level.VisualElement element = elements[j]; element.Location = new Point(element.Location.X, element.Location.Y + speed); } } else { int delta = distance - speed * last; for (int j = 0; j < elements.Count; j++) { Level.VisualElement element = elements[j]; element.Location = new Point(element.Location.X, element.Location.Y + delta); } } count++; level.Refresh(); }; timer.Disposed += delegate { if (AnimationFinish != null) { AnimationFinish(); } }; level.Refresh(); timer.Start(); }
public void Start(Level.VisualElement a, Level.VisualElement b) { Point distance = new Point(b.Location.X - a.Location.X, b.Location.Y - a.Location.Y); Point speed = new Point(distance.X / steps, distance.Y / steps); int last = steps - 1; count = 0; timer = new Timer(); timer.Interval = time / steps; timer.Tick += delegate { if (count > last) { timer.Dispose(); return; } if (count < last) { a.Location = new Point(a.Location.X + speed.X, a.Location.Y + speed.Y); b.Location = new Point(b.Location.X - speed.X, b.Location.Y - speed.Y); } else { a.Location = new Point(a.Location.X + (distance.X - speed.X * last), a.Location.Y + (distance.Y - speed.Y * last)); b.Location = new Point(b.Location.X - (distance.X - speed.X * last), b.Location.Y - (distance.Y - speed.Y * last)); } count++; level.Refresh(); }; timer.Disposed += delegate { if (AnimationFinish != null) { AnimationFinish(); } }; timer.Start(); }