How you code the movement of objects vary on what you want the object to do. In the first snippet I have annotated and indented your code to explain what’s going on.
The second snippet hopefully will illustrate better methods of coding something like this.
` sync not needed here. I think you meant to call sync on.
`sync
` sync rate would appear to have an affect even though sync is not on.
sync rate 30
make object cube 1, 20
position object 1, 0, -20, 0
position camera 0, 0, -200
for y = -20 to 40
position object 1, x, y, z
` since the wait delay time is less the sync rate, wait is basically just updating the display.
`wait 2
` a call to sync will do the same.
sync
next y
` colon not used on call to subroutine.
gosub moveright
`this whole do loop is not necessary.
remstart
do
sync
loop
remend
` halt until keypress
wait key
`end used here to prevent fall through to subroutine.
end
moveright:
for x = 0 to 40
position object 1, x, y, z
`wait 2
sync
next x
return
type t_Player
time as integer
speed as integer
xPos as float
yPos as float
zPos as float
endtype
` make user define type global if you what to change the subroutine moveright: to a function.
` unless you dimension the udt as an array.
`global Player as t_Player
Player as t_Player
Player.speed = 30
Player.xPos = 0.0
Player.yPos = -75.0
Player.zPos = 0.0
sync on
sync rate 0
autocam off
position camera 0.0, 0.0, -200.0
make object cube 1, 20.0
Player.time = timer()
do
set cursor 0, 0
print "FPS: "; screen fps()
position object 1, Player.xPos, Player.yPos, Player.zPos
sync
if timer()>Player.time+Player.speed
Player.time = timer()
gosub moveright
endif
loop
end
moveright:
if (Player.yPos<75.0)
inc Player.yPos
else
if (Player.xPos<100.0)
inc Player.xPos
endif
endif
return