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

Username:   Password: 
 RegisterRegister   
 Can't get a ball to bounce off four sides
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
GabeC99




PostPosted: Thu Jan 15, 2015 9:11 am   Post subject: Can't get a ball to bounce off four sides

so basically I need a ball to bounce off four walls in my program and i can make it bounce off one but I cant get it to do it for the other 3.
If i try to edit a new code to make it bounce off the second wall it just edits my code for the first wall bounce. Please help!

code:

setscreen ("graphics: 200, 500")

var centerX, centerY : int

centerX := 30
centerY := 100


loop
    drawoval (centerX, centerY, 25, 25, 1)
    drawfill (centerX, centerY, 7, 1)

    delay (10)
    cls


    if centerX < 200 - 25 then
        centerX := centerX + 1
        centerY := centerY + 1
    end if

    if centerX = 200 - 25 then
        loop
            centerX := centerX - 1
            centerY := centerY + 1
            drawoval (centerX, centerY, 25, 25, 1)
            drawfill (centerX, centerY, 7, 1)

            delay (10)
            cls
        end loop
    end if

    if centerX = 30 - 400 then
    centerX := centerX + 1
    centerY := centerY + 1
    drawoval (centerX, centerY, 25, 25, 1)
            drawfill (centerX, centerY, 7, 1)
           
            delay (50)
        end if    cls
end loop
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Jan 15, 2015 2:04 pm   Post subject: RE:Can\'t get a ball to bounce off four sides

From your code
code:

    if centerX = 200 - 25 then
        loop
            centerX := centerX - 1
            centerY := centerY + 1
            drawoval (centerX, centerY, 25, 25, 1)
            drawfill (centerX, centerY, 7, 1)

            delay (10)
            cls
        end loop
    end if

when does this loop exit?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
GabeC99




PostPosted: Fri Jan 16, 2015 10:07 am   Post subject: Re: RE:Can\'t get a ball to bounce off four sides

Tony @ Thu Jan 15, 2015 2:04 pm wrote:
From your code
code:

    if centerX = 200 - 25 then
        loop
            centerX := centerX - 1
            centerY := centerY + 1
            drawoval (centerX, centerY, 25, 25, 1)
            drawfill (centerX, centerY, 7, 1)

            delay (10)
            cls
        end loop
    end if

when does this loop exit?


It doesnt
Insectoid




PostPosted: Fri Jan 16, 2015 1:46 pm   Post subject: RE:Can\'t get a ball to bounce off four sides

That's right! So when does the rest of the code execute?
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  [ 4 Posts ]
Jump to:   


Style:  
Search: