Lightning can create a line, beam, lightning bolt or branched lightning bolt between two vectors.
Lightning GitHub
This was made following
this article. The article can be used for further explanation of how it works.
Usage is as simple as:
var/vector/start = new (x1 * 32, y1 * 32) // position in pixels
var/vector/dest = new (x2 * 32, y2 * 32) // position in pixels
var/line/l = new(start, dest)
l.Draw(usr.z)
var/bolt/b = new(start, dest)
b.Draw(usr.z)
Updates:
1.10
- Adds two colored bolt example to demo.
1.09
- changes demo to target middle of turf.
- Updates bar for new beam.
- Re-writes beam.
- Removes PIXEL_SCALE for beams.
- Fixes demo lines not working.
1.08
- Minor optimization.
- Changes demo bolt precision to shoot from the hand.
- Fixes force lightning not resetting loop.
- Adds PIXEL_SCALE flag to segment.
- Fixes fade parameter being a fixed value of 50.
1.07
- Renamed atan2 and rand to avoid conflicts.
1.06
- Drastically reduces appearance churn.
1.05
- Tiny optimization.
- Added force lightning demo. Click stickman faces to zap them.
1.04
- Added ability to draw lines as overlays.
- Bolts can now be drawn as overlays, this greatly improves CPU usage as well as adds the ability to rotate bolts by changing transform angle on a single object.
- Added a proc to rotate last made bolt.
1.03
- Added bar datum to bars, you can adjust the size of the bar via Adjust()
- Library now supports drawing on client.screen
- Line vectors can now be rotated
1.02
- Added beam datum to handle creation of beams.
- Added parameter to control the thickness of segments
- Segment type parameter is now defaulted to /obj/segment
1.01
- Added targets parameter to branched bolt allowing to set amount of branches amount or targets fire branched bolts at.
- The demo will now clear lines when mode is changed
- Fixes the library to allow different icon_size
For a full list of changes
click here.
Because of the new thickness parameter I moved /obj/segment from the demo to the library, the parameter now defaults to /obj/segment, you can still use a different type to generate different results.
I've yet to mess with beam "head", I didn't see much need for it with lightning but it may be nice to do so now.