Jump to content
esplonky

Score + 1

Recommended Posts

is there any way to make my score go up by one when the fire button is pressed, as in joy0fire is pressed, score goes to 1, joy0fire is pressed again, score goes to 2, etc.

Share this post


Link to post
Share on other sites

it compiles and all, but didn't do squat.

 

Do you see the score? Is it increasing by one every time you press the fire button?

Share this post


Link to post
Share on other sites

You need to use a variable, or flag. I'm sure what RT posted is considerably better, but something like:

 

if joy0fire && a = 0 then a = 1

if a = 1 then score = score + 1 : a = 2

if !joy0fire && a <> 0 then a = 0

Edited by MausGames
  • Like 1

Share this post


Link to post
Share on other sites

RT, no, it just keeps going up up up as i hold down the fire button.

Share this post


Link to post
Share on other sites

RT, no, it just keeps going up up up as i hold down the fire button.

 

So when you run the .bin file I also uploaded, does it do the same thing? It works for me. You have to press and release the fire button for it to add one to the score.

Share this post


Link to post
Share on other sites

I know, it works with your .bin, and I put everything in my code exactly how it was in yours, i put the dim at the header, before all the other code, I put the other code in my main_loop and then the skip_fire i put right after my main_loop

Share this post


Link to post
Share on other sites

I know, it works with your .bin, and I put everything in my code exactly how it was in yours, i put the dim at the header, before all the other code, I put the other code in my main_loop and then the skip_fire i put right after my main_loop

 

Here's the code again:

 

  rem  ****************************************************************
  rem  *
  rem  *  Create aliases for variables.
  rem  *
  rem  ****************************************************************
  rem  '
  rem  '  (You can have more than one alias for each variable.)
  rem  '
  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '
  rem  '  BitOp variable for debouncing the fire button.
  rem  '
  dim _Bit0_Debounce_Fire = d




__Main_Loop
  rem  @# Main Loop
  rem  ****************************************************************
  rem  ****************************************************************
  rem  *
  rem  *
  rem  *  Main Loop
  rem  *
  rem  *
  rem  ****************************************************************
  rem  ****************************************************************


  rem  ****************************************************************
  rem  *
  rem  *  Score color.
  rem  *
  rem  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '
  scorecolor = $1A



  rem  ****************************************************************
  rem  *
  rem  *  Debounce fire button.
  rem  *
  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '
  rem  '  If fire button not pressed, clear debounce bit and skip.
  rem  '
  if !joy0fire then _Bit0_Debounce_Fire{0} = 0 : goto __Skip_Fire


  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  If fire button is pressed, but debounce bit is on, skip.
  rem  '
  if _Bit0_Debounce_Fire{0} then goto __Skip_Fire


  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  Turn on fire button debounce bit.
  rem  '
  _Bit0_Debounce_Fire{0} = 1


  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  Add one to score.
  rem  '
  score = score + 1

__Skip_Fire



  rem  ****************************************************************
  rem  *
  rem  *  Draw the screen.
  rem  *
  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '
  drawscreen



  goto __Main_Loop

 

 

This part needs to be inside of your main loop:

 

  rem  ****************************************************************
  rem  *
  rem  *  Debounce fire button.
  rem  *
  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '
  rem  '  If fire button not pressed, clear debounce bit and skip.
  rem  '
  if !joy0fire then _Bit0_Debounce_Fire{0} = 0 : goto __Skip_Fire


  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  If fire button is pressed, but debounce bit is on, skip.
  rem  '
  if _Bit0_Debounce_Fire{0} then goto __Skip_Fire


  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  Turn on fire button debounce bit.
  rem  '
  _Bit0_Debounce_Fire{0} = 1


  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  Add one to score.
  rem  '
  score = score + 1

__Skip_Fire

Share this post


Link to post
Share on other sites

that's what is in my main_loop. and I just solved it. I forgot to take out:

 

if joy0fire then score = score + 1

 

