Help with ON SPRITE GOSUB issue

By mariocavalcanti

Resident (63)

mariocavalcanti's picture

06-07-2018, 13:19

Hello, my friends. Please take a look at the code below. When the sprites collide, the value of the L variable decreases more than once, as if the Sprite Off instruction was not being executed immediately. Is there a way around this? Thank you.

Code link on MSXPen: https://msxpen.com/codes/-LGjI0hthNJnUhPCmEHx

10 SCREEN 1,1:L=10:LOCATE5,5:?"LIVES: ";L
20 SPRITE$(0)=CHR$(&H3C)+CHR$(&H7E)+CHR$(&H81)+CHR$(&H81)+CHR$(&HFF)+CHR$(&H7E)+CHR$(&H24)+CHR$(&H42)
30 ON SPRITE GOSUB 100
40 SPRITE ON
50 FOR X=0 TO 255 STEP 1
60 PUT SPRITE 0,(X,100),15,0
70 PUT SPRITE 1,(255-X,100),10,0
80 NEXT X
90 RUN
100 SPRITE OFF
110 X=0:BEEP:L=L-1:LOCATE12,5:?L
120 SPRITE ON
130 RETURN
Login or register to post comments

By ARTRAG

Enlighted (6173)

ARTRAG's picture

06-07-2018, 14:54

You need to remove the colliding sprites before sprite on at line 120
Better before beep so that you are sure that vblank has occurred already
This is causing the multiple calls

By mariocavalcanti

Resident (63)

mariocavalcanti's picture

06-07-2018, 15:49

BINGO! It worked like a charm. Thank you, my friend! Big smile