
-----------------------------------
Darkshining
Tue Sep 20, 2005 7:13 pm

2 directional buttons?
-----------------------------------
How do you use two directional buttons at once?
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?
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


-----------------------------------
Mazer
Tue Sep 20, 2005 7:20 pm

Re: 2 directional buttons?
-----------------------------------
Thusly
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
Tue Sep 20, 2005 7:22 pm


-----------------------------------
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
Tue Sep 20, 2005 7:35 pm


-----------------------------------
Don't use elsifs.  Just use four ifs.  Do it, and you should see why. :)

-----------------------------------
Darkshining
Tue Sep 20, 2005 7:44 pm


-----------------------------------
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?
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
Tue Sep 20, 2005 8:16 pm


-----------------------------------
Maybe you should take a quick glance at an 'if' tutorial.

I can go . . .


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 

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.


loop
     // blah blah blah
     delay (5)
end loop

-----------------------------------
Darkshining
Tue Sep 20, 2005 8:39 pm


-----------------------------------
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
Tue Sep 20, 2005 8:55 pm

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.

-----------------------------------
beard0
Tue Sep 20, 2005 9:14 pm

Re: 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.
Ouch!!!!  Please no, use Draw.Arc, and just use initial and final angles 180 degrees apart.

Also,
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
Wed Sep 21, 2005 7:51 am


-----------------------------------
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'.
