Hello fish,
While on the surface your supposition seems logical, you have to go back a few more lines in the example code to see what's going on:
if upkey()=1 then y=y-3
if downkey()=1 then y=y+3
if leftkey()=1 then x=x-3
if rightkey()=1 then x=x+3
The arrow keys are constantly updating the x and y position. The whole purpose of oldx and oldy is to keep the old value of x and y before they are updated by the arrow keys. When you approach the positioning of the sprite in the manner you suggest and use the command
SPRITE 1,oldx,oldy,1 you are basically just positioning the sprite at whatever value x or y has been updated to on the last loop repeat.
When the collision code is written as
rem Check for collision and block new position
if sprite collision(1,0)>0
x=oldx
y=oldy
sprite 1,x,y,1
endif
You are
resetting x and y to the old values, so the next pass through the repeat, oldx and oldy have effectively not been changed. Make sense?
Let me try explaining it a different way.
Let's say we repeat the loop 3 times. I'll write some pseudo code of what's happening to the variables:
pass 1
oldx=x
oldy=y
`since x=0 and y=0 at this point, oldx=0 and oldy=0
`let's increase x and y
x=x+3
y=y+3
`so now x=3 and y=3
when there's collision: x=oldx and y=oldy
`so now x=0 and y=0
position sprite at x,y (which is 0,0)
pass 2
oldx=x=0
oldy=y=0
x=x+3
y=y+3
'no collision so onto the next pass
pass 3
oldx=x=3
oldy=y=3
x=x+3=6
y=y+3=6
'collision
x=oldx=3
y=oldy=3
position sprite at 3,3
Now, if we use your logic and never set x=oldx and y=oldy, then those values would never be reset and oldx and oldy would just keep increasing (although they would be one loop behind x and y in value) thus enabling the sprite to continue to overlap the other sprite. The whole point of using oldx and oldy is to ensure that x and y get reset to their old values before they were ever updated by the arrow keys. If the sprites keep colliding, then x and y remain at the values of oldx and oldy.
Enjoy your day.