Hi guys :o) Could anyone help me out here please. For some reason my code isn't working properly. When the ball hits the bricks, it is deleting the wrong ones :o(
here's the code:
Thanks for any help, this is driving me mad :o)
here's the code:
Graphics 800,600 SetBuffer BackBuffer() Global SCREEN_WIDTH = 800 Global SCREEN_HEIGHT = 600 Global AREA_X = 150 ; the X origin for drawing the bricks Global AREA_Y = 30 ; the Y origin for drawing the bricks Global AREA_WIDTH = 10 ;width of game area (in bricks) Global AREA_HEIGHT = 5 ;height of game area (in bricks) Global BRICK_WIDTH = 50 Global BRICK_HEIGHT= 15 Global BALL_WIDTH = 10 Global BALL_HEIGHT = 10 Global ball_x = 10 Global ball_y = 10 Global ball_x_dir = 1 ; ball x direction(1 means forwards) Global ball_y_dir = 1 ; ball y direction(1 means down) Global ball_x_speed = 3 Global ball_y_speed = 3 Dim Bricks(AREA_WIDTH-1,AREA_HEIGHT-1) For y=0 To AREA_HEIGHT-1 For x=0 To AREA_WIDTH-1 Bricks(x,y)=1 Next Next ;Bricks(2,1)=0 While Not KeyHit(1) Cls update_ball() For y = 0 To AREA_HEIGHT-1 For x = 0 To AREA_WIDTH-1 If Bricks(x,y)=1 Then Color 255,Rand(0,135),55 Rect AREA_X+x*BRICK_WIDTH,AREA_Y+y*BRICK_HEIGHT,BRICK_WIDTH,BRICK_HEIGHT,1 Color 255,255,255 Rect AREA_X+x*BRICK_WIDTH,AREA_Y+y*BRICK_HEIGHT,BRICK_WIDTH,BRICK_HEIGHT,0 EndIf Next Next Rect ball_x,ball_y,BALL_WIDTH,BALL_HEIGHT,1 Text 0,0,"BALL X:"+ball_x+" BALL:Y"+ball_y Flip Wend End Function update_ball() If ball_x_dir = 1 Then ball_x = ball_x+ball_x_speed If ball_x_dir = 0 Then ball_x = ball_x-ball_x_speed If ball_y_dir = 1 Then ball_y = ball_y+ball_y_speed If ball_y_dir = 0 Then ball_y = ball_y-ball_y_speed If ball_x>(SCREEN_WIDTH-BALL_WIDTH) Then ball_x_dir = 1-ball_x_dir If ball_x<0 Then ball_x_dir = 1-ball_x_dir If ball_y>(SCREEN_HEIGHT-BALL_HEIGHT) Then ball_y_dir = 1-ball_y_dir If ball_y<0 Then ball_y_dir = 1-ball_y_dir For y = 0 To AREA_HEIGHT-1 For x = 0 To AREA_WIDTH-1 If Bricks(x,y)<>0 If ball_y_dir=0 And ball_y<AREA_Y+y*BRICK_HEIGHT+BRICK_HEIGHT Then ball_y_dir = 1-ball_y_dir:Bricks(x,y)=0 EndIf Next Next End Function
Thanks for any help, this is driving me mad :o)