GMS 2.3+ How to Program This Type of Movement? (Example Included)


Any number of ways. It helps that you are limited to 4 degrees of movement so the logic is fairly simple. In how I'd approach it, you'd really only need to track two systems:

1. Track each point where the direction changed (and keep these tracked positions in order of time, so a stack structure or something would be ideal)
2. Track the 'head' position in relation to the last 'changed' position.

Then just loop through positions connecting them together to make the body as well as the last 'change' with the head.

You keep track of #2 because when the head gets close enough to the last position you delete it from the stack to allow the 'backtracking'. Could probably be easily implemented in maybe a dozen lines of code.


You could track each piece of pipe, or track each area of the map. Tracking map status would be the way to go if you made the pipe and map all tiles, with the pipe head being an instance.

Tracking each piece of pipe would require the smallest data set and would likely be ideal for you.

You shouldn't need a loop per se. If the pipe speed is negative (retracting), move the head in its reverse direction until it gets to the old grid position, then pop the pipe piece at the end of the stack or queue. Ideally, draw the pipe pieces once as needed, not every step, but it shouldn't be a big deal if the map is small enough.
Last edited: