All pastes #191844 Raw Edit

Something

public text v1 · immutable
·published 2006-10-05 12:42 UTC
rendered paste body
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 point: int :=0
var life :int :=0

% Ball direction after it hits paddle
% Change ball Speed
% Levels ??
% balls left
% Paddle size
% Score...box count
%  Obsticles  (Difficult)

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 (1)
    mousewhere (mx, my, mb)
    drawfillbox (mx - size, 0, mx + size, 50, black)  % draws the paddle
    drawfillbox (mx - size - 1, 0, 0, 50, white)       % erases where the paddle used to be
    drawfillbox (maxx, 0, mx + size + 1, 50, white) % erases where the paddle used to be
    drawfilloval (ballx, bally, 15, 15, white)     % 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"
        put point
        life+=1
        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 <= 66 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 .. 10   % top of ball
        if whatdotcolour (ballx - 15 + i, bally + 16) = red then
            collidex := ballx div 100
            collidey := (bally + 16 + diry) div 100
            collidex := collidex * 100
            collidey := collidey * 100
            drawfillbox (collidex, collidey, collidex + 50, collidey + 30, white)
            diry := - (diry) %top
            point+=1
            exit
        end if
        if whatdotcolour (ballx - 15 + i, bally - 16) = red then
            collidex := ballx div 100
            collidey := (bally - 16 + diry) div 100
            collidex := collidex * 100
            collidey := collidey * 100
            drawfillbox (collidex, collidey, collidex + 50, collidey + 30, white)
            diry := - (diry) % bottom
           point+=1
             exit
        end if
        if whatdotcolour (ballx + 16, bally - 15 + i) = red then
            collidex := (ballx + 16 + dirx) div 100
            collidey := bally div 100
            collidex := collidex * 100
            collidey := collidey * 100
            drawfillbox (collidex, collidey, collidex + 50, collidey + 30, white)
            dirx := - (dirx)
            point+=1
            exit
        end if
        if whatdotcolour (ballx - 16, bally - 15 + i) = red then
            collidex := (ballx - 16 - dirx) div 100
            collidey := bally div 100
            collidex := collidex * 100
            collidey := collidey * 100
            drawfillbox (collidex, collidey, collidex + 50, collidey + 30, white)
            dirx := - (dirx) % left
            point+=1
            exit
        end if
    end for
    exit when life =3
    put
    View.Update
end loop