I have done the sprite collision on my game and on the Y collision
it works fine but on the X collision it sometimes goes past the
collision a few pixels and if your up against the a X wall you can't
go up or down.Works fine on the Y collision though.
-Try attachment.
-Here's the code.
set display mode 640,480,32
sync on:sync rate 999
load bitmap "map.bmp",1
get image 100,0,0,2999,1999
delete bitmap 1
load bitmap "collisionmap.bmp",1
get image 101,0,0,1187,867
delete bitmap 1
load bitmap "chocobo.bmp",1
for x=0 to 7
get image x+1,50*x,0,50+50*x,49
next x
delete bitmap 1
dot 0,0
dot 0,1
dot 1,0
dot 1,1
get image 102,0,0,1,1:cls
image=1
dim done(4)
DO
sprite 2,x-2421,y-540,101
sprite 3,-1690,240,102: rem -1710
paste image 100,x-1250,y-1000
sprite 1,290,200,image
if sprite collision(2,3)=0
oldx=x
oldy=y
endif
gosub movement
sprite 2,x-2421,y-540,101
sprite 3,-1690,240,102: rem -1710
paste image 100,x-1250,y-1000
sprite 1,290,200,image
print x
if sprite collision(2,3)=1
x=oldx
y=oldy
endif
sync:cls
LOOP
END
movement:
rk=rightkey()
lk=leftkey()
uk=upkey()
dk=downkey()
`1=up|2=right|3=down|4=left
olddirection=direction
if Uk=0 and Rk=0 and Dk=0 and Lk=0 then direction=0
if Uk=1 and Rk=0 and Dk=0 and Lk=0 then done(1)=0
if Rk=1 and Uk=0 and Dk=0 and Lk=0 then done(2)=0
if Dk=1 and Rk=0 and Uk=0 and Lk=0 then done(3)=0
if Lk=1 and Dk=0 and Rk=0 and Uk=0 then done(4)=0
if Uk=0 and done(1)=1 then done(1)=0
if Rk=0 and done(2)=1 then done(2)=0
if Dk=0 and done(3)=1 then done(3)=0
if Lk=0 and done(4)=1 then done(4)=0
if Uk=1 and done(1)=0 then direction=1:done(1)=1
if Rk=1 and done(2)=0 then direction=2:done(2)=1
if Dk=1 and done(3)=0 then direction=3:done(3)=1
if Lk=1 and done(4)=0 then direction=4:done(4)=1
if direction=1
inc ima
y=y+1
if direction<>olddirection and olddirection>0 then image=1
if ima=>3
image=image+1
if image=9 then image=1
ima=0
endif
goto done
endif
if direction=2
inc ima
x=x-1
if direction<>olddirection and olddirection>0 then image=1:rem 9
if ima=>3
image=image+1
if image=9 then image=1
ima=0
endif
goto done
endif
if direction=3
inc ima
y=y-1
if direction<>olddirection and olddirection>0 then image=1:rem 17
if ima=>3
image=image+1
if image=9 then image=1
ima=0
endif
goto done
endif
if direction=4
inc ima
x=x+1
if direction<>olddirection and olddirection>0 then image=1:rem 25
if ima=>3
image=image+1
if image=9 then image=1
ima=0
endif
goto done
endif
done:
return
[img]null[/img]
If at first you don't succeed-Pause-Go to last checkpoint