Jump to content
IGNORED

Filling up a Playfield Randomly


Primordial Ooze

Recommended Posts

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 by 2600 Hero
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

  • 4 years later...

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.

Link to comment
Share on other sites

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 by bogax
Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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