Lightning

by Rotem12
generates lines, beams or lightning bolts [More]
To download this library for your Linux/Mac installation, enter this on your command line:

DreamDownload byond://Rotem12.Lightning##version=12

Emulator users, in the BYOND pager go to File | Open Location and enter this URL:

byond://Rotem12.Lightning##version=12

415 downloads
Version 1.10
Date added: Jun 21 2015
Last updated: Apr 30
9 fans
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.

Comments

Rotem12: (Jun 25 2015, 5:17 am)
I released a beam datum for all those who are interested in beams, there's also a parameter to control thickness, it comes handy with lines beams or if you're using a different icon size.

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.
Avidanimefan: (Jun 25 2015, 1:28 am)
Why not just generate all the rotations up front in a associated list and build the bolts based on the list?

This might have to be done on a player by player basis but it might be a decent alternative to generating them all on the fly.

I'm going to go play with this, I was actually thinking of putting something like a skill that allows the player to shoot lightning rods. Then another skill that releases electricity , which is drawn to anything struck with a lightning rod. Thanks for posting
Rotem12: (Jun 24 2015, 5:27 pm)
Bravo1 wrote:
The problem seems to be exacerbated the closer the destination is to the source.

I updated to attempt fix it, the update effects both normal and branched bolts, the segments are positioned slightly different now, I hope it looks better.

Aside from that, it also aims to branch out other bolts earlier than it did before, what I think happened was it attempted to branch when it's over 90% close to the end leaving it no room.

There's not much point if bolts branch out too late anyway so that should be better now.

EDIT: I also toyed with pooling, just pooling segments is not having any impact, I already know how to rotate an entire bolt, I'll work on it more later in hopes pooling entire bolts can help.
Bravo1: (Jun 24 2015, 2:56 pm)
I have it running at 60fps. Not sure if that's the cause of the issue or not.

The problem seems to be exacerbated the closer the destination is to the source.
Kaiochao: (Jun 24 2015, 2:40 pm)
I remember making a Force Lightning skill for an unreleased Star Wars fan-game years ago. It used Kunark's Line Drawer library and it looked pretty cool for being tile-based. Every couple tiles it would fork, and each segment would be attracted to certain objects like explosive barrels, droids, or other people.

This is much fancier-looking.