View.Set ("graphics:max,max")
View.Set ("offscreenonly")
var size : int := 50
var mx, my, mb : int
var collidex, collidey : int := 0
var ballx, bally : int := 200
var dirx, diry : int := 0
var ballSpeed : int := 4
var hit : string := "no"
var col : int
% Ball direction after it hits paddle
% Change ball Speed
% Levels ??
% balls left
% Score...box count
% Obsticles(Difficult)
loop
randint (col, 1, maxcol)
drawfillbox (maxx, 1, 1, maxy, col)
dirx := ballSpeed %dirx moves the ball left or right - ballspeed is the number of pixels it moves
diry := ballSpeed %diry moves the ball up or down - ballspeed is the number of pixels it moves
for x : 100 .. 800 by 100 % draws the bricks every 100 pixels
for y : 300 .. 600 by 100
drawfillbox (x, y, x + 50, y + 30, red) % the bricks are 50 pixels wide by 30 pixels high
end for
end for
loop
%delay (3)
mousewhere (mx, my, mb)
drawfillbox (mx - size, 0, mx + size, 15, black) % draws the paddle
drawfillbox (mx - size - 1, 0, 0, 15, col) % erases where the paddle used to be
drawfillbox (maxx, 0, mx + size + 1, 15, col) % erases where the paddle used to be
drawfilloval (ballx, bally, 15, 15, col) % erases where the ball used to be
ballx += dirx %current x location of the ball...the ball is being moved left or right depending on the value of dirx
bally += diry %current y location of the ball...the ball is being moved up or down depending on the value of diry
drawfilloval (ballx, bally, 15, 15, blue) % draws the ball
if ballx >= maxx then % right wall - ball will travel left after it gets to the edge of the screen
dirx := - (dirx)
elsif bally >= maxy then % top wall - ball will travel down after it gets to the edge of the screen
diry := - (diry)
elsif ballx <= 0 then % left wall- ball will travel right after it gets to the edge of the screen
dirx := - (dirx)
elsif bally <= 0 then % bottom of screen --Life is lost
diry := - (diry)
locate (1, 1)
put "lost ball"
ballx := 200 % resets starting location of ball
bally := 200
loop
mousewhere (mx, my, mb) % doesnt restart until mouse is clicked
exit when mb = 1
end loop
end if
%paddle collision - ball bounces up when it hits paddle
if ballx > mx - size and ballx < mx + size and bally <= 30 then
diry := - (diry)
end if
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following for loop checks to see if the ball touches any of the bricks. It checks all four %
% 'sides' of the circle. If the circle touches a brick the current x and y location of the ball %
% is divided by 100 then multiplied by 100 in order to draw a box over the brick hit. %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i : 1 .. 30 % top of ball
if whatdotcolour (ballx - 15 + i, bally + 16) = red then
collidex := (ballx - 15 + i) div 100
collidey := (bally + 16 + diry) div 100
collidex := collidex * 100
collidey := collidey * 100
drawfillbox (collidex, collidey, collidex + 50, collidey + 30, col)
diry := - (diry) %top
exit
end if
if whatdotcolour (ballx - 15 + i, bally - 16) = red then
collidex := (ballx - 15 + i) div 100
collidey := (bally - 16 - diry) div 100
collidex := collidex * 100
collidey := collidey * 100
drawfillbox (collidex, collidey, collidex + 50, collidey + 30, col)
diry := - (diry) % bottom
exit
end if
if whatdotcolour (ballx + 16, bally - 15 + i) = red then
collidex := (ballx + 16 + dirx) div 100
collidey := (bally - 15 + i) div 100
collidex := collidex * 100
collidey := collidey * 100
drawfillbox (collidex, collidey, collidex + 50, collidey + 30, col)
dirx := - (dirx)
exit
end if
if whatdotcolour (ballx - 16, bally - 15 + i) = red then
collidex := (ballx - 16 - dirx) div 100
collidey := (bally - 15 + i) div 100
collidex := collidex * 100
collidey := collidey * 100
drawfillbox (collidex, collidey, collidex + 50, collidey + 30, col)
dirx := - (dirx) % left
exit
end if
end for
View.Update
end loop
end loop