Computer Science Canada

Can't get a ball to bounce off four sides

Author:  GabeC99 [ 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

Author:  Tony [ 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?

Author:  GabeC99 [ 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

Author:  Insectoid [ 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?


: