+Random Terrain Posted June 1, 2013 Share Posted June 1, 2013 I really don't understand counters either. Take a look at this 27 second video where kids are playing Don't Spill the Beans and watch what happens about 16 seconds into it: www.youtube.com/watch?v=yx-cewdfTpo http://www.youtube.com/watch?v=yx-cewdfTpo A normal bB variable is similar to the pot in Don't Spill the Beans and numbers can be thought of as beans. The pot can hold up to 255 beans. If you try to add more than 255 beans, the pot will tip over and you'll be left with zero beans in the pot. If you try to subtract when there are zero beans in the pot, 255 beans will magically hop back up into the pot. A counter isn't special, it's just a regular old variable. Counters are only called counters because they are used for counting. You probably already know that the drawscreen command must run 60 times a second for NTSC programs, so if you wanted something to happen once a second, you'd want your counter to stop every time it contains 60 beans. Here's an example using the variable c as a counter: c = c + 1 : rem * A bean is tossed into the pot. if c = 60 then c = 0 : rem * You dump the beans out of the pot, then do whatever it is you wanted to do here. The example above will keep doing whatever it is you want to do every second (60 = one second). If you wanted something to happen every 2 seconds, you'd change 60 to 120. Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 1, 2013 Author Share Posted June 1, 2013 (edited) That was one of the best explanations I ever heard. I understand completely! You rock Random Terrain! Let's see. To get the effect of a pixel appearing every second. Then I would set it up like this? c = c + 1 if c = 60 then c = 0 : pfpixel temp5 temp6 on temp5 = (rand&31) : temp6 = (rand&7) + (rand/64) pfpixel temp5 temp6 off Edited June 1, 2013 by Rabbit 2600 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted June 1, 2013 Share Posted June 1, 2013 That was one of the best explanations I ever heard. I understand completely! You rock Random Terrain! Let's see. To get the effect of a pixel appearing every second. Then I would set it up like this? c = c + 1 if c = 60 then c = 0 then pfpixel temp5 temp6 on temp5 = (rand&31) : temp6 = (rand&7) + (rand/64) Almost. You have an extra then. You could do this: c = c + 1 if c = 60 then c = 0 : temp5 = (rand&31) : temp6 = (rand&7) + (rand/64) : pfpixel temp5 temp6 on Or if you are afraid the line is getting too long, you can do this trick: c = c + 1 if c < 60 then goto __Skip_60_Count c = 0 temp5 = (rand&31) : temp6 = (rand&7) + (rand/64) pfpixel temp5 temp6 on __Skip_60_Count That last one lets you use a lot of code on as many lines as you want without using gosub. I learned that from batari. Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 1, 2013 Author Share Posted June 1, 2013 Cool that I almost had it^^ Thank you once again. Now I got it to work perfectly! Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 1, 2013 Author Share Posted June 1, 2013 (edited) Hm, having some trouble with player0 and pfpixel collision again The player dosn't get any score when touching the pixels. p = 0 if p then if collision(player0, playfield) then p = 0: score = score+10 Edited June 1, 2013 by Rabbit 2600 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted June 1, 2013 Share Posted June 1, 2013 Hm, having some trouble with player0 and pfpixel collision again The player dosn't get any score when touching the pixels. p = 0 if p then if collision(player0, playfield) then p = 0: score = score+10 If you use "p = 0" right before an if-then that requires p to be greater than zero, guess what will happen? That's right. You guessed it. Nothing will happen. Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 1, 2013 Author Share Posted June 1, 2013 Ah! What a silly misstake! It's obviously suppose to be p = 1! Thank you once again =) Quote Link to comment Share on other sites More sharing options...
bogax Posted June 1, 2013 Share Posted June 1, 2013 That last one lets you use a lot of code on as many lines as you want without using gosub. I learned that from batari. I'll add that I've been using gosubs for things you might not normally use a gosub for, just to get player defintions and the like out of the way, to make it easier to see what the code is doing. you'd (probably) normally use a gosub where you want to reuse a piece of code but don't want to take up space with another copy of the code. but gosubs use extra time and code/memory compared to say, a goto especially if you're jumping around in diferent banks. Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 1, 2013 Author Share Posted June 1, 2013 (edited) Ahh, neat! Now score is working as it should. Trying to get the pixel that player0 touches to get destroyed but it's not going well. Is a goto function that bypasses this code the right thing to do? if c = 60 then c = 0 : temp5 = (rand&31) : temp6 = (rand&7) + (rand/64) : pfpixel temp5 temp6 on Edited June 1, 2013 by Rabbit 2600 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted June 1, 2013 Share Posted June 1, 2013 Ahh, neat! Now score is working as it should. Trying to get the pixel that player0 touches to get destroyed but it's not going well. Is a goto function that bypasses this code the right thing to do? if c = 60 then c = 0 : temp5 = (rand&31) : temp6 = (rand&7) + (rand/64) : pfpixel temp5 temp6 on If you want to destroy a playfield pixel that a sprite touches, you have to convert the sprite coordinates to playfield coordinates, but if your sprite is larger than a playfield pixel, it can be hard to tell where that playfield pixel actually is. It's not something that beginners would normally be able to do without someone just doing it for them. Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 1, 2013 Author Share Posted June 1, 2013 (edited) Mm'kay. I'm sure I'll figure it out eventually. I have two great examples to work by, both have the features I need. I just need to find a way to combine them. It's quite interesting trying to figure out what makes things work in what way.: if c = 60 then c = 0 : goto skippixel temp5 = (rand&31) : temp6 = (rand&7) + (rand/64) pfpixel temp5 temp6 on skippixel And p = 0 if p then if collision(player0, playfield) then p = 0 if joy0right then player0x = player0x + 1 if joy0left then player0x = player0x - 1 if joy0up then player0y = player0y - 1 if joy0down then player0y = player0y + 1 if p then Skip_Pixel pfpixel s t off s = (rand&31) : t = rand/2 : t = ((t/2 + t)/4 + t)/16 pfpixel s t on if joy0fire then p = 1 Skip_Pixel Edited June 1, 2013 by Rabbit 2600 Quote Link to comment Share on other sites More sharing options...
bogax Posted June 1, 2013 Share Posted June 1, 2013 (edited) here's some code that will show you sprite and pfpixel positions fire switches between them sprite_v_pf.bas Edited June 1, 2013 by bogax Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 1, 2013 Author Share Posted June 1, 2013 Mama Mia, that's alot of code. I'll dive into it =) Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 1, 2013 Author Share Posted June 1, 2013 Is there any way to do collision with pixels without converting player0's position into pixel position? Quote Link to comment Share on other sites More sharing options...
bogax Posted June 1, 2013 Share Posted June 1, 2013 (edited) Mama Mia, that's alot of code. I'll dive into it =) You can if you want If you have questions, ask It's really just to show pfpixel positions versus player positions. The reason I said the player-playfield collision code is probably not what you want is because in it there's only one pfpixel it can be and it doesn't care which direction you're going. That simplifies things greatly But I expect most of the time you'd need to figure out which of several/many pfpixels your player is colliding with you have to do that by position. And it could be that this corner of the player is colliding with that pfpixel and that corner of the player is colliding with this pfpixel. hmm maybe I should rig it to show when an actual collision is detected. It's only when an actual player pixel overlaps a playfield pixel that you get a collision. I used a box for the player so if it overlaps at all you'd get a collision but if the player was say a single pixel you could have player pixels that you defined as off overlapping pfpixels without a collision and that complicates figuring by position which is colliding with what. Edited June 1, 2013 by bogax Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 1, 2013 Author Share Posted June 1, 2013 (edited) I can't do it. I can't convert player0 positin to pixel position =/ Edited June 2, 2013 by Rabbit 2600 Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 2, 2013 Author Share Posted June 2, 2013 (edited) Okay, I came up with a solution that works! I'm having problems with a screen. When the player has cleaned up 5 spots a screen showing "CLEAN!" should appear. But the games moves to that screen directly from the title instead of the playfield screen. What am I doing wrong? rem Generated 2013-05-31 20:37:14 by Visual bB Version 1.0.0.554 rem ********************************** rem * * rem * * rem * * rem * * rem * * rem ********************************** set kernel_options player1colors playercolors pfcolors set smartbranching on dim rand16 = z dim Master_Counter = a dim timer = b dim _P1_L_R = player1x.a dim _P1_U_D = player1y.b dim _P0_L_R = player0x.a dim _P0_U_D = player0y.b dim _player0a = a dim _player0b = b scorecolor = $20 player0x = 50 player0y = 50 p = 1 player1x = 70 player1y = 70 ballx = rand&127 bally = rand&63 ballheight = 4 c = 0 player0color: $F4; $F4; $0E; $0E; $0E; $0E; $2E; $2E; $2E; $2E; $2E; $06; $06; $06; $0E; $0E; end player1color: $A2; $A2; $A2; $A2; $A2; $20; $20; $20; $20; $20; $2E; $2E; $2E; $2E; $0E; $0E; end playfield: .....X.X..XX..X..X.XXX.XXXX..... .....X.X.X..X.X..X.X...X........ .....XXX.X..X.X..X.XXX.XXXX..... .....X.X.X..X.X..X...X.X........ .....X.X..XX...XX..XXX.XXXX..... ................................ .X..X.XXXX.XXXX.XX..X.X..X.XXXX. .X.X..X....X....X.X.X.XX.X.X.... .XX...XXXX.XXXX.XX..X.X.XX.X.XX. .X.X..X....X....X...X.X..X.X..X. .X..X.XXXX.XXXX.X...X.X..X.XXXX. end title pfcolors: $2E $2C $2C $2A $2A $28 $28 $26 $26 $24 $24 $24 end drawscreen if joy0fire || joy1fire then goto skiptitle goto title screen1 skiptitle playfield: X.............XXXXX............X X.............X...X............X XXXXXXXXXXXXXXX...XXXXXXXXXXXXXX X..............................X X..............................X X..............................X X..............................X X..............................X X..............................X X..............................X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end main f=f+1 : if f = 20 then f = 0 if f = 0 then gosub f0 if f = 10 then gosub f1 rem POSSIBLY INEFFICIENT CODE, SEPARATE COLOR INFO FOR EACH FRAME... if joy0right then r = 0 if joy0left then r = 8 REFP0 = r pfcolors: $2E $2C $2C $2A $2A $28 $28 $26 $26 $24 $24 $24 end drawscreen if joy0right then player0x = player0x + 1 if joy0left then player0x = player0x - 1 if joy0up then player0y = player0y - 1 if joy0down then player0y = player0y + 1 if _P1_U_D < _P0_U_D then _P1_U_D = _P1_U_D + 0.30 if _P1_U_D > _P0_U_D then _P1_U_D = _P1_U_D - 0.30 if _P1_L_R < _P0_L_R then _P1_L_R = _P1_L_R + 0.30 if _P1_L_R > _P0_L_R then _P1_L_R = _P1_L_R - 0.30 if p = 1 then if collision(player0, ball) then p = 0: score = score+10: p = 1:bally=rand&63:ballx=rand&127: c = c + 1 if c = 5 then goto clean playfield: ................................ ................................ ................................ .....XXX.X...XXX..X..X..X.X..... .....X...X...X...X.X.XX.X.X..... .....X...X...XXX.XXX.X.XX.X..... .....X...X...X...X.X.X..X....... .....XX..XXX.XXX.X.X.X..X.X..... ................................ ................................ ................................ end clean pfcolors: $2E $2C $2C $2A $2A $28 $28 $26 $26 $24 $24 $24 end drawscreen if joy0fire || joy1fire then goto skiptitle goto clean screen2 goto main f0 player0: %00100110 %00000110 %00110010 %00110010 %01100100 %00000100 %00111000 %01001000 %00100000 %01110000 %01010000 %01110000 %11000000 %11000000 %00000000 %00000000 end return f1 player0: %10010111 %01000001 %00110001 %00110001 %01100010 %00000010 %00011100 %00100100 %00010000 %00111000 %00101000 %00111000 %01100000 %01100000 %00000000 %00000000 end player1: %00000100 %01100100 %00100100 %00101000 %00111000 %00000000 %10111000 %10111000 %11111100 %00111010 %00000001 %00111001 %00101001 %00111000 %00000000 %00000000 end player1: %00101000 %00101000 %00101000 %00101000 %00111000 %01000000 %01011000 %01011000 %01111100 %00111010 %00000010 %00111010 %00101010 %00111000 %00000000 %00000000 end return Edited June 2, 2013 by Rabbit 2600 Quote Link to comment Share on other sites More sharing options...
bogax Posted June 2, 2013 Share Posted June 2, 2013 Okay, I came up with a solution that works! I'm having problems with a screen. When the player has cleaned up 5 spots a screen showing "CLEAN!" should appear. But the games moves to that screen directly from the title instead of the playfield screen. What am I doing wrong? You skip the clean ! playfield statement when c = 5 Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 2, 2013 Author Share Posted June 2, 2013 (edited) Cheers! Got it working =D And, I almost got the code working that makes you go back to the playfield after the "clean!" screen. Only thing is the player0 and ball is missing. How do I fix it? rem Generated 2013-05-31 20:37:14 by Visual bB Version 1.0.0.554 rem ********************************** rem * * rem * * rem * * rem * * rem * * rem ********************************** set kernel_options player1colors playercolors pfcolors set smartbranching on dim rand16 = z dim Master_Counter = a dim timer = b dim _P1_L_R = player1x.a dim _P1_U_D = player1y.b dim _P0_L_R = player0x.a dim _P0_U_D = player0y.b dim _player0a = a dim _player0b = b scorecolor = $20 player0x = 50 player0y = 50 p = 1 player1x = 70 player1y = 70 ballx = rand&127 bally = rand&63 ballheight = 4 c = 0 player0color: $F4; $F4; $0E; $0E; $0E; $0E; $2E; $2E; $2E; $2E; $2E; $06; $06; $06; $0E; $0E; end player1color: $A2; $A2; $A2; $A2; $A2; $20; $20; $20; $20; $20; $2E; $2E; $2E; $2E; $0E; $0E; end playfield: .....X.X..XX..X..X.XXX.XXXX..... .....X.X.X..X.X..X.X...X........ .....XXX.X..X.X..X.XXX.XXXX..... .....X.X.X..X.X..X...X.X........ .....X.X..XX...XX..XXX.XXXX..... ................................ .X..X.XXXX.XXXX.XX..X.X..X.XXXX. .X.X..X....X....X.X.X.XX.X.X.... .XX...XXXX.XXXX.XX..X.X.XX.X.XX. .X.X..X....X....X...X.X..X.X..X. .X..X.XXXX.XXXX.X...X.X..X.XXXX. end title pfcolors: $2E $2C $2C $2A $2A $28 $28 $26 $26 $24 $24 $24 end drawscreen if joy0fire || joy1fire then goto skiptitle goto title screen1 skiptitle playfield: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX...XXXXXXXXXXXXXX XXXXXXXXXXXXXXX...XXXXXXXXXXXXXX X..............................X X..............................X X..............................X X..............................X X..............................X X..............................X X..............................X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end main f=f+1 : if f = 20 then f = 0 if f = 0 then gosub f0 if f = 10 then gosub f1 rem POSSIBLY INEFFICIENT CODE, SEPARATE COLOR INFO FOR EACH FRAME... if joy0right then r = 0 if joy0left then r = 8 REFP0 = r pfcolors: $2E $2C $2C $2A $2A $28 $28 $26 $26 $24 $24 $24 end drawscreen if joy0right then player0x = player0x + 1 if joy0left then player0x = player0x - 1 if joy0up then player0y = player0y - 1 if joy0down then player0y = player0y + 1 if _P1_U_D < _P0_U_D then _P1_U_D = _P1_U_D + 0.30 if _P1_U_D > _P0_U_D then _P1_U_D = _P1_U_D - 0.30 if _P1_L_R < _P0_L_R then _P1_L_R = _P1_L_R + 0.30 if _P1_L_R > _P0_L_R then _P1_L_R = _P1_L_R - 0.30 if p = 1 then if collision(player0, ball) then p = 0: score = score+10: p = 1:bally=rand&63:ballx=rand&127: c = c + 1 if c = 5 then goto __Clean_Screen_Loop if collision(ball,playfield) then bally=rand&63:ballx=rand&127 goto main __Clean_Screen_Loop rem **************************************************************** rem * rem * Playfield colors. rem * rem ```````````````````````````````````````````````````````````````` rem ` COLUBK = 0 : COLUPF = $30 ballx = 255 : bally = 255 player0x = 255 : player0y = 255 player1x = 255 : player1y = 255 missile0x = 255 : missile0y = 255 missile1x = 255 : missile1y = 255 rem **************************************************************** rem * rem * Draws the screen. rem * rem ```````````````````````````````````````````````````````````````` rem ` playfield: ................................ ................................ ................................ .....XXX.X...XXX..X..X..X.X..... .....X...X...X...X.X.XX.X.X..... .....X...X...XXX.XXX.X.XX.X..... .....X...X...X...X.X.X..X....... .....XX..XXX.XXX.X.X.X..X.X..... ................................ ................................ ................................ end drawscreen if joy0fire || joy1fire then c = 0: goto title goto __Clean_Screen_Loop f0 player0: %00100110 %00000110 %00110010 %00110010 %01100100 %00000100 %00111000 %01001000 %00100000 %01110000 %01010000 %01110000 %11000000 %11000000 %00000000 %00000000 end return f1 player0: %10010111 %01000001 %00110001 %00110001 %01100010 %00000010 %00011100 %00100100 %00010000 %00111000 %00101000 %00111000 %01100000 %01100000 %00000000 %00000000 end player1: %00000100 %01100100 %00100100 %00101000 %00111000 %00000000 %10111000 %10111000 %11111100 %00111010 %00000001 %00111001 %00101001 %00111000 %00000000 %00000000 end player1: %00101000 %00101000 %00101000 %00101000 %00111000 %01000000 %01011000 %01011000 %01111100 %00111010 %00000010 %00111010 %00101010 %00111000 %00000000 %00000000 end return Edited June 2, 2013 by Rabbit 2600 Quote Link to comment Share on other sites More sharing options...
bogax Posted June 5, 2013 Share Posted June 5, 2013 hmm maybe I should rig it to show when an actual collision is detected. Heh, I don't suppose anybody cares but.. I added a collision indication. The player color changes. I added a few different player shapes which you can step through using left and right when the player is yellow. Step through the functions using fire. The functions are: move the playfield block, move the player, change the player shape. Scorecolor follows function. scr_positions.bas Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 5, 2013 Author Share Posted June 5, 2013 Nice! That'll come in handy for me =) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.