private void Movement() { foreach (var point in route.GetPoints()) { Application.Current.Dispatcher.Invoke(delegate { marker_car.Position = point; this.Point = point; if (chel != null) { chel.setPosition(point); chel.marker_chelik.Position = point; Follow?.Invoke(this, null); } }); Thread.Sleep(1000); } if (chel == null) { Arrived?.Invoke(this, null); } else { MessageBox.Show("Приехали"); newThread.Abort(); chel = null; } }
private void MoveByRoute() { // последовательный перебор точек маршрута foreach (var point in route.getPoints()) { // делегат, возвращающий управление в главный поток Application.Current.Dispatcher.Invoke(delegate { // изменение позиции маркера carMarker.Position = point; this.point = point; if (pass != null) { pass.setPosition(point); pass.humanMarker.Position = point; } Follow?.Invoke(this, null); }); // задержка 500 мс Thread.Sleep(500); } if (pass == null) { Arrived?.Invoke(this, null); } else { pass = null; } }
internal void FireArrived(double ra, double dec, double zoom) { if (Arrived != null) { Arrived.Invoke(this, new ArrivedEventArgs(ra, dec, zoom)); } }
private void moveByRoute() { PointLatLng prevPoint = route.getPoints()[0]; foreach (var point in route.getPoints()) { Application.Current.Dispatcher.Invoke(delegate { carMarker.Position = point; double latDiff = point.Lat - prevPoint.Lat; double lngDiff = point.Lng - prevPoint.Lng; double angle = Math.Atan2(lngDiff, latDiff) * 180.0 / Math.PI; carMarker.Shape.RenderTransform = new RotateTransform { Angle = angle + 80 }; this.point = point; if (passengers.Count != 0) { passengers[0].setPoint(point); passengers[0].humanMarker.Position = point; } }); Thread.Sleep(500); prevPoint = point; } Arrived?.Invoke(this, null); }
// WebSocketに接続 public void Connect() { var random = new Random(); var server = WebSocketServers[random.Next(0, WebSocketServers.Length - 1)]; //クライアント側のWebSocketを定義 WebSocket = new WebSocket($"wss://{server}:3000/"); Timer = new Timer(s => WebSocket.Send("{}"), null, Timeout.Infinite, Timeout.Infinite); WebSocket.Opened += (s, e) => { WebSocket.Send("{\"time\":0}"); Debug.WriteLine("Opened"); Timer.Change(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30)); }; WebSocket.MessageReceived += (s, e) => { Arrived?.Invoke(JsonConvert.DeserializeObject <Lighitning>(e.Message)); }; WebSocket.Closed += (s, e) => { Debug.WriteLine("Closed"); Timer.Change(Timeout.Infinite, Timeout.Infinite); }; WebSocket.Error += (s, e) => Debug.WriteLine("Error"); WebSocket.Open(); }
// метод перемещения по маршруту private void MoveByRoute() { double pointss = 100 / route.getLocations().Count; foreach (var point in route.getLocations()) { this.location = point; Application.Current.Dispatcher.Invoke(delegate { this.location = point; marker.Position = point; gMap.Position = point; (Application.Current.MainWindow as MainWindow).Progress.Value += pointss + 1; if (pers != null) { pers.setLocation(point); pers.getMarker().Position = point; } }); Thread.Sleep(300); } // отправка события о прибытии после достижения последней точки маршрута if (pers == null) { Arrived?.Invoke(this, null); } else { pers.endOfJourney(); pers = null; } }
private void MoveByRoute() { foreach (var point in route.Points) { Application.Current.Dispatcher.Invoke(delegate { this.point = point; marker.Position = point; if (h != null) { h.marker.Position = point; Follow?.Invoke(this, null); } }); Thread.Sleep(1000); } if (h == null) { Arrived?.Invoke(this, null); } else { h = null; ArrivedToLocate?.Invoke(this, null); } }
private void MoveByRoute() { // последовательный перебор точек маршрута foreach (var point in route.GetPoints()) { // делегат, возвращающий управление в главный поток Application.Current.Dispatcher.Invoke(delegate { // изменение позиции маркера carMarker.Position = point; this.point = point; if (pass != null) { pass.setPosition(point); pass.humanMarker.Position = point; Follow?.Invoke(this, null); } }); // задержка 500 мс Thread.Sleep(500); } if (pass == null) { // отправка события о прибытии после достижения последней точки маршрута Arrived?.Invoke(this, null); // MessageBox.Show("Пункт назначения."); } else { MessageBox.Show("Вы прибыли в пункт назначения."); newThread.Abort(); pass = null; } }
private void MoveByRoute() { foreach (var Point in route.Points) { Application.Current.Dispatcher.Invoke(delegate { if (marker_car != null) { this.Point = Point; marker_car.Position = Point; } if (human != null) { human.marker_human.Position = Point; Follow?.Invoke(this, null); } }); Thread.Sleep(500); } if (human == null) { Arrived?.Invoke(this, null); } }
// метод перемещения по маршруту private void MoveByRoute() { // последовательный перебор точек маршрута foreach (var point in route.Points) { // делегат, возвращающий управление в главный поток Application.Current.Dispatcher.Invoke(delegate { this.point = point; // изменение позиции маркера marker.Position = point; if (human != null) { human.marker.Position = point; Follow?.Invoke(this, null); } }); // задержка 500 мс Thread.Sleep(500); } if (human == null) { // отправка события о прибытии после достижения последней точки маршрута Arrived?.Invoke(this, null); } else { MessageBox.Show("so, here we are!"); human = null; Arrived?.Invoke(this, null); } }
private void MoveByRoute() { try { foreach (var point in route.Points) { Application.Current.Dispatcher.Invoke(delegate { this.point = point; marker.Position = point; if (human != null) { human.marker.Position = point; human.point = point; Follow?.Invoke(this, null); } }); Thread.Sleep(1000); } if (human == null) { Arrived?.Invoke(this, null); } else { MessageBox.Show("Passenger arrived"); human = null; Arrived?.Invoke(this, null); } } catch { }; }
private void MoveByRoute() { double cAngle = 0; // последовательный перебор точек маршрута for (int i = 0; i < ePoints.Count; i++) { var point = ePoints[i]; // делегат, возвращающий управление в главный поток Application.Current.Dispatcher.Invoke(delegate { if (i < ePoints.Count - 10) { var nextPoint = ePoints[i + 10]; double latDiff = nextPoint.Lat - point.Lat; double lngDiff = nextPoint.Lng - point.Lng; // вычисление угла направления движения // latDiff и lngDiff - катеты прямоугольного треугольника double angle = Math.Atan2(lngDiff, latDiff) * 180.0 / Math.PI; // установка угла поворота маркера if (Math.Abs(angle - cAngle) > 10) //|| (a - angle < 0)) { cAngle = angle; carMarker.Shape.RenderTransform = new RotateTransform(angle, 10, 10); } } gMap.Position = carMarker.Position; // изменение позиции маркера carMarker.Position = point; this.point = point; if (pass != null) { pass.setPosition(point); pass.humanMarker.Position = point; pass.humanMarker.Shape.RenderTransform = new RotateTransform(cAngle, 16, 16); // FollowtheCar?.Invoke(this, null); } }); // задержка 5 мс Thread.Sleep(5); } // отправка события о прибытии после достижения последней точки маршрута if (pass == null) { Arrived?.Invoke(this, null); } else { pass = null; FollowtheCar?.Invoke(this, null); //newThread.Abort(); } }
private void MoveByRoute() { lock (lerpPoints) { double cAngle = 0; for (int i = 0; i < lerpPoints.Count; i++) { var point = lerpPoints[i]; if (Application.Current == null) { _moveThread?.Abort(); return; } Application.Current.Dispatcher.Invoke(() => { //if (i < lerpPoints.Count - 10) //{ // var nextPoint = lerpPoints[i + 10]; // double latDiff = nextPoint.Lat - point.Lat; // double lngDiff = nextPoint.Lng - point.Lng; // double angle = Math.Atan2(lngDiff, latDiff) * 180.0 / Math.PI - 90.0; // if (Math.Abs(angle - cAngle) > 11) // { // cAngle = angle; // _carMarker.Shape.RenderTransform = new RotateTransform { Angle = angle/*, CenterX = 20, CenterY = 26.67*/ }; // } //} _point = point; _carMarker.Position = point; if (_passenger.IsSeated) { _passenger.SetPosition(point); _passenger.GetMarker().Position = point; } PositionChanged?.Invoke(this, new CarPositionChangedArgs { Max = lerpPoints.Count, Progress = i }); }); Thread.Sleep(1); } if (_moveThread.IsAlive) { Application.Current.Dispatcher.Invoke(() => Arrived?.Invoke(this, EventArgs.Empty)); } if (!_passenger.IsSeated) { Application.Current.Dispatcher.Invoke(() => PassengerArrived?.Invoke(this, EventArgs.Empty)); } } }
private void moveByRoute() { foreach (var point in route) { { // вычисление разницы между двумя соседними точками по широте и долготе double latDiff = point.Lat - this.point.Lat; double lngDiff = point.Lng - this.point.Lng; // вычисление угла направления движения //latDiff и lngDiff - катеты прямоугольного треугольника double angle = Math.Atan2(lngDiff, latDiff) * 180.0 / Math.PI; this.point = point; Application.Current.Dispatcher.Invoke(delegate { // установка угла поворота маркера TransformGroup transform = new TransformGroup(); transform.Children.Add(new RotateTransform { Angle = angle - 90.0, CenterX = 14, CenterY = 14 }); transform.Children.Add(new TranslateTransform { X = -14, Y = -14 }); MainWindow.marker_taxiCar.Shape.RenderTransform = transform; //MainWindow.marker_taxiCar.Shape.RenderTransform = new RotateTransform { Angle = angle - 90.0, CenterX = 14, CenterY = 14 }; //MainWindow.marker_taxiCar.Shape.RenderTransform = new TranslateTransform { X = -14, Y = -14 }; MainWindow.marker_taxiCar.Position = this.point; MainWindow.map.Position = this.point; //добавить перемещение пассажиров foreach (Human passenger in passengers) { pos += 1; passenger.moveTo(this.point); MainWindow.marker_taxiClient.Position = passenger.getFocus(); Follow?.Invoke(this, EventArgs.Empty); } }); } Thread.Sleep(250); } if (passengers.Count() > 0) { MessageBox.Show("Такси приехало в пункт назначения"); } passengers.Clear(); route.Clear(); // отправка события о прибытии после достижения последней точки маршрута Arrived?.Invoke(this, null); }
public void Run() { Arrived += (int way) => { Console.WriteLine($"{RoadsNames[way]} - приехала машина и теперь там {Roads[way]}"); if (Roads[0] + Roads[2] > (Roads[1] + Roads[3]) * 2) { ChangeLight(new int[] { 0, 2 }); } else if (Roads[1] + Roads[3] > (Roads[0] + Roads[2]) * 2) { ChangeLight(new int[] { 1, 3 }); } else if (TrafficLightStatus[way]) { CrossroadsPermits[way].Set(); } }; for (int i = 0; i < Roads.Length; i++) { new Thread((object way) => { while (true) { Roads[(int)way]++; Arrived?.Invoke((int)way); Monitor.TryEnter(random, -1); int sleepTime = random.Next(200, 1001); Monitor.Exit(random); Thread.Sleep(sleepTime); } }).Start(i); new Thread((object way) => { while (true) { CrossroadsPermits[(int)way].WaitOne(); if (Roads[(int)way] > 0) { Console.WriteLine($"{RoadsNames[(int)way]} - машина едет {GetDirection()}, осталось {--Roads[(int)way]}"); Thread.Sleep(300); } else { CrossroadsPermits[(int)way].Reset(); } } }).Start(i); } }
private void Update() { transform.Translate(Vector2.left * _speed * Time.deltaTime); if (_player.transform.position.x >= gameObject.transform.position.x && !_isArrived) { Arrived?.Invoke(); _isArrived = true; } if (_countdown > 0) { _countdown -= Time.deltaTime; } else { Destroy(gameObject); } }
protected virtual void OnTriggerEnter(Collider other) { if (IsClient) { return; } if (IsArrived) { return; } var pf = other.gameObject.GetComponentInChildren <IPathFinderBase>(); if (pf != null && pf.IsArrived && other.gameObject.activeSelf && pf.Target == Target) { mNavMeshAgent.ResetPath(); Arrived?.Invoke(); IsArrived = true; mWaypointInst.SetActive(false); } }