Example #1
0
        public CollisionResult Update(System.Drawing.Point position, int rotation, bool drivingForward)
        {
            CollisionResult result = new CollisionResult();

            List<Vector> frontBack;
            if (drivingForward)
            {
                frontBack = Front;
            }
            else
            {
                frontBack = Back;
            }

            var fb = new Vector[PointsPerSide];
            var left = new Vector[PointsPerSide];
            var right = new Vector[PointsPerSide];
            for (int i = 0; i < PointsPerSide; i++)
            {
                fb[i] = rotateVector(frontBack[i], rotation);
                fb[i].X += position.X;
                fb[i].Y += position.Y;

                left[i] = rotateVector(Left[i], rotation);
                left[i].X += position.X;
                left[i].Y += position.Y;

                right[i] = rotateVector(Right[i], rotation);
                right[i].X += position.X;
                right[i].Y += position.Y;
            }

            if (drivingForward)
                result.Front = collision.Collides(fb, (int)position.X, (int)position.Y);
            else
                result.Back = collision.Collides(fb, (int)position.X, (int)position.Y);

            result.Left = collision.Collides(left, (int)position.X, (int)position.Y);
            result.Right = collision.Collides(right, (int)position.X, (int)position.Y);

            return result;
        }