Results 1 to 8 of 8

Thread: game programm.. need help

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    California
    Posts
    2

    game programm.. need help

    i have a chase game... the computer chases u... and the problem is well sometimes when i quickly press right... it goes twice, not once to the right =(... i use timers for both computer and human controls.. so plz help me! I need to fix this cause the human char can get into a base and be safe from the computer... but if he misses it w/ one of those 2 walks thatd be bad.. PLZ HELP!

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well the way I do it is that I store what the 4 key positions are like :

    VB Code:
    1. Private keyLeft As Boolean
    2.     Private keyRight As Boolean
    3.     Private keyUp As Boolean
    4.     Private keyDown As Boolean

    So when the user presses a key, it sets two of the above to either True or False. If the user presses Right, then keyRight is True, and keyLeft is False.

    And then in the timer event (though I normally use GetTickCount), I check is keyLeft or keyRight true, and if one of them is, then move the person in that direction, and then set it to false.
    Same for up/down.

    Ya follow ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    How are you collecting your input at the moment?
    Harry.

    "From one thing, know ten thousand things."

  4. #4
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    With windows programming the way it works is by sending messages to the window everytime an action occurs, whats happenign here is when a key is held windows doesnt sa "hey that keys being pressed" it just repeatedly says "key pressed". So on the forms keyUp / KeyDown u have to set a boolean variable on whether the key is down and then check if the vari is true or false.

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    California
    Posts
    2

    Arrow ...

    Actually that is almost what i did.... and that wasnt the problem... the problem is that i held the button down for 3 milli-seconds and the timer looped about every 1 milli-second... and well i dont need that no more cause i changed the game around so it dont need that nomore =). but thnx for re-plying

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Remember,

    Timer Control : Evil
    GetTickCount : Saintly
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  7. #7
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Originally posted by plenderj
    Remember,

    Timer Control : Evil
    GetTickCount : Saintly
    Lol theres nothing that bad about Timer. Its just imprecise below about 60 ms. If you want evil just look at FSO...
    You just proved that sig advertisements work.

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    You must limit the number of times the game updates, instead of the number of times the SCREEN updates. They should be different, unless the screen refresh is limited as well.

    Try this.
    VB Code:
    1. Dim ms as Long
    2.    ms = GetTickCount
    3.    Do
    4.       UpdateSCREEN 'draw things
    5.       If GetTickCount - ms >= 1000 / gameUpdsPerSecond 'set this variable to like 33 or so, for 30 updates per second. For refrence, the SNES console has this set to 60 for all games.
    6.          UpdateGAME
    7.          ms = GetTickCount
    8.       End If
    9.       DoEvents
    10.    Loop
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

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