LoginLogin

I need help with BG collision

Root / Programming Questions / [.]

Im_Old_ManCreated:
How would I put in collision into my game? Here's the code:
ACLS
XON EXPAD
SPDEF 0,0,0,16,32,16,16,1
SPDEF 1,16,0,16,32,16,16,1
SPDEF 2,32,0,16,32,16,16,1
SPDEF 3,0,0,16,32,16,16,9
SPDEF 4,16,0,16,32,16,16,9
SPDEF 5,32,0,16,32,16,16,9
LOAD "GRP4:SP",0
LOAD "GRP0:BG",0
SPSET 0,0
SPSCALE 0,2,2
X=50
Y=160
@0
IF X<28 THEN X=28
IF X>405 THEN X=405
IF Y<118 THEN Y=118
VSYNC
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF BUTTON AND #B THEN GOSUB @JUMP
GOTO @0
@MR1
ANIM=ANIM+2
IF ANIM==10 THEN SPCHR 0,0
IF ANIM==20 THEN SPCHR 0,1
IF ANIM==30 THEN SPCHR 0,0
IF ANIM==40 THEN SPCHR 0,2
IF ANIM>40 THEN ANIM=0
OLD=629:LFT=FALSE
X=X+2
RETURN
@ML1
ANIM=ANIM+2
IF ANIM==10 THEN SPCHR 0,3
IF ANIM==20 THEN SPCHR 0,4
IF ANIM==30 THEN SPCHR 0,3
IF ANIM==40 THEN SPCHR 0,5
IF ANIM>40 THEN ANIM=0
OLD=629:LFT=FALSE
X=X-2
RETURN
@JUMP
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y-6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y-6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y-6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y-6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y-6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y-6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y-6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y+6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y+6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y+6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y+6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y+6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y+6
VSYNC 1.5
SPOFS 0,X,Y
IF BUTTON AND #RIGHT THEN GOSUB @MR1
IF BUTTON AND #LEFT THEN GOSUB @ML1
IF Y<118 THEN Y=118
Y=Y+6

RETURN

Here is a nice code if your player is moving around the screen:
while 1
 if bgget(layer,px variable+16,py variable,1)==background number then dec y
 if bgget(layer,px variable,py variable+16,1)==background number then dec x
 if bgget(layer,px variable+16,py+32 variable,1)==background number then inc y
 if bgget(layer,px variable+32,py variable+16,1)==background number then inc x
 wait
wend

Well for starters you can stop using label loops and labels and instead use while loops and functions

Well for starters you can stop using label loops and labels and instead use while loops and functions
B-u-r-n. I'm curious though. Your programs layout and style indicates a platformer. I don't think random_guys recommendation would work. It could be similar, but with a few modifications.