
-----------------------------------
therealbuba
Sun Apr 26, 2009 6:17 pm

Movement Help
-----------------------------------
What is it you are trying to achieve?
Get a plane in an animation to move according to how directional buttons.


What is the problem you are having?
Turing only takes one Input keydown at a time.


Describe what you have tried to solve this problem
I created two array char of boolean for Input Keydown and an if statement for them. Basically i want the plane to move up and right when i press up and right arrows.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
For example

     Please specify what version of Turing you are using
Latest

Would appriciate the help guys :D

-----------------------------------
Dusk Eagle
Sun Apr 26, 2009 7:13 pm

Re: Movement Help
-----------------------------------
if c(KEY_UP_ARROW) and c(KEY_RIGHT_ARROW) then
%whatever you want%
This works fine for me.

-----------------------------------
therealbuba
Sun Apr 26, 2009 8:33 pm

RE:Movement Help
-----------------------------------
Really? For some reason it won't work for me... :(

-----------------------------------
Dusk Eagle
Sun Apr 26, 2009 8:58 pm

Re: Movement Help
-----------------------------------
Are you sure the problem is with your character inputs and not your logic for moving the plane up? Try commenting out all the code within the condition and simply typing "put true". Be sure to View.Update if necessary. Then see if pressing those two buttons outputs "true" to the screen.

-----------------------------------
therealbuba
Sun Apr 26, 2009 9:05 pm

RE:Movement Help
-----------------------------------
No my logic fine, it works when i use only one of the inputs to move the plane, it moves up and down corresponding to arrows as well as right and left, however when combining it only moves in the direction of the first arrow pressed.

-----------------------------------
DifinityRJ
Mon Apr 27, 2009 11:15 am

Re: Movement Help
-----------------------------------

setscreen ("offscreenonly")
var chars : array char of boolean
var x, y : int := 100
proc drawplayer
    Draw.FillBox (x, y, x + 10, y + 10, black)
end drawplayer
proc getkeys
    Input.KeyDown (chars)
    if chars (KEY_LEFT_ARROW) then
        x -= 1
    end if
    if chars (KEY_RIGHT_ARROW) then
        x += 1
    end if
    if chars (KEY_UP_ARROW) then
        y += 1
    end if
    if chars (KEY_DOWN_ARROW) then
        y -= 1
    end if
end getkeys
loop
    cls
    getkeys
    drawplayer
    delay (10)
    View.Update
end loop


Code is self-explanatory.

Does this help, or were you trying to do something else?

If you put elsif for each new key, you can only press one key at a time.  However, if they are in different if-statements you can press multiple keys at a time.

-----------------------------------
therealbuba
Mon Apr 27, 2009 4:23 pm

RE:Movement Help
-----------------------------------
K thank you so much i got it :)

+bits :)
