Byte56's answer is very good, especially for the example image given where simulating the movement of each "ball" in the line will work well. I'll give you an alternative idea however which might work better, or might be easier to implement if you are trying to work with a dashed line (with or without animation), something like
-- -- -- --
- Calculate the angle at which your dashed line is aimed, and the distance (T) it should extend from the start (call it point S).
- Check for an intersection with the wall(s) you have present. There are lots of ways to do this, for example see this question.
- If there is no intersection, simply draw your line with whatever tools you use in your engine.
- If there is an intersection (call it point I):
- Draw the first section of your line between the start point and the intersection point SI, as in 3.
- Calculate the angle for the 2nd line segment by reflecting it in the surface you have intersected (see for example this question.
- Calculate the remaining line distance (T - SI)
- Draw the remaining line segment from point I with the appropriate angle.
- Repeat 2 - 4 if more intersections are possible.
As for animation in this case, that heavily depends on how you are drawing the line. If you are using a "dashed" texture you may be able to achieve this by:
- Tiling / Repeating the texture along the length of the line and then "animating" / adjusting the texture offsets each frame such that you achieve the illusion of the dashes moving along the line.
Otherwise, if using vectors etc.
- By similarly drawing the individual dashes based on some "offset" from the beginning of the line, and then moving this offset over time.