so now it works. thanks!

Share this post


Link to post
Share on other sites

This is why I hate bit flags. I know the squeeze is supposed to be part of the fun, but I'm too dim for dim, it ends up being too much.

Share this post


Link to post
Share on other sites

This is why I hate bit flags. I know the squeeze is supposed to be part of the fun, but I'm too dim for dim, it ends up being too much.

 

That's why I use:

 

_Bit0_Blah_Blah{0}

_Bit1_Blah_Blah{1}

_Bit2_Blah_Blah{2}

_Bit3_Blah_Blah{3}

_Bit4_Blah_Blah{4}

_Bit5_Blah_Blah{5}

_Bit6_Blah_Blah{6}

_Bit7_Blah_Blah{7}

 

The bit number at the beginning tells me what goes between the curly brackets. I never have to scroll back up and look what I put in a REM statement that describes it. What I need to know is right in front of me.

Share this post


Link to post
Share on other sites

bit ops confuse me to hell :?

 

Everything confused me all to hell at the beginning. I didn't even understand how you could play a sound effect while other things happened at the same time until it was explained to me.

 

I didn't know how to do an attract mode and a lot of other stuff until I got answers from better programmers in this forum.

 

Bits are easy if you think of them as 8 tiny variables inside of a normal variable. A lot of things can be done with these 'bit variables' instead of wasting an entire normal variable. As long as your aliases are descriptive, it's hard to mess up. Here's an example:

 

  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  BitOp variables.
  rem  '
  dim BitOp_01 = q

  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  Player is falling if on.
  rem  '
  dim Bit0_Fall_in_Progress = q

  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  Player moved to the left if on.
  rem  '
  dim Bit1_Slide_Left_in_Progress = q

  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  Player moved to the right if on.
  rem  '
  dim Bit2_Slide_Right_in_Progress = q

  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  Player can't hold down fire button to repeatedly jump.
  rem  '
  dim Bit3_Fire_Debounce = q

  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  Flips player sprite when necessary.
  rem  '
  dim Bit4_Flip_P1 = q

  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  Lets player slide when direction changes.
  rem  '
  dim Bit5_Ground_Slide_in_Progress = q

  rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  rem  '  Allows player to slide while ducking.
  rem  '
  dim Bit6_Duck_in_Progress = q

  • Like 1

Share this post


Link to post
Share on other sites

ah, so instead of only having 26 variables, I can have 208?

 

Yeah, I have this on the bB page:

 

http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#bit

Accessing the bits of a variable is almost like turning it into 8 separate variables. Instead of having only 26 variables, you potentially have 208. You just have to remember that these itty-bitty variables can only hold 0 or 1.

Share this post


Link to post
Share on other sites

oh, i read up on bit ops there, guess i didn't see that. :P

 

Maybe I should move it higher in that section or make a did you know box.

Share this post


Link to post
Share on other sites

Programmers sometimes use a single bit as a "boolean" value. You don't really need to know what "boolean" means besides that 0 is false and 1 is true. This saves alot of space because instead of 1 0-255 value now you have 8 true or false variables.

 

So instead of

 

a = 0-255

 

we have

 

a{0} = 0 or 1 (true or false)

a{1} = 0 or 1 (true or false)

a{2} = 0 or 1 (true or false)

a{3} = 0 or 1 (true or false)

a{4} = 0 or 1 (true or false)

a{5} = 0 or 1 (true or false)

a{6} = 0 or 1 (true or false)

a{7} = 0 or 1 (true or false)

 

There are many things in a game that are only true or false. If you use binary variables to represent 2 states (true or false) then you are using them as a boolean variable.

 

I just wanted to clarify what "bit ops" or "flags" are in this thread :)

Edited by theloon
  • Like 1

Share this post


Link to post
Share on other sites
I just wanted to clarify what "bit ops" or "flags" are in this thread :)

 

and that's probably the best way to tell me :)

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...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...