Computer Science Canada

Breakout Game

Author:  smith_scott_04 [ Tue Dec 02, 2003 6:31 pm ]
Post subject:  Breakout Game

This is Version 0.02, there is no continous loop but the basics are there. There is going to be specila powerups, levels, lives and that sort of thing but for now i need feedback.

Author:  smith_scott_04 [ Tue Dec 02, 2003 6:38 pm ]
Post subject: 

OOPS here is the Code

code:


%Designed By Mike Petrov and Scott Smith

View.Set ("offscreenonly")

var boxesbroken : int := 0
var boxcolor : int := 30
var mx, my, button : int %Mouse
var x, y, colo : int %Paddle
var blx, bly, speed : real %Ball
var ball : boolean := false
var borderx1, bordery1, borderx2, bordery2 : int
var bangle : real := 75
speed := 3
var works : boolean := true
var xbound, ybound : int
xbound := 10
ybound := 6
var box : array 1 .. xbound, 1 .. ybound of boolean

for i : 1 .. xbound
    for j : 1 .. ybound
        box (i, j) := true
    end for
end for

borderx1 := 3
bordery1 := 5
borderx2 := maxx - 2
bordery2 := maxy - 5

colorback (black)
cls %Clears the screen making it black

x := (maxx div 2) - 50
y := 10
colo := 0

blx := (maxx div 2) - 50
bly := 20

%-------------------------PROCEDURES START-------------------------------

procedure DrawBoxes ()
    for i : 1 .. xbound
        for j : 1 .. ybound
            if box (i, j) = true then
                drawfillbox (borderx1 + i * 4 + i * 59, bordery2 - j * 4 - j * 15, borderx1 +
                    i * 4 + (i - 1) * 59, bordery2 - j * 4 - (j - 1) * 15, boxcolor)
            end if
        end for
    end for
end DrawBoxes

%------------------------------------------------------------------------

procedure FindBox (fbX, fbY : int)
    for i : 1 .. xbound
        for j : 1 .. ybound
            if fbX <= borderx1 + i * 4 + i * 59 and fbX >= borderx1 + i * 4 + (i - 1)
                    * 59 and fbY >= bordery2 - j * 4 - j * 15 and fbY <= bordery2 - j * 4 - (j - 1)
                    * 15 then
                boxesbroken := boxesbroken + 1
                if boxesbroken = xbound * ybound then
                    works := false
                    put "You Won"
                end if
                box (i, j) := false
            end if
        end for
    end for
end FindBox

%------------------------------------------------------------------------

procedure calculatexy (var x, y : real, angle, step : real)
    x := step * cosd (angle) + x
    y := step * sind (angle) + y
end calculatexy

%------------------------------------------------------------------------

procedure CollisionDetect (cdX, cdY : real, var cdAngle : real)

    if cdX <= borderx1 + 4 and cdAngle <= 180 then %Left Border + down
        cdAngle := 90 - (cdAngle - 90)
    elsif cdX <= borderx1 + 4 and cdAngle >= 180 then %Left Border + up
        cdAngle := 270 + (270 - cdAngle)
    elsif cdX <= x + 25 and cdX >= x - 25 and cdY <= 20 then
        cdAngle := 360 - cdAngle
    elsif cdY <= bordery1 + 4 then %Down Border
        color (0)
        put "YOU LOSE!" ..
        works := false
    elsif cdY >= bordery2 - 4 then %Up Border
        cdAngle := 360 - cdAngle
    elsif cdX >= borderx2 - 4 and cdAngle <= 180 then
        cdAngle := 90 - (cdAngle - 90)

    elsif cdX >= borderx2 - 4 and cdAngle >= 180 then
        cdAngle := 270 + (270 - cdAngle)
    end if

    if whatdotcolor (round (cdX), round (cdY + 3)) = boxcolor then
        if cdAngle < 180 then
            cdAngle := 360 - cdAngle
        else

        end if
        FindBox (round (cdX), round (cdY + 3))
    end if
end CollisionDetect

%------------------------------------------------------------------------

procedure drawborders ()
    drawbox (borderx1, bordery1, borderx2, bordery2, white)
    drawbox (borderx1 - 1, bordery1 - 1, borderx2 + 1, bordery2 + 1, white)
