private void Move() { if (!IsMoving || IsStanding) { return; } if (CellToMove.Count != 0 && X == DestPoint.X && Y == DestPoint.Y) { DestPoint = new Point(CellToMove[CellToMove.Count - 1].X * Map.CollisionDim, CellToMove[CellToMove.Count - 1].Y * Map.CollisionDim); CellToMove.RemoveAt(CellToMove.Count - 1); IsMoving = true; } //float oX = this.X; //float oY = this.Y; if (this.Y == DestPoint.Y && this.X < DestPoint.X) { this.X += Speed; } else if (this.Y > DestPoint.Y && this.X < DestPoint.X) { this.X += (float)(Speed / Math.Sqrt(2)); this.Y -= (float)(Speed / Math.Sqrt(2)); } else if (this.Y > DestPoint.Y && this.X == DestPoint.X) { this.Y -= Speed; } else if (this.Y > DestPoint.Y && this.X > DestPoint.X) { this.X -= (float)(Speed / Math.Sqrt(2)); this.Y -= (float)(Speed / Math.Sqrt(2)); } else if (this.Y == DestPoint.Y && this.X > DestPoint.X) { this.X -= Speed; } else if (this.Y < DestPoint.Y && this.X > DestPoint.X) { this.X -= (float)(Speed / Math.Sqrt(2)); this.Y += (float)(Speed / Math.Sqrt(2)); } else if (this.Y < DestPoint.Y && this.X == DestPoint.X) { this.Y += Speed; } else if (this.Y < DestPoint.Y && this.X < DestPoint.X) { this.X += (float)(Speed / Math.Sqrt(2)); this.Y += (float)(Speed / Math.Sqrt(2)); } //for (int i = 0; i < Owner._listToDraw.Count; ++i) // if (!this.Equals(Owner._listToDraw[i]) && this.IsCollisionWith(Owner._listToDraw[i])) // { // this.X = oX; // this.Y = oY; // } if (Math.Abs(this.X - DestPoint.X) < Speed / Math.Sqrt(2) && Math.Abs(this.Y - DestPoint.Y) < Speed / Math.Sqrt(2)) { this.X = DestPoint.X; this.Y = DestPoint.Y; if (CellToMove.Count == 0 && IsMoving) { IsStanding = true; } } }
private void Move() { if (CellToMove.Count != 0 && X == DestPoint.X && Y == DestPoint.Y) { DestPoint = new Point(CellToMove[CellToMove.Count - 1].X * Map.CollisionDim, CellToMove[CellToMove.Count - 1].Y * Map.CollisionDim); CellToMove.RemoveAt(CellToMove.Count - 1); IsMoving = true; } if (this.Y == DestPoint.Y && this.X < DestPoint.X) { this.X += Speed; } else if (this.Y > DestPoint.Y && this.X < DestPoint.X) { this.X += (float)(Speed / Math.Sqrt(2)); this.Y -= (float)(Speed / Math.Sqrt(2)); } else if (this.Y > DestPoint.Y && this.X == DestPoint.X) { this.Y -= Speed; } else if (this.Y > DestPoint.Y && this.X > DestPoint.X) { this.X -= (float)(Speed / Math.Sqrt(2)); this.Y -= (float)(Speed / Math.Sqrt(2)); } else if (this.Y == DestPoint.Y && this.X > DestPoint.X) { this.X -= Speed; } else if (this.Y < DestPoint.Y && this.X > DestPoint.X) { this.X -= (float)(Speed / Math.Sqrt(2)); this.Y += (float)(Speed / Math.Sqrt(2)); } else if (this.Y < DestPoint.Y && this.X == DestPoint.X) { this.Y += Speed; } else if (this.Y < DestPoint.Y && this.X < DestPoint.X) { this.X += (float)(Speed / Math.Sqrt(2)); this.Y += (float)(Speed / Math.Sqrt(2)); } if (Math.Abs(this.X - DestPoint.X) < Speed / Math.Sqrt(2) && Math.Abs(this.Y - DestPoint.Y) < Speed / Math.Sqrt(2)) { this.X = DestPoint.X; this.Y = DestPoint.Y; if (CellToMove.Count == 0) { IsMoving = false; IsStanding = true; } } }