This looks essentially correct with one exception.
You are wrapping player and rock positions.
Before rendering you must also wrap tempx, i.e. position of rock relative to player.
This is simpler with a function for wrapping:
Then the movement code is reduced to this:
You are wrapping player and rock positions.
Before rendering you must also wrap tempx, i.e. position of rock relative to player.
This is simpler with a function for wrapping:
Function wrap#( u# ) w2# = 2.0 * worldsize u = u Mod w2 If u < -worldsize Then Return u + w2 If u > +worldsize Then Return u - w2 Return u End Function
Then the movement code is reduced to this:
x = wrap( x + vx ) ; move player rx = wrap( rx + rvx ) ; move rock vx = vx * 0.99 ; friction TurnEntity ship, 0, -mxspd * 0.1, 0 PositionEntity rock, wrap( rx - x ), 0, 0