private void SpawnWall() { if (_timer > _waitTime) { CurrentIndex++; _timer = 0; _statePoint = (StatePoint)Mathf.RoundToInt(Random.Range(0, 4)); _arrayRbWall[CurrentIndex].velocity = Vector2.zero; switch (_statePoint) { case StatePoint.Up: _arrayWall[CurrentIndex].transform.position = new Vector3(_upPoint.position.x + Mathf.RoundToInt(Random.Range(0, Mathf.Abs(_upPoint.position.x * 2 + 1))), _upPoint.position.y, _upPoint.position.z); _arrayRbWall[CurrentIndex].AddForce(Vector2.down * _forceWall); break; case StatePoint.Down: _arrayWall[CurrentIndex].transform.position = new Vector3(_downPoint.position.x + Mathf.RoundToInt(Random.Range(0, Mathf.Abs(_downPoint.position.x * 2 + 1))), _downPoint.position.y, _downPoint.position.z); _arrayRbWall[CurrentIndex].AddForce(Vector2.up * _forceWall); break; case StatePoint.Left: _arrayWall[CurrentIndex].transform.position = new Vector3(_leftPoint.position.x, _leftPoint.position.y + Mathf.RoundToInt(Random.Range(0, Mathf.Abs(_leftPoint.position.y * 2 - 1))), _leftPoint.position.z); _arrayRbWall[CurrentIndex].AddForce(Vector2.right * _forceWall); break; case StatePoint.Right: _arrayWall[CurrentIndex].transform.position = new Vector3(_rightPoint.position.x, _leftPoint.position.y + Mathf.RoundToInt(Random.Range(0, Mathf.Abs(_leftPoint.position.y * 2 - 1))), _rightPoint.position.z); _arrayRbWall[CurrentIndex].AddForce(Vector2.left * _forceWall); break; default: break; } } }
/// <summary> /// 绘制线条 /// </summary> /// <param name="dc"></param> /// <param name="brush"></param> /// <param name="thickness"></param> /// <param name="p1"></param> /// <param name="p2"></param> private void DrawingLine(DrawingContext dc, double thickness, StatePoint p1, StatePoint p2, int index) { //Point结构里存的是位置的比例,这里要做一下转换 //Canvas的坐标原点在左上角 Point point1 = new Point(p1.point.X * canvas.ActualWidth, canvas.ActualHeight - canvas.ActualHeight * index / (brokenLines.Count + 1.0)); Point point2 = new Point(p2.point.X * canvas.ActualWidth, canvas.ActualHeight - (canvas.ActualHeight * index / (brokenLines.Count + 1.0) - thickness)); dc.DrawRectangle(Brush[p1.state], new Pen(), new Rect(point1, point2)); }
/// <summary> /// 获取拉伸过的曲线 /// </summary> /// <returns></returns> private List <BrokenLine> GetStretchLines(List <BrokenLine> lines) { if (lines.Count == 0) { return(lines); } //每n个绘制一次 int n = lines[0].Points.Count / pointDensity + 1; //一共nCount个点 //int nCount = lines[0].Points.Count / n; //转换X轴比例 for (int i = 0; i < lines.Count; ++i) { List <StatePoint> points = new List <StatePoint>(); //for (int j = 0; j < Math.Round((lines[i].Points.Count / ScaleRatioAxisX), MidpointRounding.AwayFromZero); j += n) for (int j = 0; j < (lines[i].Points.Count / ScaleRatioAxisX); j += n) { StatePoint p = lines[i].Points[j]; points.Add(p); } lines[i].Points = points; } #region ////每n个绘制一次 //int n = lines[0].Points.Count / pointDensity + 1; ////一共nCount个点 //int nCount = lines[0].Points.Count / n; ////转换X轴比例 //for (int i = 0; i < lines.Count; ++i) //{ // List<Point> points = new List<Point>(); // //for (int j = 0; j < lines[i].Points.Count; j += n) // //{ // //Point p = new Point(1.0 / (nCount - 1) * j / n, // //lines[i].Points[j].Y); // //if (p.X > 1) // //break; // //points.Add(p); // //} // //lines[i].Points = points; //} #endregion return(lines); }
private float GetCurrentPosition(float percent) { if (percent >= 1) { return(StatePoint[StatePoint.Length - 1].Position); } else if (percent <= 0) { return(StatePoint[0].Position); } StatePoint min = null; StatePoint max = null; for (int index = 0; index < StatePoint.Length; index++) { var point = StatePoint[index]; if (!(percent < point.Percent)) { continue; } min = StatePoint[index - 1]; max = point; break; } if (min == null || max == null) { return(0); } var L = max.Position - min.Position; var C = (percent - min.Percent) / (max.Percent - min.Percent); var f = min.Position + L * C; return(f); return(0); }
public override bool Equals(object obj) { StatePoint tempObj = (StatePoint)obj; return(_id.Equals(tempObj.ID)); }