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

Username:   Password: 
 RegisterRegister   
 bouncing ball
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shoobyman




PostPosted: Thu Dec 15, 2005 9:42 pm   Post subject: bouncing ball

This code is driving me crazy cuz i can only give it the borders on the x axis, not y (even though my program looks like i tried to make a y border). can some1 plz tell me how to change it so the y border will actually work without changing everything? this is the code

code:

var x : int := 2
var y : int := 2

loop
    if x <= 2 then
        loop
            exit when x >= 630 or y >= 390
            delay (30)
            cls
            drawfilloval (x, y, 10, 10, 7)
            x := x + 10
            y := y + 2
        end loop
    end if
    if x >= 630 then
        loop
            exit when x <= 2 or y <= 2 or y >= 630
            delay (30)
            cls
            drawfilloval (x, y, 10, 10, 7)
            x := x - 10
            y := y - 2
        end loop
    end if
end loop



Mod edit: Code tags please, no triple posting, and no caps lock. Thanks.
Sponsor
Sponsor
Sponsor
sponsor
Bored




PostPosted: Thu Dec 15, 2005 9:47 pm   Post subject: (No subject)

The problem with your program is really simple your changeing both the y and x directions when your ball hits the end of the x part of the screen. Try using a single loop and a variable to store xSpeed and ySpeed. When the ball hits its max or minimum x value have the xSpeed become - xSpeed therfore going the other way (bouncing). Do the same for your y
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  [ 2 Posts ]
Jump to:   


Style:  
Search: