OK, whinges out of the way first...
Please check the stickies at the top of the forum. These tell you how to post without getting whinged at - eg: Please state the version of DB you are using!
As Sixty Squares says, use code boxes - highlighting it and then clicking on the code button does the same thing as manually typing tags in.
The main thing this will do is maintain any indentation your code has. Don't use them and your indentation disappears.
So, if you
don't already, indent your code. For me, length-wise your snippet was right at the limit of what I will bother looking at when not indented.
Experienced programmers indent their code and often won't even bother looking at non-indented code. You need to keep them on side.
With the code boxes and indentation, your code snippet looks like this:
CLS
SYNC ON
SYNC RATE 35
HIDE MOUSE
` Hit will be a boolean value = true if collision has occured
hit AS INTEGER = 0
`Set background color
INK 0, RGB(0,0,0)
`Load picture
LOAD IMAGE "ball.bmp",1
LOAD IMAGE "brick.bmp",2
`Where to put the sprites
x = 100
y = 100
SPRITE 1,X,Y,1
`First brick
x1 = 0
y1 = 0
SPRITE 2,X1,Y1,2
`Second Brick
x2 = 0
y2 = 405
SPRITE 3,x2,y2,2
`Third brick
x3 = 540
y3 = 0
SPRITE 4,x3,y3,2
`Fourth brick
x4 = 540
y4 = 405
SPRITE 5,x4,y4,2
SPRITE 1, x, y, 1
CLS
REPEAT
`Controls
IF (RIGHTKEY())
x = x + 10
ENDIF
IF (LEFTKEY())
x = x - 10
ENDIF
IF (UPKEY())
y = y - 10
ENDIF
IF (DOWNKEY())
y = y + 10
ENDIF
`Top left brick deletes after ball hits
IF (SPRITE COLLISION(1, 2) > 0)
DELETE SPRITE 2
INK RGB(255, 0, 0),0
TEXT 310, 0, "Good Job"
SYNC
hit = 1
x = 320
y = 240
ENDIF
`Bottom left brick deletes after ball hits
IF (SPRITE COLLISION(1, 3) > 0)
DELETE SPRITE 3
INK RGB(255, 0, 0,),0
TEXT 320, 0, "Good Job"
SYNC
hit = 1
x = 320
y = 240
ENDIF
`Top right brick deletes after ball hits
IF (SPRITE COLLISION(1, 4) > 0)
DELETE SPRITE 4
INK RGB(255, 0, 0),0
TEXT 310,0, "Good Job"
SYNC
hit = 1
x = 320
y = 240
ENDIF
`Bottom right brick deletes after ball hits
IF (SPRITE COLLISION(1, 5) > 0)
DELETE SPRITE 5
INK RGB(255, 0, 0),0
TEXT 310, 0, "Good Job"
SYNC
hit = 1
x = 320
y = 240
ENDIF
SPRITE 1, x, y, 1
SYNC
CLS
IF (hit = 1)
Wait 3000
hit = 0
endif
UNTIL (ESCAPEKEY())
end
OK, that said, your program is very linear and when it grows will quickly become unmanageable. You need to structure your programs at a very early stage to make them modular. This makes them much easier to add to and maintain.
You need to put your code into procedures and/or functions and call them from a main loop. This will also prevent you having some of the problems you are currently experiencing
An example general purpose skeleton layout can be found in my Program Layout tutorial (link in the stickies).
As for your issues (in no particular order):
1.
IF (RIGHTKEY())
x = x + 10
ENDIF
is better as:
IF RIGHTKEY() Then Inc x,10
though admittedly the result is exactly the same!
2. In a 3D game, the background colour blue is the default Backdrop colour. Use the
Color Backdrop 0 command to change it to black. In 2D
CLS 0 clears the screen to black. INK 0, RGB(0,0,0) as you have used sets the TEXT background colour - not the screen.
3. Under normal circumstances, you should only have one Sync in your program - inside the main program loop at the end. You shouldn't need a Sync after a text command, but if you do require one, then you often have to put the Sync before the Text command.
4. You have 4 sprite collision blocks checking for collision between sprite 1 and 2, 3, 4 and 5. These 40 or so lines could be replaced with:
SPCol = SPRITE COLLISION(1, 0)
If SPCol > 1
DELETE SPRITE SPCol
INK RGB(255, 0, 0),0
TEXT 310,0, "Good Job"
hit = 1: x = 320: y = 240
Endif
I know many of these things come with coding experience, so I hope you don't mind me pointing them out now.
TDK_Man