MV/MZ SDJB_DrawLinesBetween

PluginName: SDJB_DrawLinesBetween
Author: ShadowDragon

DrawLinesBetween.gif


Cool feature, draw progress line (0-1), for skill tree in one way.
DrawLinesBetween2.gif


CTBolt created a nice plugin "CreateLinesBetween", but has some issues
and bugs, and was for MZ only.

As I re-create it from scratch and some logic from his, I improved performance
and optimized it to make it work for MV and MZ.

I also added some features, see spoiler how to use.

Spoiler: How to use
Code:
 Introduction
 ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞
 Create Lines between player to event, follower to event, event to event
 or map coordinates (x,y) in tiles or pixels.


 How to Use
 ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞
 There are some scriptcalls you can use to make it clean, easy and
 best of all, user-friendly and efficient.

 There are 3 ways to set it up!
 
 $gameScreen.setLine(connect, options)

 connect:
   => There are 2 ways for connect the sources
   1) Characters connect is using an array [A, B]
      
        0 = player
      < 0 = followers
      > 0 = event ID

 Example:
   $gameScreen.setLine([0, 3])    //=> player ↔ event 3
   $gameScreen.setLine([-2, 7])   //=> follower 2 ↔ event 7
   $gameScreen.setLine([2, 5])    //=> event 2 ↔ event 5
 
 You can use options to customize the line:
   pixel, zIndex, width, color, progress, speed, alpha and pulse.

 Example:
   $gameScreen.setLine([2,5], {width: 2, color:0x00ff00, alpha: 1});

 zIndex:
    Sets the line priority, higher values appear above lower values.
    Default is 0.

 width:
    The thickness of the line (default is 2)

 mode:
    Determines how the line is animated.
       "progress" = line is drawn over time.
           The initial progress of the line (0 → 1). Default is 1 (instant).
           Can be used to start the line partially drawn.

       "pulse"    = line continuously grows and shrinks in width.
           Enables a pulsing width animation.
           The value is the maximum additional width applied during the pulse cycle.

           width: 2, pulse: 2  //=> 2px ↔ 4px
           width: 2, pulse: 3  //=> 2px ↔ 5px

    Default is "none".

 speed:
    Controls the animation speed.
       mode: "progress"
           Number of frames required to draw the line completely.

       mode: "pulse"
           Number of frames required to expand from the base width
           to the maximum pulse width.

 color:
    The color of the line in hex: "#FF0000" or 0xFF0000, as both works
    The default color is white (0xFFFFFF)

 alpha:
    The alpha color, which by default is 1


   2) Coordinates connects is using an object array [{x:n, y:n},{x:n, y:n}]
      This can also go in 2 ways, by tiles or by pixels (default false)

      By default, pixels is false, meaning: coordinate by tiles.

 Example:
    Start at Map X 4, Y 6 and end at X 10, Y 48:
    $gameScreen.setLine([{x:4,y:6}, {x:10,y:48}])

    Start at Map X 210, Y 30 and end at X 700, Y 300
    $gameScreen.setLine([{x:210,y:30},{x:700,y:300}], {pixel:true});
 
    pixel:
      true  = pixel coordinates
      false = map tiles

    With all options (optional):
    $gameScreen.setLine([{x:50,y:50},{x:500,y:500}], {
       pixel:true, zIndex:1, width:4, pulse:3, speed:120, color:0x00FF00, alpha:0.7});


   3) Besides connecting character to character, or Map coordinates,
      you could also connect events to map coordinates.

 Example:
    $gameScreen.setLine([0, {x:8, y: 10}])    //=> player ↔ Map Coordinates
    $gameScreen.setLine([0, {x:8, y: 10}], {color: "#00FFFF"})


 Remove Lines between map coordinates:

 Example:
    $gameScreen.removeLineCoords({x:4, y:6})

    This removes all lines, connected to that map coordinate.


 Removing Lines between connections is relative easy as well.

 Example:
    This require an start point and end point (can be used reversed)

    $gameScreen.removeLinesBetween(disconnect)

    Sample for characters:
    $gameScreen.removeLinesBetween([3,5])
    $gameScreen.removeLinesBetween([5,3]) => same effect as above

    Sample for map coordinates:
    $gameScreen.removeLinesBetween([{x:3,y:5},{x:10,y:20}])
    $gameScreen.removeLinesBetween([{x:10,y:20},{x:3,y:5}])  => same effect as above

    Sample for character and map coordinates:
    $gameScreen.removeLinesBetween([6,{x:10,y:20}])
    $gameScreen.removeLinesBetween([{x:10,y:20},6])  => same effect as above

    If Multple was connected to the same point, remove one line between them.

 
 Removing a Line from one source can break all others.

 Example:
    You have a connect A to B, A to C, A to D, D to E
 
    $gameScreen.removeLine(source)

    Removes ALL lines connected to the source.
    Remaining nodes stay connected to each other.

    Sample:

    $gameScreen.removeLine(2);   

    This removes all lines connected to event 2


 To remove all lines, use the following line:

    $gameScreen.removeAllLines();
 

 Pixel Distance
 ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞ ͞
 Check the console log for the pixel distance and use
 the following scriptcall:

 Example:
   $gameScreen.lineInPixels(sourceA, sourceB, pixels)

 souceA / sourceB: check the distance between map coords or characters.
                   (player, followers, events)
 pixels (optional): default is false, and only works for map coordinates
                   when using pixels.

 
 To check the map coordinates (tiles) distance in pixels:
   $gameScreen.lineInPixels({x:1, y:4}, {x:5, y:6})

 To check the map coordinates in pixels:
   $gameScreen.lineInPixels({x:32, y:128}, {x:64, y:192}, true)

 To check the characters distance in pixels (player, followers, events):
   $gameScreen.lineInPixels(3, 12)


 In order to use it in a conditional branch to check if its true or false
 if map coordinates (tiles) to event id 12 is lower than 96 pixels distance.

   $gameScreen.lineInPixels({x:1, y:4}, 12) < 96


 Or if you use map coords in pixels:

   $gameScreen.lineInPixels({x:32, y:128}, 12, true) < 96


 Use the console log first to see the actual pixel distance.
 This makes creating pixel-based conditions easier and more accurate.

