View Full Version : help! :D
Unskilled
10-02-2003, 07:33 AM
Does anyone know how to move a character whit keyboard in visual c++??
jverkoey
10-02-2003, 09:26 AM
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
is left key pressed
move character left
is right key pressed
move character right
....etc.......
Silvercord
10-02-2003, 09:40 AM
jeff you loser go to tda
Unskilled
10-02-2003, 10:26 AM
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
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.
jdinger
10-02-2003, 12:11 PM
Check out the console tutorials at Game Tutorials (http://www.gametutorials.com)
Unskilled
10-02-2003, 12:40 PM
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.
harryP
10-02-2003, 02:37 PM
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:
for(;;)
{
if(kbhit())
{
char key = getch();
if(key == 'w') // Move forward
{
// Movement code here
}
}
// Do something else if a key isn't it
DoSomething();
}
jverkoey
10-02-2003, 09:41 PM
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:
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 :)
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.