Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Ball Bounce off the Bottom Brick
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nikki




PostPosted: Mon Jan 21, 2008 5:16 pm   Post subject: Re: Final Projects

Could someone please help me i need to know how to make the ball in my program bounce off the bottom brick and hit the others at the top. The game is brick. After that i need to make the bricks up top disappear when the ball hits it. PLZ HELP ME ITS MY FINAL!

var x, y : int
var x1, y1 : int
var move : string (1)

const movement := 22
const dist := 5
var xx := 100
var yy := 15
x := 200
y := 0
x1 := 310
y1 := 20
var ballx, bally, xmod, ymod : int := 200
xmod := 1
ymod := 1
drawfillbox (10, 363, 70, 380, black)
drawfillbox (80, 363, 140, 380, black)
drawfillbox (150, 363, 210, 380, black)
drawfillbox (220, 363, 280, 380, black)
drawfillbox (290, 363, 350, 380, black)
drawfillbox (360, 363, 420, 380, black)
drawfillbox (430, 363, 490, 380, black)
drawfillbox (500, 363, 560, 380, black)
drawfillbox (570, 363, 630, 380, black)
drawfillbox (10, 333, 70, 350, black)
drawfillbox (80, 333, 140, 350, black)
drawfillbox (150, 333, 210, 350, black)
drawfillbox (220, 333, 280, 350, black)
drawfillbox (290, 333, 350, 350, black)
drawfillbox (360, 333, 420, 350, black)
drawfillbox (430, 333, 490, 350, black)
drawfillbox (500, 333, 560, 350, black)
drawfillbox (570, 333, 630, 350, black)
drawfillbox (10, 303, 70, 320, black)
drawfillbox (80, 303, 140, 320, black)
drawfillbox (150, 303, 210, 320, black)
drawfillbox (220, 303, 280, 320, black)
drawfillbox (290, 303, 350, 320, black)
drawfillbox (360, 303, 420, 320, black)
drawfillbox (430, 303, 490, 320, black)
drawfillbox (500, 303, 560, 320, black)
drawfillbox (570, 303, 630, 320, black)
drawfillbox (10, 273, 70, 290, black)
drawfillbox (80, 273, 140, 290, black)
drawfillbox (150, 273, 210, 290, black)
drawfillbox (220, 273, 280, 290, black)
drawfillbox (290, 273, 350, 290, black)
drawfillbox (360, 273, 420, 290, black)
drawfillbox (430, 273, 490, 290, black)
drawfillbox (500, 273, 560, 290, black)
drawfillbox (570, 273, 630, 290, black)
drawfillbox (10, 243, 70, 260, black)
drawfillbox (80, 243, 140, 260, black)
drawfillbox (150, 243, 210, 260, black)
drawfillbox (430, 243, 490, 260, black)
drawfillbox (500, 243, 560, 260, black)
drawfillbox (570, 243, 630, 260, black)


loop
if hasch then
getch (move); %Get Input
if move = chr (203) and x > 5 then
drawfillbox (x, y, x1, y1, 0)
x := x - 7
x1 := x1 - 7
elsif move = chr (205) and x < 520 then
drawfilloval (x, y, x1, y1, 0)
x := x + 7
x1 := x1 + 7
end if
end if
ballx += xmod
bally += ymod
if ballx + 10 >= maxx then
xmod := -1
elsif ballx - 10 <= 0 then
xmod := 1
end if
if bally + 10 >= maxy then
ymod := -1
elsif bally - 10 <= 0 then
ymod := 1
end if
drawfillbox (x, y, x1, y1, black)
drawfilloval (ballx, bally, 10, 10, 12)
delay (7)
drawfilloval (ballx, bally, 10, 10, 0)

end loop
Sponsor
Sponsor
Sponsor
sponsor
BigBear




PostPosted: Mon Jan 28, 2008 11:54 pm   Post subject: Re: Ball Bounce off the Bottom Brick

To make the ball bounce off the brick use the command whatdotcolor.
To check if the ball is on the color black then do the same thing for when the ball is at the edge of the screen.
MichaelM




PostPosted: Tue Jan 29, 2008 3:33 pm   Post subject: Re: Ball Bounce off the Bottom Brick

Yes, big bear is right, but you'd need to have the blocks a different colour than your bricks, otherwise you'll get other crazy bounces. If keep your
brick black, just add the following to your ifs, which checks the colour just below the ball:
code:

        if bally + 10 >= maxy then
            ymod := -1
        elsif bally - 10 <= 0 then
            ymod := 1
        elsif whatdotcolour(ballx,bally-11)=black then
            ymod:=1
        end if

However, this only checks below, you'll need to add a bit more for hits on the left and right of the brick.

Oh, and I couldn't help but notice that your big list of drawfillboxes could be shortened by about 50 lines using a pair of loops (at the cost of two more variables):

code:

var drawx : int := 10
var drawy : int := 363
for a : 1 .. 5
    for b : 1 .. 9
        drawfillbox (drawx, drawy, drawx + 60, drawy + 17, 40)
        drawx := drawx + 70
    end for
    drawx:=10
    drawy:=drawy-30
end for
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: