Hey guys, I hate to bring up 2D collision, as it is mentioned pretty much everywhere, but I have a problem with all of the other examples I have found online so far. In my game, I am trying to detect when my character is hitting any other sprite (such as the side of a building, a tree, etc.). I have managed to get the detection down (despite my code being primitive to say the least), but I can't figure out how to tell the sprite that, "That house is above you, you are touching the bottom of it with your head, therefore you can go left, right, down, but not up until you stop touching that house." Any help is MUCH appreciated. Thank you in advance to anybody who can.
Here's my code:
mainloop:
Hide Mouse
sync on
sync rate 60
gosub vars
gosub loadimages
do
DRAW SPRITES LAST
gosub playercheck
gosub sprites
gosub playerother
gosub playermovement
print x, ", ", y, ",", ks, ",", sprite collision(1,0)
sync
cls
loop
vars:
x=screen width()/2
y=screen height()/2
imgnum=0
air=5
ks=0
return
playermovement:
IF keystate(32)=1
imgnum=1
for i=0 to 2
Sprite 1, x, y, imgnum
IF Sprite collision(1,0)=0
x=x+6
goto endright1
ENDIF
IF ks=32
goto endright2
ELSE
x=x+6
ENDIF
endright1:
endright2:
Sprite 1, x, y, imgnum
sync
sleep 50
imgnum=imgnum+1
delete sprite 1
cls
next
sprite 1, x, y, 2
sync
imgnum=2
ks=32
return
endif
IF keystate(30)=1
imgnum=10
for i=0 to 2
Sprite 1, x, y, imgnum
IF Sprite collision(1,0)=0
x=x-6
goto endleft1
ENDIF
IF ks=30
goto endleft2
ELSE
x=x-6
ENDIF
endleft1:
endleft2:
Sprite 1, x, y, imgnum
sync
sleep 50
imgnum=imgnum+1
delete sprite 1
cls
next
sprite 1, x, y, 11
sync
imgnum=11
ks=30
return
endif
IF keystate(17)=1
imgnum=4
for i=0 to 2
Sprite 1, x, y, imgnum
IF Sprite collision(1,0)=0
y=y-6
goto endup1
ENDIF
IF ks=17
goto endup2
ELSE
y=y-6
ENDIF
endup1:
endup2:
Sprite 1, x, y, imgnum
sync
sleep 50
imgnum=imgnum+1
delete sprite 1
cls
next
Sprite 1, x, y, 5
sync
imgnum=5
ks=17
return
endif
IF keystate(31)=1
imgnum=7
for i=0 to 2
Sprite 1, x, y, imgnum
IF Sprite collision(1,0)=0
y=y+6
goto enddown1
ENDIF
IF ks=31
goto enddown2
ELSE
y=y+6
ENDIF
enddown1:
enddown2:
Sprite 1, x, y, imgnum
sync
sleep 50
imgnum=imgnum+1
delete sprite 1
cls
next
sprite 1, x, y, 8
sync
imgnum=8
ks=31
return
endif
playerother:
IF Spacekey()=1
cls
for i=0 to 10
y=y-air
sprite 1, x, y, imgnum
sync
air=air-1
sleep 25
delete sprite 1
cls
next
air=5
sprite 1, x, y, imgnum
return
endif
return
playercheck:
IF NOT Sprite Exist(1)
imgnum=8
Sprite 1, x, y, imgnum
sync
return
endif
return
sprites:
gosub fchouse1
return
fchouse1:
sprite 3, 100, 100, 14
set sprite 3, 0, 1
scale sprite 3, 200
set sprite priority 3, -99
return
-Live to code-