Basically, I can create a collision with 1 brick.
I can create many bricks to appear on screen.
However, I cannot do them both at the same time.
What am I doing wrong?
`set window on
`set window size 480, 640
sync on
sync rate 30
set display mode 800, 600, 32
set window on
set image colorkey 000, 000, 000
xvelocity as integer
yvelocity as integer
xposition as integer = screen width()/2
yposition as integer = 550
xbrick as integer
ybrick as integer
xball as float
yball as float
xball = screen width() /2
yball = screen height() /2
ballXVelocity as float = 12.5
ballYVelocity as float = 10.2
lives as integer = 3
#constant backgroundimage 100
#constant backgroundsprite 100
#constant paddleimage 200
#constant paddlesprite 200
#constant ballimage 300
#constant ballsprite 300
#constant brickimage 400
#constant bricksprite 400
#constant brickspritestart 400
spriteexist = 0
load image "Wolverineblades.png", paddleimage
load image "Milky_Sky_by_Orioto.jpg", 2
load image "Wolverinehead.png", ballimage
`load image "brick.png", bricksprite
load image "brick.png", brickimage
sprite paddlesprite, xPosition, yPosition, paddleimage
sprite ballsprite, xball, yball, ballimage
sprite bricksprite, xbrick, ybrick, brickimage
sprite bricksprite, 0, 0, brickimage
hide sprite bricksprite
REM Create columns of bricks
numCols as integer
numCols = 4
REM Create rows of bricks
numRows as integer
numRows = 4
brickNum = numCols*numRows
dim brick(brickNum) as BrickType
type BrickType
brickAlive as integer
imageNumber as integer
spriteNumber as integer
x as integer
y as integer
width as integer
height as integer
endtype
xStart as integer
xStart = screen width()/10
yStart as integer
yStart = screen height()/8
brickWidth as integer
brickWidth = sprite width (bricksprite)
xSpace as integer
xSpace = brickWidth + xStart
brickHeight as integer
brickHeight = sprite height (bricksprite)
ySpace as integer
ySpace = brickHeight + yStart
x as integer
x = xStart
y as integer
y = yStart
do
cls
hide mouse
IF MOUSECLICK() = 1 THEN playerclickstart = 1
`mouse input
M = MOUSEMOVEX()
if M <> 0
xPosition = xPosition + M
Endif
REM Begin Array for placing multiple Bricks
brick = 0
brickSpriteNum = brickspritestart
for c = 0 to numCols-1
for r = 0 to numRows-1
brick(brick).brickAlive = 1
brick(brick).imageNumber = brickimage
brick(brick).spriteNumber = brickSpriteNum
brick(brick).x = c *xSpace + xStart
brick(brick).y = r * ySpace + yStart
brick(brick).width = sprite width(bricksprite)
brick(brick).height = sprite height(bricksprite)
inc brick
inc brickSpriteNum
next r
next c
for i = 0 to brickNum-1
if brick(i).brickAlive > 0
sprite brick(i).spriteNumber, brick(i).x, brick(i).y, brick(i).imageNumber
endif
next i
`colision of paddle to wall
if xPosition < 0
xPosition = 0
endif
if xPosition > screen width() - sprite width(paddlesprite)
xPosition = screen width() - sprite width(paddlesprite)
endif
`GAME LOGIC
`sides
if sprite x(ballSprite) + sprite width (ballSprite) > screen width()
ballXVelocity = -ballXVelocity
endif
if sprite x(ballSprite) < 0
ballXVelocity = -ballXVelocity
endif
`death scenario
if sprite y(ballSprite) + sprite height (ballSprite) > screen height() - 25
dec lives
yPosition = 550
xball = screen width() /2
yball = screen height() /2
ballXVelocity as float = 6.2
ballYVelocity as float = 8.0
playerclickstart = 0
wait 1000
endif
`top border collision
if sprite y(ballSprite) < 0
ballYVelocity = -ballYVelocity
endif
`collision with paddle
if sprite x(ballSprite) <= sprite x(paddlesprite) + sprite width(paddlesprite) && sprite x(ballSprite) + sprite width(ballSprite) >= sprite x(paddlesprite)
if sprite y(ballSprite) + sprite height(ballSprite) >= sprite y(paddlesprite)
if ballYVelocity > 0
ballYVelocity = -ballYVelocity
endif
endif
endif
REM Initialise Game Start
if playerclickstart = 1
inc xball, ballXVelocity
inc yball, ballYVelocity
endif
REM draw Paddle and Ball
sprite ballsprite, xball, yball, ballimage
sprite paddlesprite, xPosition, yPosition, paddleimage
`sprite bricksprite, 400, 400, brickimage
paste image 2, 0, 0
REM Player Lives
INK RGB(0,255,128), 0
text 10, 10, "Lives: " + STR$(lives)
sync
if sprite x(bricksprite) + sprite width(bricksprite) => sprite y(ballsprite) + sprite height(ballsprite) <= sprite y(bricksprite) + sprite height(bricksprite)
if sprite y(bricksprite) + sprite height(bricksprite) <= sprite y(ballsprite) + sprite height(ballsprite)
if ballYVelocity < 0
if sprite hit (bricksprite, ballsprite)
ballYVelocity = -ballYVelocity
inc score, 10
spriteexist = 1
`boxes(i).bdead = "dead"
`play sound 14
endif
endif
endif
endif
REM Remove Sprite outside of screen
if sprite hit(300, 400) = 1
spriteexist = 1
ballyvelocity = -ballyvelocity
ballXVelocity = -ballXVelocity
offset sprite 400, -400, -400
endif
loop