Jump to content
Sign in to follow this  
jbaudrand

joyfire with sound

Recommended Posts

I'm trying to add sound in a little game,

 

if joy0fire then missile0y=player0y-2:missile0x=player0x+4:AUDV0=8:AUDC0=4
 p=p+1
 if p=10 then AUDC0=0

 

:/ I though the counter will be in frame, but it's too long, it plays during 3-4 seconds, so I wonder what is my mistake.

 

any idea?

Share this post


Link to post
Share on other sites

Try adding a ":P=0" to the end of your if statement.

 

Without it "p" will be some value from 0-255 when the fire button is pressed.

Edited by RevEng

Share this post


Link to post
Share on other sites

Try adding a ":P=0" to the end of your if statement.

 

Without it "p" will be some value from 0-255 when the fire button is pressed.

 

Thanks, it's working better but I'm still trying to understand how it works: because when I set if p=2 then AUDC0=0, the sound stay as long as the missile is on screen, very strange

test sound.bas

Share this post


Link to post
Share on other sites

The problem in a nutshell, is that if missile0y<=240 then you're always skipping the bit of code that increments your sound timer and turns off the sound when it reaches 2.

 

If you move that bit of code above your missile0y check, so it's executed each frame, then everything works out...

 

*** EXISTING CODE

 if missile0y>240 then goto skip
 missile0y = missile0y-2:goto drawlooping
 
skip
 if joy0fire then missile0y=player0y-2:missile0x=player0x+4:AUDV0=4:AUDC0=3:p=0
 p=p+1
 if p=2 then AUDC0=0

drawlooping

*** NEW CODE

 p=p+1
 if p=2 then AUDC0=0

 if missile0y>240 then goto skip
 missile0y = missile0y-2:goto drawlooping
 
skip
 if joy0fire then missile0y=player0y-2:missile0x=player0x+4:AUDV0=4:AUDC0=3:p=0

Share this post


Link to post
Share on other sites

The problem in a nutshell, is that if missile0y<=240 then you're always skipping the bit of code that increments your sound timer and turns off the sound when it reaches 2.

 

If you move that bit of code above your missile0y check, so it's executed each frame, then everything works out...

 

*** EXISTING CODE

 if missile0y>240 then goto skip
 missile0y = missile0y-2:goto drawlooping
 
skip
 if joy0fire then missile0y=player0y-2:missile0x=player0x+4:AUDV0=4:AUDC0=3:p=0
 p=p+1
 if p=2 then AUDC0=0

drawlooping

*** NEW CODE

 p=p+1
 if p=2 then AUDC0=0

 if missile0y>240 then goto skip
 missile0y = missile0y-2:goto drawlooping
 
skip
 if joy0fire then missile0y=player0y-2:missile0x=player0x+4:AUDV0=4:AUDC0=3:p=0

 

ooh thanks, the logic in programming is merciless..

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...