Log In  

Cart #pzmowin-0 | 2023-08-05 | Code ▽ | Embed ▽ | No License

Hello, I'm new to programming and have been struggling with a line intersection function. The goal of this cart is to draw lines one after another, the origin of one segment being the endpoint of another. This has led to several problems, as initially the intersect function was considering this shared point to count as an intersection. To remedy this, I separated the lines into three categories: #1, the line being currently drawn, #2, the previously drawn line, and #3, all the lines before it. The problem I've run into here is that it's only calculating an intersection with the first line of the last list (#3).

This WIP cart prints whether or not intersect is true, and then the number of segments in the lists for #2 and #3 respectively. Is there a way to loop through and detect intersection for all of this last list? Thank you for bearing with my wall of text, and for your time and assistance.

P#132766 2023-08-05 18:23 ( Edited 2023-08-05 18:27)

1

Pico-8's line function actually has a built-in way of doing this already. After drawing a line, any further line() calls with only 2 parameters will draw a line from the endpoint of the previous line to the point specified.

Here's a little example:

function _update()
 cls()
 line(8,8,48,32,11)
 line(24,64)
 line(80,64)
 line(120,120)
end
P#132797 2023-08-06 16:26

[Please log in to post a comment]