示例#1
0
        public List<LV> Collision(Vector2 pos2, Vector2 pos1, out Line2 _wall)
        {
            _wall = null;
            List<LV> _HitPoints = new List<LV>();
            foreach(MapDatabase.Polygon _Polygon in _Polygons)
            {
                Vector2? _oldPoint = null;
                foreach(Point _p in _Polygon._Points)
                {
                    Vector2 _point = new Vector2((float)_p.X, (float)_p.Y);
                    if(_oldPoint != null)
                    {
                        Vector2? hitPoint = Physics.LineCollision(pos1, pos2, _point, _oldPoint.Value, true);

                        if(hitPoint != null)
                        {
                            Line2 _Line2 = new Line2 { _p1 = _point, _p2 = _oldPoint.Value };
                            _HitPoints.Add(new LV { _Vector2 = hitPoint.Value, _Line2 = _Line2 });
                        }
                    }
                    _oldPoint = _point;
                }
            }
            _HitPoints.Sort(new Comparison<LV>(delegate(LV a, LV b)
            {
                float adist = Vector2.Distance(pos1, a._Vector2);
                float bdist = Vector2.Distance(pos1, b._Vector2);
                if(adist > bdist) return 1;
                else if(adist < bdist) return -1;
                else return 0;
            }));
            return _HitPoints;
        }
示例#2
0
 public static Vector2 Reflect(Vector2 speed, Line2 wall)
 {
     Vector2 _vector = new Vector2(wall._p1.X - wall._p2.X, wall._p1.Y - wall._p2.Y);
     Calculator.RotateVector(ref _vector, 1.57f);
     _vector.Normalize();
     return Reflect(speed, _vector);
 }