Does anyone know how to move a character whit keyboard in visual c++??
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++............Originally posted by Unskilled
Does anyone know how to move a character whit keyboard in visual c++??
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.......
jeff you loser go to tda
Sorry for not explaning well.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.......
I want to start moving a character like 'a' in a console.
Check out the console tutorials at Game Tutorials
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.
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
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:
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: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)
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