# key problem

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 06-05-2002
key problem
I'm programming a RPG game in borland C++ 3.0
this is just for fun later i will change the graphic mode to opengl or directx but for now is with BGI

my question is how do i know when a key is pressed and when is a key is normal... that's for this reason:

i can capture the key with getch(), i'm capturing the up,down,left,right keys this is for the moving the character on the screen, but it moves slow cuz the D.O.S. key respond, i think that is the problem, is like then you press a key and you keep pressed you see the letter then it begins to repeat on the screen but slowly...

my procedure es something like this:
Code:

```while (tecla!='0') do //with 0 it exit, this is just an example {   tecla=getch();   //here i evaluate the key }```
plz help... i just need help with this...
• 06-05-2002
JoshG
I would help you, but I do not understand your problem. Are you saying your program moves too fast? It acts like you hit a key more than once? Look up kbhit() it is in conio.h.
• 06-05-2002
nop the problem is the guy moves too slow...
• 06-05-2002
Vicious
do you have a

X++ or y++ in a game loop?

if so try changing it to

x += 10 or y+= 10

the igher number the faster it mooves.

++ is one space at a time

+= 5 is five spaces at a time ect...
• 06-05-2002
JoshG
That could also make him move "jumpy". I had a sprite that I had to make move faster, but when I used x = x + 20; It was too jumpy. So for everytime the user pressed right, I made it do something like this:

Code:

```if(inkey == KEY_RIGHT) {   x = x + 5;   redrawsprite();   x = x + 5;   redrawsprite();   x = x + 5;   redrawsprite();   x = x + 5;   redrawsprite(); }```
See how that works?

Could have been:
Code:

```if(inkey == KEY_RIGHT) {   for(int j = 1; j <= 4; j++)   {     x = x + (5 * j);     redrawsprite();   } }```
• 06-05-2002
Vicious
yah it would be jumpy, unless you had it on a higer resolution.

Josh will you code make it run fast and smooth.

Run one space at a time just faster instead of multiple spaces?
• 06-05-2002
red_baron
your code will work good joshG. i'm pretty sure if you do the for loop to move a couple of spaces with each key press will make the game much smoother.
• 06-05-2002
JoshG
Damn I am smart, jk. I used that method for my Sniper game, before I quit working on it.
• 06-05-2002
red_baron
lol ,
have any of you checked out Leeman_s game yet? i need some help playing it...
• 06-05-2002
JoshG
The DOOM_LORD one? I played it some, it seems nice. I don't have enough time to really play it though.
• 06-05-2002
Vicious
yup, its a really nice RPG.

Its the best text-based RPG ive ever seen. Very creative and good battle system.
• 06-05-2002
red_baron
how far have you gotten? i'm in room 47 and i've been making a map :P
• 06-05-2002
Vicious
-_-;

past the first few bad guys.......
• 06-05-2002
red_baron
check out the map i posted hope leeman wont be upset cause i posted it up.