Thread: How do i make my sprite move?

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    5

    How do i make my sprite move?

    What code do I punch in to make the arrow keys move my little guy?

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    well, since you haven't told us what platform this is for or what input API you're using (if you're using one, at all) it's hard to say.

    You need to give more details about how you're writing this game in the first place.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    9
    if kbhit()
    {
    char dir=getch();

    if (dir==72)
    x--;

    }

    ...etc.

    Just look around to find the codes for the other keys.

    PS: I might be wrong about left being 72.

  4. #4
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    um he said sprite not console char, if im understanding correctly

  5. #5
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    No, Leeman, the code that smartperson posted would work. It is almost identical to the code that I have used in several of my early 13h graphical programs. Of course it needs some tailoring to the purpose of the invidiual program, but that general code is a very good example and will work.

    The numbers of the arrow keys in the ASCII character set are:

    right arrow = 77
    left arrow = 75
    up arrow = 72
    down arrow = 80
    My Website

    "Circular logic is good because it is."

  6. #6
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    oh ok, 13h mode. i was refering to thinking he was asking about an api such as allegro, dx, opengl or something of that likes.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    99
    I don't think DavidP was neccessarily saying that Hyper was using 13h, but just saying that the code was similar to what HE used in 13h. Although I could be wrong. Maybe the thread starter should clear this up, then he'll probably get the answer that he is looking for.

  8. #8
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    Yes, although it is very similar to what I used in 13h, it can be used in other graphic modes an APIs. Even in OpenGL, DX, SDL, etc. Although I suggest using those API's built in keyboard handlers, you can also handle the keyboard this way in those API's, except for using the getch function, you would probably need a different function instead of getch.
    My Website

    "Circular logic is good because it is."

  9. #9
    if you are going to make a free roaming game, collision detection will kill you if you put it in . It may be just me, but I have always sucked at collision detection.

  10. #10
    Anonymous
    Guest
    Sorry, I should've been more specific, its a console application, and the game is an overhead view. (It is me, I just didn't feel like logging in)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List (Base 21)
    By ATXFG in forum C Programming
    Replies: 3
    Last Post: 04-01-2007, 09:58 PM
  2. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  3. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  4. Replies: 12
    Last Post: 06-06-2005, 05:45 AM
  5. Formatting Output
    By Aakash Datt in forum C++ Programming
    Replies: 2
    Last Post: 05-16-2003, 08:20 PM