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

Username:   Password: 
 RegisterRegister   
 2 directional buttons?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Darkshining




PostPosted: Tue Sep 20, 2005 7:13 pm   Post subject: 2 directional buttons?

How do you use two directional buttons at once?
code:
var key : string (1) := ""
var chars : array char of boolean
var x, y, b : int
var ballx, bally : int := 200
loop
    setscreen ("graphics:600;600")
    setscreen ("offscreenonly")
    View.Update
    Draw.FillBox (0, 0, maxx, maxy, 255)
    Draw.FillOval (ballx, bally, 20, 20, blue)
    Input.KeyDown (chars)       
        if chars (KEY_UP_ARROW) then
            bally := bally + 2
        delay (20)
        elsif chars (KEY_DOWN_ARROW) then
            bally := bally - 2
        delay (20)
        elsif chars (KEY_RIGHT_ARROW) then
            ballx := ballx + 2
        delay (20)
        elsif chars (KEY_LEFT_ARROW) then
            ballx := ballx - 2
        delay (20)
        end if
end loop


like this?
code:
elsif chars (KEY_UP_ARROW + KEY_RIGHT_ARROW) then
            bally := bally + 2
            ballx := ballx + 2
        elsif chars (KEY_UP_ARROW + KEY_LEFT_ARROW) then
            bally := bally + 2
            ballx := ballx - 2
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Tue Sep 20, 2005 7:20 pm   Post subject: Re: 2 directional buttons?

Thusly
code:
elsif chars (KEY_UP_ARROW) and chars(KEY_RIGHT_ARROW) then
            bally := bally + 2
            ballx := ballx + 2
        elsif chars (KEY_UP_ARROW) and chars (KEY_LEFT_ARROW) then
            bally := bally + 2
            ballx := ballx - 2
Darkshining




PostPosted: Tue Sep 20, 2005 7:22 pm   Post subject: (No subject)

Ohh, thank you, i didn't know you can't put two keys in one bracket.

oh, one small problem, the program runs, but when you press KEY_UP_ARROW and KEY_RIGHT_ARROW
or
KEY_UP_ARROW and KEY_LEFT_ARROW it doesn't not respond the way it was supposed to. it just goes up.
how can i make it go diagonal?
Cervantes




PostPosted: Tue Sep 20, 2005 7:35 pm   Post subject: (No subject)

Don't use elsifs. Just use four ifs. Do it, and you should see why. Smile
Darkshining




PostPosted: Tue Sep 20, 2005 7:44 pm   Post subject: (No subject)

Like this?
this one has two errors, don't you have to use ifs with at least one else?
and syntax error at end loop for some reason?
code:
var key : string (1) := ""
var chars : array char of boolean
var x, y, b : int
var ballx, bally : int := 200
loop
    setscreen ("graphics:600;600")
    setscreen ("offscreenonly")
    View.Update
    Draw.FillBox (0, 0, maxx, maxy, 255)
    Draw.FillOval (ballx, bally, 20, 20, blue)
    Input.KeyDown (chars)       
        if chars (KEY_UP_ARROW) then
            bally := bally + 2
        delay (5)
        if chars (KEY_DOWN_ARROW) then
            bally := bally - 2
        delay (5)
        if chars (KEY_RIGHT_ARROW) then
            ballx := ballx + 2
        delay (5)
        if chars (KEY_LEFT_ARROW) then
            ballx := ballx - 2
        delay (5)
        if chars (KEY_UP_ARROW) and chars(KEY_RIGHT_ARROW) then
            bally := bally + 2
            ballx := ballx + 2
        delay (5)   
        if chars (KEY_UP_ARROW) and chars (KEY_LEFT_ARROW) then
            bally := bally + 2
            ballx := ballx - 2
        delay (5)
        end if
end loop
[/quote]
jamonathin




PostPosted: Tue Sep 20, 2005 8:16 pm   Post subject: (No subject)

Maybe you should take a quick glance at an 'if' tutorial.

I can go . . .

code:

if key (KEY_UP_ARRROW) then
     x += y
elsif key (KEY_DOWN_ARROW) then
     y += x
end if

and that's One if statement.

Or i can go
code:

if key (KEY_UP_ARRROW) then
     x += y
end if
if key (KEY_DOWN_ARROW) then
     y += x
end if

And there's two if statements.

Your problem is you didn't put any 'end ifs' at the, well, end of your ifs.

Oh, and mite i add, put ONE delay, at the end of your loop, not in every if statement.

code:

loop
     // blah blah blah
     delay (5)
end loop
Darkshining




PostPosted: Tue Sep 20, 2005 8:39 pm   Post subject: (No subject)

Thank you, i just want to add i started learning Turing one week ago.
oh, this seems like a silly question but, how do you draw a semicircle?
Mr. T




PostPosted: Tue Sep 20, 2005 8:55 pm   Post subject: AlexYoung

Draw a circle using the Draw.Oval command, then cover half the circle with a square (Draw.Box) that is the same colour as the background.
Sponsor
Sponsor
Sponsor
sponsor
beard0




PostPosted: Tue Sep 20, 2005 9:14 pm   Post subject: Re: AlexYoung

Pwned wrote:
Draw a circle using the Draw.Oval command, then cover half the circle with a square (Draw.Box) that is the same colour as the background.

Ouch!!!! Please no, use Draw.Arc, and just use initial and final angles 180 degrees apart.

Also,
Darkshining wrote:
don't you have to use ifs with at least one else

This is seen by some as a good coding practice. They think that it makes it more clear if when you want to do something in one case only, that you explicitly state that you want to do nothing otherwise. This is not my view; I'm simply relaying this as a possible explanation as to why Darkshining may have thought this neccessary.
jamonathin




PostPosted: Wed Sep 21, 2005 7:51 am   Post subject: (No subject)

One thing you may want to remember, is your good buddy F10. Just go to search, and type in whatever you want to look for.

For example if there's something you want to draw, type 'draw'.
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  [ 10 Posts ]
Jump to:   


Style:  
Search: