Primordial Ooze Posted January 22, 2009 Share Posted January 22, 2009 (edited) I would like to know if it is possible to "fill" a playfield up randomly. I am creating a remake of monstachase while i take a break on 2600 hero. to start Playfield: %XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %X........................................................X %X........................................................X %X........................................................X %X........................................................X %X........................................................X %X........................................................X %X........................................................X %X........................................................X %X........................................................X %X........................................................X %XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end then before the game is started: generateplayfield // left to right for temp1 = 2 to 29 // generate a random number between 0 and 1 rand = r // if rand is greater then 127, then turn the playfield pixel on if rand > 127 then pfpixel temp1 1 on:next // top to bottom for temp2 = 2 to 10 // generate a random number between 0 and 1 rand = r // if rand is greater then 127, then turn the playfield pixel on if rand > 127 then pfpixel 1 temp2 on:next Please let me know if this is correct. 2600 Hero Edited January 22, 2009 by 2600 Hero Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted January 22, 2009 Share Posted January 22, 2009 At a glance, the code looks okay to me. But in the playfield statement you need to take out the % at the beginning of each line. The % symbol is used to indicate a binary value, so you need to use it when defining the data for a player. But the data for the playfield doesn't use binary values, because there are 32 pixels instead of only 8 pixels-- plus, the playfield data is expressed using periods and Xs, whereas binary values are expressed using 0s and 1s. Michael Quote Link to comment Share on other sites More sharing options...
CurtisP Posted February 4, 2009 Share Posted February 4, 2009 Don't use the temp variables for loops as they sometimes get used in bB functions. The rand function, for example, overwrites the value in temp1. Quote Link to comment Share on other sites More sharing options...
Robert M Posted February 4, 2009 Share Posted February 4, 2009 I do not believe bBasic supports nested for-loops. To make nested loops you will have to build them yourself using if-then goto constructs. Also, you put your 'next' instructions inside the if-then statements, so the next is executed only if the condition is true. Moreover, trying to randomly plot the entire playfield in one overscan period is not possible, the screen will roll. I recommend you add a call to drawscreen at the end of the outer loop so that the screen is drawn as each row of random pixels is added. Quote Link to comment Share on other sites More sharing options...
MausGames Posted February 4, 2009 Share Posted February 4, 2009 To get as close as possible to one random row of playfield pixels per frame, it would be best to use the playfield variables. You could not do this with 32 pfpixel commands in one frame, that would use over 6400 cycles. Quote Link to comment Share on other sites More sharing options...
MausGames Posted February 4, 2009 Share Posted February 4, 2009 Here is an example of what it looks like to fill up the entire screen with random pixels by assigning the value of rand directly to the playfield variables, one row at a time. It uses the maximum possible horizontal resolution, so it would work much faster with a 32x12 playfield. randscreen.bin Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted May 30, 2013 Share Posted May 30, 2013 I tried pasting the code in my project, but I get a syntax error at this line: if rand > 127 then pfpixel 1 temp2 on:next Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted May 30, 2013 Share Posted May 30, 2013 I tried pasting the code in my project, but I get a syntax error at this line: if rand > 127 then pfpixel 1 temp2 on:next You might try putting the next on a separate line. Looking back at the original code in the first post, I'm not sure if the next statements should have been inside the ifs the way they were. Other than that suggestion, the pfpixel statement might not be available in all bB kernels-- for example, I don't think it works with the multisprite kernel. Quote Link to comment Share on other sites More sharing options...
bogax Posted May 30, 2013 Share Posted May 30, 2013 Don't use the temp variables for loops as they sometimes get used in bB functions. The rand function, for example, overwrites the value in temp1. unless its changed, rand doesn't use temp1 Quote Link to comment Share on other sites More sharing options...
bogax Posted May 30, 2013 Share Posted May 30, 2013 (edited) I do not believe bBasic supports nested for-loops. To make nested loops you will have to build them yourself using if-then goto constructs. You can nest for-next loops You only get one next per for and a next is associates with the next previous for that's not already paired with a next so for j = 1 to 10 for i = 1 to 10 goto skip next skip next is like for j = 1 to 10 for i = 1 to 10 goto skip next i skip next j (even if you put in the i and the j ) (like this) for j = 1 to 10 for i = 1 to 10 goto skip next j skip next i Edited May 30, 2013 by bogax Quote Link to comment Share on other sites More sharing options...
bogax Posted May 30, 2013 Share Posted May 30, 2013 Something like this? r_fill_pf.bas 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.