On-Key changes

This is a discussion on On-Key changes within the Game Programming forums, part of the General Programming Boards category; I need my game to move the guy up on up arrow, odwn on down arrow, etc, but i cant ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    206

    On-Key changes

    I need my game to move the guy up on up arrow, odwn on down arrow, etc, but i cant do it. i was think somewhere along the lines of this?

    Code:
    		if(_kbhit() == (char)75)
    		{
    			posone -= 1;
    		}
    		else if(_kbhit() == (char)77)
    		{
    			posone += 1;
    		}
    		else if(_kbhit() == (char)72)
    		{
    			postwo -= 1;
    		}
    		else if(_kbhit() == (char)80)
    		{
    			postwo += 1;
    		}
    of course its wrong but any help would be appreciated.
    P.S. posone is left(negative) right(positive) and postwo is up(negative) down(positive) on the game map.(stored in a 2d array, map[posone][postwo], get it? )

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Code:
    char keyPress;
    
    keyPress = getc();
    switch(keyPress)
    {
           case 75 : /*blah blah blah*/;break;
           case 77 : /*blah blah blah*/;break;
           case 72 : /*blah blah blah*/;break;
           case 80 : /*blah blah blah*/;break;
           default  : break;
    }

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    thank you it worked ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 05:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    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