0

I'm currently programming my first game in JavaScript, and I've never technically learned JavaScript, I'm more fluent with Python.

Anyway, I need to find a way to make a list of all the pixels between two points on a straight horizontal line. I would then use the list to reference whether the user's character is touching any of the pixels to trigger a screen change.

It would be something like

pixels = []
(Function here to add the pixels to the list)
    For pixel in pixels
         If (dist(object.x, object.y, pixel.x, 0) < 1) {
            object.x = start point on new screen
            Object.y = 

Does this make any sense? I'm sorry I'm bad at explaining things but I could use the help.

clemens
  • 16,716
  • 11
  • 50
  • 65

1 Answers1

0

You almost certainly don't want to test intersection this way. This is going to require many more steps than just doing standard line-rectangle collision detection.

I recommend googling something like "line rectangle intersection" or "line rectangle collision detection" for a ton of results, including:

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107