• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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

Binsk

Member
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.
 

TheouAegis

Member
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:
Top