end drawborders
%------------------------------------------------------------------------

%------------------------------------------------------------------------

Draw.FillBox (x, y, (x + 50), (y + 10), colo)         % Paddle
Draw.FillOval ((round (blx) + 25), (round (bly) + 19), 8, 8, colo)         %Ball

loop

    Mouse.Where (mx, my, button)

    cls

    DrawBoxes ()

    drawborders ()
    if mx >= (borderx1 + 25) and mx <= (borderx2 - 25) then
        x := mx
        if ball = false then
            blx := mx
        end if
    elsif x >= (borderx1 + 25) and mx < (borderx1 + 25) then
        x := borderx1 + 25
        if ball = false then
            blx := x
        end if
    elsif x <= (borderx2 - 25) and mx > (borderx2 - 25) then
        x := borderx2 - 25
        if ball = false then
            blx := x
        end if
    end if

    if ball = false then
        if button = 1 then
            ball := true
            calculatexy (blx, bly, bangle, speed)
        end if
    else
        if button = 1 then
            speed := speed + 0.05
        end if
        calculatexy (blx, bly, bangle, speed)
        CollisionDetect (blx, bly, bangle)
    end if

    Draw.FillBox ((x - 25), y, (x + 25), (y + 10), colo)         %Paddle
    Draw.FillOval (round (blx), round (bly) + 4, 4, 4, colo)         % Ball

    View.Update

    exit when works = false
    delay (10)
end loop


Author:  Tony [ Tue Dec 02, 2003 7:05 pm ]
Post subject: 

you got to make it so that if the ball hits on the side of the paddle, it bounces off at another angle. Because this way (assuming user always doesnt let the ball fall through) every game will be identical. Heck, some levels might not even be possible if the ball's path will never reach certain block.

Author:  smith_scott_04 [ Tue Dec 02, 2003 8:56 pm ]
Post subject: 

I know its only it the starting stages im goin to put in a fromula so that you are able to hit it at different angles.

Author:  Homer_simpson [ Tue Dec 02, 2003 11:23 pm ]
Post subject: 

there's no need for a formula man... use vectors... besically this is how it is:

x+=cosd(angle)
y+=sind(angle)

Author:  smith_scott_04 [ Tue Dec 02, 2003 11:43 pm ]
Post subject: 

thanks Homer seemed to work ok

Author:  Homer_simpson [ Wed Dec 03, 2003 12:37 am ]
Post subject: 

np... but if u had any extra help with vectors just ask me or i think some1 here had a complete vector class for turing...

Author:  smith_scott_04 [ Wed Dec 03, 2003 10:54 pm ]
Post subject: 

thanks Homer , but i think i will be alright.

Author:  FDisk87 [ Fri Dec 05, 2003 9:04 pm ]
Post subject: 

Looks alright, however minor this suggestion may be is the game needs more colour Smile

Author:  smith_scott_04 [ Sat Dec 06, 2003 11:51 pm ]
Post subject: 

im trying to make it look like the original game.

Author:  Maverick [ Fri Dec 19, 2003 12:08 pm ]
Post subject: 

very good game. Only problem is the angles.

+ 5BITS

Author:  Triple Five [ Fri Dec 19, 2003 12:20 pm ]
Post subject: 

good game Very Happy almost like the original

Author:  DanShadow [ Wed Dec 24, 2003 4:10 pm ]
Post subject: 

Pretty neat, but it could be done much easier. L ike with 'whatdotcolor' or something. Also, you should probably make the speed like 10.

Author:  LeadHead [ Fri Sep 19, 2008 8:39 am ]
Post subject:  Re: Breakout Game

I've noticed that sometimes when the ball hits my paddle it disolves into it and then rolls off and i lose.
but other than that quite enjoyable. Canada

Author:  S_Grimm [ Fri Sep 19, 2008 10:08 am ]
Post subject:  RE:Breakout Game

please don't post in forums that are 5 years old.

Author:  CodeMonkey2000 [ Fri Sep 19, 2008 5:08 pm ]
Post subject:  Re: Breakout Game

Hmm. This thread is locked


: