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

Username:   Password: 
 RegisterRegister   
 Movement Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
therealbuba




PostPosted: Sun Apr 26, 2009 6:17 pm   Post subject: 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

code:
   elsif a (KEY_UP_ARROW) and b (KEY_RIGHT_ARROW) then
            vy := vy + 3
            vx := vx + 5


where a and b are two array char of boolean vars


Please specify what version of Turing you are using
Latest

Would appriciate the help guys Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Dusk Eagle




PostPosted: Sun Apr 26, 2009 7:13 pm   Post subject: Re: Movement Help

Turing:
if c(KEY_UP_ARROW) and c(KEY_RIGHT_ARROW) then
%whatever you want%

This works fine for me.
therealbuba




PostPosted: Sun Apr 26, 2009 8:33 pm   Post subject: RE:Movement Help

Really? For some reason it won't work for me... Sad
Dusk Eagle




PostPosted: Sun Apr 26, 2009 8:58 pm   Post subject: 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




PostPosted: Sun Apr 26, 2009 9:05 pm   Post subject: 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




PostPosted: Mon Apr 27, 2009 11:15 am   Post subject: Re: Movement Help

Turing:

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




PostPosted: Mon Apr 27, 2009 4:23 pm   Post subject: RE:Movement Help

K thank you so much i got it Smile

+bits Smile
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  [ 7 Posts ]
Jump to:   


Style:  
Search: