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

Username:   Password: 
 RegisterRegister   
 "Bouncing" a circle
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
yazdmich




PostPosted: Thu Oct 11, 2012 9:24 pm   Post subject: "Bouncing" a circle

What is it you are trying to achieve?
Bounce a circle off the edge of an output window


What is the problem you are having?
can't get it to loop properly


Describe what you have tried to solve this problem
loops, procedures, forward declarations


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing:


setscreen ("graphics:700;700")
var x, y : int
const inc := 5
const radius := 25
var chars : array char of boolean
forward procedure moveup
forward procedure movedown
forward procedure moveleft
forward procedure moveright
procedure keydown
    Input.KeyDown (chars)
end keydown
body procedure moveup
    loop
        keydown
        exit when not chars (KEY_UP_ARROW)
        y := y + inc
        if y > maxy - radius then
            movedown
        end if
        delay (100)
        drawoval (x, y, radius, radius, 1)
    end loop
end moveup
body procedure movedown
    y := y - inc
    if y < radius then
        moveup
    end if
end movedown
body procedure moveright
    x := x + inc
    if x > maxx - radius then
        moveleft
    end if
end moveright
body procedure moveleft
    x := x - inc
    if x < radius then
        moveright
    end if
end moveleft
x := maxx div 2
y := maxy div 2
loop
    keydown
    if chars (KEY_LEFT_ARROW) or chars (KEY_RIGHT_ARROW) or chars (KEY_UP_ARROW) or chars (KEY_DOWN_ARROW) then
        loop
            keydown
            if chars (KEY_LEFT_ARROW) then
                moveleft
            end if
            if chars (KEY_RIGHT_ARROW) then
                moveright
            end if
            if chars (KEY_DOWN_ARROW) then
                movedown
            end if
            if chars (KEY_UP_ARROW) then
                moveup
            end if
        end loop
    else
        loop
            keydown
            exit when chars (KEY_LEFT_ARROW) or chars (KEY_RIGHT_ARROW) or chars (KEY_UP_ARROW)
            moveup
            delay (100)
            drawoval (x, y, radius, radius, 1)
        end loop
    end if
end loop



Please specify what version of Turing you are using
OpenTuring 1.0.1 (based on 4.1.2)
Sponsor
Sponsor
Sponsor
sponsor
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  [ 1 Posts ]
Jump to:   


Style:  
Search: