The
for loop is within the
do loop, and without a flag. So, this causes the program to continually make bricks using the
for loop, without anything to stop it.
So setup your code with a brick function, which is called only when you wish it to be called. Or place the
for loop above the
do statement.
Function:
function bricklayer(rowcnt,columnstart,blockwidth,block,blocky,blockimg,blockscalex,blockscaley)
column=columnstart
for row1 = 1 to rowcnt
inc column,blockwidth
sprite block, column, blocky, blockimg
size sprite block, blockscalex, blockscaley
next column
endfunction
Now place this function below your main program loop(your
do loop. Then call it when necessary, passing it the variables needed. This function itself will allow for very dynamic block creation.
EX:
REM ... your setup code before this (object creations, vars, arrays, etc)
`place background(this only needs to be called once before the loop)
position object 1, 0, 100, -600
REM I'm emulating your for loop here which you called before the brick laying for loop
inc block,4
REMSTART this can be called whenever you need it to, but it seems you only need to
call it once before you loop. If you place it within your loop it will
be called over and over and over...you get my flow. Check the function
declaration below the do loop to find out the perimeter specifics
REMEND
bricklayer(7,1,blockwidth,block,19,2,45,22.5)
REM -------------------
REM ---- MAIN LOOP ----
REM -------------------
do
set cursor 100, 440
print "xvalue: ";ballx; " yvalue: ";bally;
sprite 1, ballx, bally, 1
`get ball moving
ballx = ballx - ballspeedx
bally = bally + ballspeedy
`if the ball hits the wall it changes direction
if ballx < 26 then ballspeedx = -ballspeedx
if ballx > 392 then ballspeedx = -ballspeedx
if bally < 18 then ballspeedy = -ballspeedy
if bally > 444 then ballspeedy = -ballspeedy
sync
loop
REM place the function at end of loop so that it is not "ran into to" during gameplay which will cause the program to crash
function bricklayer(rowcnt,columnstart,blockwidth,block,blocky,blockimg,blockscalex,blockscaley)
column=columnstart
for row1 = 1 to rowcnt
inc column,blockwidth
sprite block, column, blocky, blockimg
size sprite block, blockscalex, blockscaley
next column
endfunction
I hope this helps. I don't know your knowledge of functions, so ask if you don't understand. For now, try to understand that placing the block making for loop within you do loop was causing the blocks to be made every single frame of the game.