Results 1 to 15 of 15

Thread: Accelerating and Decelerating

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    The Littlest State in the Union
    Posts
    57

    Exclamation

    Hey Im using (getkeystate) api for input and what I want to do is when some 1 presses space the Speedometer accelerates(This I can Do) but how can I make it so when space isn't pressed it will perform my deceleration. Please dont tell me to use Key_press and Key_Up.
    Thanks
    Visual Basic 6.0 Enterprise Edition
    Java 2
    Windows 98
    Mac OS 9.1

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Use a timer, and in your timer sub:
    Code:
    If key_is_pressed Then
        speed = speed + accel
    else
        speed = speed - decel
    end if
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    The Littlest State in the Union
    Posts
    57

    Exclamation Sorry

    Sorry that wont work cause there is going to be at least 5 more keys. Let me say Id like to use getkeystate api, cause Im familiar w/ it.
    Visual Basic 6.0 Enterprise Edition
    Java 2
    Windows 98
    Mac OS 9.1

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Just check the key state for each key individually in the timer procedure. You can use GetKeyState if you want.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    The Littlest State in the Union
    Posts
    57

    Another Prob

    Private Sub mainloop()
    Do While DoEvents
    If (GetKeyState(vbKeySpace)) Then
    Label1 = "Up"
    end if
    If (GetKeyState(vbKeySpace)and key_down)
    Label1 = "Down"
    End If

    Loop
    End Sub

    This was just a test but it works except for when you hold space and release.It only works if you tap space. Any idea?????
    Visual Basic 6.0 Enterprise Edition
    Java 2
    Windows 98
    Mac OS 9.1

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    This is sort-of-what-I-mean. I expect you can adapt the code from that:
    Attached Files Attached Files
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    How bout you do the if...then..elseif...endif statement and put in all your buttons, and at the end put in else, and then decelerate there.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    First look at this project (save as..), if it's what you need read THIS.

  9. #9
    Zaei
    Guest
    Create a couple of Booleans for each key. when you detect that Key X has been pressed (however you want to do it), set Boolean X to TRUE. Then, in your loop, just update accordingly, then get the keystates again. When its off, then set the Boolean to FALSE. XOR might help with this, for testing if the key should be switched.
    Code:
    If FIGetKeyStateFunction(KeyX) Xor KeyXIsDown Then
        KeyXIsDown = Not KeyXIsDown 
    End If
    Z.

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    The Littlest State in the Union
    Posts
    57

    Wink Fox......

    Fox I think your way is the best. But how come you need to show Me before you can call the loop. This is something that has puzzled me for years(not really).
    Visual Basic 6.0 Enterprise Edition
    Java 2
    Windows 98
    Mac OS 9.1

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    The Littlest State in the Union
    Posts
    57

    Thumbs up Actually

    I just checked Sastraxi's way and his is best...and its the easiest way!
    Visual Basic 6.0 Enterprise Edition
    Java 2
    Windows 98
    Mac OS 9.1

  12. #12
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    HA!

    Beat you fox! hehe

    j/k
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  13. #13
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Yeah

    Main thing is we could help him :P

  14. #14
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I know that... I think...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  15. #15
    Zaei
    Guest
    You have to call Me.Show, because when the main loop is in form_load, all code in the sub is executed BEFORE the form is shown. If you dont tell it to show the form first, nothing will appear to happen.

    Z.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width