Jump to content
Sign in to follow this  
esplonky

Randomizing playfield blocks?

Recommended Posts

I need a way to randomize a scrolling playfield, but like a cave sort of scene, so as you move to the right, the playfield makes random ridges on the top and bottom of the screen and then a few blocks in the middle area. and i would like collision detection too

Edited by esplonky

Share this post


Link to post
Share on other sites

If it's just random screens look at my Destiny source here:

http://www.atariage....p/#entry2140266

 

I divide the playfield into three horizontal chunks. When I randomly select one chunk I push up the screen using pfmove commands then randomly select another chunk and repeat the process until all 3 sections have filled the screen.

 

The problem is, you want a scrolling game with random screens. In that case I'd just make and destroy random blocks in the corners that are about to move off screen. So, if you're moving left randomly make and destroy blocks to the far right.

Edited by theloon

Share this post


Link to post
Share on other sites

This is off the cuff, but, I think random playfield blocks can be placed with the pfpixel command.

 

Work that PFPIXEL command boy!

 

 

pfpixel xpos ypos function (bb-across-anim-01.gif | bb-vertical-anim-03.gif)

 

xpos can be 0-31 and ypos can be 0-11 (11 is hidden off of the screen and only seen if scrolled.) If you use Superchip RAM and pfres, you can have more than 11 rows.

 

function is any of on, off, or flip. On turns the block on, off turns it off, and flip turns it off if it was on or on if it was off.

 

Basically, if you needed to scramble the far left-hand side of the cave you'd do a few pfpixel commands:

 

pfpixel 0 (rand&3) flip

 

pfpixel 0 (rand&3) flip

 

pfpixel 0 (rand&3) flip

 

..and so on. The rand&3 part is to get a number between 0 and 3.

 

UPDATE: You'd want to update a small column of blocks to the left (when moving right) so I switched "(rand&3) 0" to "0 (rand&3)"

Edited by theloon

Share this post


Link to post
Share on other sites

Can i get a code snippet (With Comments explaining what it's doing)

Share this post


Link to post
Share on other sites

Can i get a code snippet (With Comments explaining what it's doing)

I'm not ignoring you dawg :) I'm behind on my own coding (my own fault). Hopefully someone will whip up or link to a good example.

Share this post


Link to post
Share on other sites

Yeah, That's how I've learned how to code in bB pretty much, is code snippets

Share this post


Link to post
Share on other sites
rem Compiler Options
set smartbranching on
set romsize 4k

rem These are basic settings for a simple game. smartbranching never hurts. We don't need multi-bank so 4k.

rem Declare variables
dim xpos = a
dim ypos = b

rem bB doesn't always work right with temp variables and doesn't like alot of caclulations on one line. We're gonna use up two variables for the playfield pixel position.

rem Startup code
init
COLUPF = $0E

rem Put code here that should always run before the main program begins. In this case I'm setting the playfield pixel color to white.

rem Main loop
main
xpos = rand&3
ypos = rand&3
pfpixel xpos ypos flip
drawscreen
goto main

rem Like I said, bB wont let us do pfpixel temp1 temp2 or lots of calculations like pfpixel 0 (rand&3) flip so we have to break it down.

Edited by theloon

Share this post


Link to post
Share on other sites

Can i get a code snippet (With Comments explaining what it's doing)

I'm not ignoring you dawg :) I'm behind on my own coding (my own fault). Hopefully someone will whip up or link to a good example.

esplonky,

here is a block of code I think you may enjoy :)

 

The routine draws several layers of random structures over one another to create a random cityscape.

 

v=5 rem overlay 5 drawings of random structures, try setting it to 1 to see the difference

for w=1 to v

q = rand: q= q / 8

rem q = 32 - q

if q < 5 then q = 5

if q >26 then q = 6

t= rand: t= t/8

u = rand: u= u/40 + t

rem can't get that last column... so don't set it

if u>29 then u=29

if t>29 then t=29

for m = t to u

for n = q to 31 rem goes to 31

pfpixel m n on

next

next

next

Share this post


Link to post
Share on other sites

@Mr SQL: I can't get your code to work right. Doesn't compile as is. Could to provide a yaddayadda.bas file instead?

 

UPDATE: Thank you Mr SQL :)

Edited by theloon

Share this post


Link to post
Share on other sites

@Mr SQL: I can't get your code to work right. Doesn't compile as is. Could to provide a yaddayadda.bas file instead?

loon,

sure the example is from CityScape, I've shared the source code here:

http://www.atariage.com/forums/topic/187460-cityscape-new-2600-game/

 

I have an idea why the block isn't compiling for you; try setting the option for a 31 pfpixel high screen (superchip) instead of 11 pfpixels:

set romsize 8kSC

const pfres=32

Share this post


Link to post
Share on other sites

@theloon is yours just supposed to be white blocks moving around up in the top left?

Share this post


Link to post
Share on other sites

@theloon is yours just supposed to be white blocks moving around up in the top left?

 

Ya man! rand&3 gives a random number between 0 and 3. I give the variables xpos (hortizontal playfield position) and ypos (vertical playfield position) a number between 0 and 3. I then use the pfpixel command with those xpos and ypos to place a playfield pixel. When I specifiy flip it reverses whatever piayfield pixel is at that location.

Edited by theloon

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