zIndex and pulse
aboveredLine.gif
BelowRedLine.gif


=== TERMS OF USE ===
Free for Non-Commercial and Commercial use when credit is given.
credit one of the following:
ShadowDragon
ShadowDragonJB


=== WARNING ===
YOU ARE NOT ALLOWED TO:
* MODIFY without permission
* EXTEND without permission
* TAKE CODE without permission
* CLAIM AS YOU MADE IT
* REDISTRIBUTE but link back to the forum or itch.io
* SELL this product as standalone.
* DO NOT REMOVE THE HEADER.


Download from itch.io (require my base plugin (SDJB_Base or SDJB_BaseMZ (minified version))
tenor-86507499.gif
So, this could have the potential to be used as a laser bouncing puzzle in a dungeon?
So, this could have the potential to be used as a laser bouncing puzzle in a dungeon?
not exactly yet, but will add a feature for to drawLineTo to draw a line in x frames.

while its directly drawn, you can make it like that.

other available idea's:

skill tree, (require my SDJB_MouseControlEx plugin (former name SDJB_MouseHover)
this way, you can drag the map around if its a huge skill tree (like diablo path of exile.)

other ways, map transfer, to draw line, which is accessable,

mirror like beams, but if the other feature is added, this is very doable, and much cooler.

fishing mini game, to follow the fish, reel in.

there are many ways, but if you have suggestions, please leave them behind 🙂
NOTE: There is an issue on scrolling map that the lines between doesn't work.
while the points are there, it doesn't stay fixed.

This issue has been fixed, but adding a new feature before release,
so if you use a scroll map and the points move, wait for the next release =)

The new feature is something that many may like ^^

EDIT:
New version is up and updated with fix and feature.
This makes me think of some puzzles. It would be great if we could track the distance between the source and the target in pixels or something like that. If the distance is shorter or longer than a number, something will happen.
This makes me think of some puzzles. It would be great if we could track the distance between the source and the target in pixels or something like that. If the distance is shorter or longer than a number, something will happen.
it would require some rework, but I can see what can be done, if the reason is good.
it can draw event to event, or coordinates, so if using coordinated or tiles, I can see
for the distance for point A to B, in a new function.

I can see what I can do on that as it may be helpful.
@JamesRyan I managed to get the distance between source A and B
in pixels.

I adjust tomorrow the helpfile and update the plugin for release.
I only did some small testing, so check if it works like you wanted by than.
Updated the plugin to check distance between sourceA and sourceB
in pixels, so you can use it inside the conditional branch to make it
true or false.

I don't have specific ways for usage at this point, request by @JamesRyan.
I hope it didn't broke anything in MZ, as it should work.

if there are any suggestions, (or feedback), let me know.
first post is also updated with the helpfile.
Updated the plugin to check distance between sourceA and sourceB
in pixels, so you can use it inside the conditional branch to make it
true or false.

I don't have specific ways for usage at this point, request by @JamesRyan.
I hope it didn't broke anything in MZ, as it should work.

if there are any suggestions, (or feedback), let me know.
first post is also updated with the helpfile.
Thank you. I have been doing a puzzle where my MC is bound to something and cannot move further away than a certain distance from the source. I managed to make it with events, but there were no visuals to tell players when the tether was broken.
Fixed an typo in removing the line, as well moving the lines to character
instead of weather (this one get later 3 different layers to set to the
lower layer, upper character layer and upper layer, so it would be more flexible.

this also a new feature which is a surprise ^^
new update coming soon and has some changes.

removed => progress (handled differently)

added
=> zIndex to set the layer above or below other once (higher values has more priority.
=> mode: this can set modes which can extended in new future features.

mode: "progress"
this is how the new progress is set, options for progress can than be used as
starting point or mid way.

mode: "pulse"
this new mode uses width, and pulse method to pulse it. (see below)
zIndex is 0 befault, equal index depends where the line is drawn.
BelowRedLine.gif


zIndex is 1 on the white line, so it draws above them.
aboveredLine.gif


zIndex can make beams or lines more dynamically cross on different height,
in order it put it below them which can look bad.

I really want to see if I can add a glow effect, that fade out on the sides,
but not getting it to work yet.

the helpfile will be later updated on release when I get it to work or keep it like this.
but with the new way using "mode", I can add more cooler features to it.
like "wave".

not that I would add it directly, but its possible 🙂

leave suggestions/feedback behind.

stay tuned.
Plugin is updated on itch for download, in case of issues, please let me know.
any features, suggestion are also welcome.
This is a plugin I never knew I needed until now

Original thread: https://forums.rpgmakerweb.com/threads/sdjb_drawlinesbetween.182091/