key problem

This is a discussion on key problem within the Game Programming forums, part of the General Programming Boards category; I'm programming a RPG game in borland C++ 3.0 this is just for fun later i will change the graphic ...

  1. #1
    Registered User madsmile's Avatar
    Join Date
    Feb 2002
    Posts
    26

    Arrow 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...
    MADSmile
    ICQ #3653692
    (i'm running Borlad C++ Ver 3.1 under MSDOS)

  2. #2
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    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.

  3. #3
    Registered User madsmile's Avatar
    Join Date
    Feb 2002
    Posts
    26
    nop the problem is the guy moves too slow...
    MADSmile
    ICQ #3653692
    (i'm running Borlad C++ Ver 3.1 under MSDOS)

  4. #4
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    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...
    What is C++?

  5. #5
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    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();
      }
    }
    Last edited by JoshG; 06-05-2002 at 08:55 PM.

  6. #6
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    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?
    What is C++?

  7. #7
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    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.
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  8. #8
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Damn I am smart, jk. I used that method for my Sniper game, before I quit working on it.

  9. #9
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    lol ,
    have any of you checked out Leeman_s game yet? i need some help playing it...
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  10. #10
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    The DOOM_LORD one? I played it some, it seems nice. I don't have enough time to really play it though.

  11. #11
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    yup, its a really nice RPG.

    Its the best text-based RPG ive ever seen. Very creative and good battle system.
    What is C++?

  12. #12
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    how far have you gotten? i'm in room 47 and i've been making a map :P
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  13. #13
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    -_-;

    past the first few bad guys.......
    What is C++?

  14. #14
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    check out the map i posted hope leeman wont be upset cause i posted it up.

    http://www.cprogramming.com/cboard/s...threadid=19163
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  15. #15
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    so you guys really actually liked it?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 02:04 PM
  2. Mouvment problem
    By Death_Wraith in forum C++ Programming
    Replies: 9
    Last Post: 06-01-2004, 07:58 PM
  3. BCB Key press problem
    By Death_Wraith in forum Game Programming
    Replies: 0
    Last Post: 05-30-2004, 04:13 PM
  4. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 05:42 PM

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