help! :D

This is a discussion on help! :D within the Game Programming forums, part of the General Programming Boards category; Does anyone know how to move a character whit keyboard in visual c++??...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    3

    help! :D

    Does anyone know how to move a character whit keyboard in visual c++??

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903

    Re: help! :D

    Originally posted by Unskilled
    Does anyone know how to move a character whit keyboard in visual c++??
    ok, first off, the only bit of info you gave for us to work with is that you want to move a character with the keyboard, and you're using VC++............

    now, we need to know a few other things before we can fully answer your question:

    what do you want to move it in? a console? openGL? directx? win32?
    what type of character? a character sprite? a character letter ('a')?


    basically, however, the basic way it works for moving characters on a screen:

    in pseudocode
    Code:
    is left key pressed
         move character left
    is right key pressed
         move character right
    ....etc.......

  3. #3
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    jeff you loser go to tda

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    3

    Re: Re: help! :D

    Originally posted by jverkoey
    ok, first off, the only bit of info you gave for us to work with is that you want to move a character with the keyboard, and you're using VC++............

    now, we need to know a few other things before we can fully answer your question:

    what do you want to move it in? a console? openGL? directx? win32?
    what type of character? a character sprite? a character letter ('a')?


    basically, however, the basic way it works for moving characters on a screen:

    in pseudocode
    Code:
    is left key pressed
         move character left
    is right key pressed
         move character right
    ....etc.......
    Sorry for not explaning well.
    I want to start moving a character like 'a' in a console.

  5. #5
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Check out the console tutorials at Game Tutorials

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    3
    I have been there. Do you have any idea how to move an object whit a constant velocity??
    So when i hold a key, the object don't stop a while and continue whit a higher velocity. You could se this problem if you open notepad and hold a key like 'a' you will notice that it stops a while and then it continues whit a higher velocity.

    And other problem that i cannot solve is how to make an object move holding a key and at the same time pressing an other key whitout stoping the object. I will be very grateful if you could show me some examples so i can understand better.

  7. #7
    Registered User harryP's Avatar
    Join Date
    Sep 2002
    Posts
    124
    I don't know about pressing the other key thing, but if you want other things in your game to continue going on even if the user is pressing a key, use the function "kbhit()". An example:
    Code:
    for(;;)
    {
         if(kbhit())
         {
              char key = getch();
              if(key == 'w') // Move forward
              {
                    // Movement code here
              }
         }
         // Do something else if a key isn't it
         DoSomething();
    }
    Draco dormiens nunquam titallandus.
    Console Graphics Library: http://www.geocities.com/steve_alberto/cgl.html

  8. #8
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    ok, check out GetAsyncKeyState(a) & 0x81 where a is a value (for example: a='A'). this tests the state of 'A' and if it is, returns true

    example:

    Code:
    if(GetAsyncKeyState(VK_UP) & 0x81)  // VK_UP is a "virtual key" for the up arrow key, right click it and say "go to definition" if you want to see more about other virtual keys
           MoveCharacter(0,-1);
    if(GetAsyncKeyState(VK_DOWN) & 0x81)
           MoveCharacter(0,1);
    
    .....etc........with the other keys...........where MoveCharacter would move the character based on (x,y)
    hopefully that won't confuse you too much you might need windows.h to use that function. and if the above doesn't work they way you want, try them out these ways:

    GetAsyncKeyState(VK_UP) & 0x80
    GetAsyncKeyState(VK_UP) & 0x01

    each one testing different bits......i'm not exactly sure which one does it the way you want to, so just test 'em all

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21