Thread: Any peeps in here know how to.....

  1. #1
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    Any peeps in here know how to.....

    anyone know how to move the character @ up, down, left, and right when the specific buttons are pressed?
    dank you
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  2. #2
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    Like this?:

    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <stdlib.h>
    
    void main()
    {
       char ch;
       int x = 10, y = 10;
    
       gotoxy(x, y);
       cout << "@";
    
       while(1)
       {
          ch = getch();
          gotoxy(x, y);
          cout << " ";
    
          switch(ch)
          {
             case 'a': x--;
                       break;
    
             case 's': x++;
                       break;
    
             case 'z': y++;
                       break;
    
             case 'w': y--;
                       break;
    
             default: exit(0);
          }
    
          gotoxy(x, y);
          cout << "@";
       }
    }
    Sorry about not commenting....

  3. #3
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    Umm......Well, not like that......

    well, not like that. that code closes when a button is pressed. How about using the getch(); command??
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  4. #4
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    >well, not like that. that code closes when a button is pressed. How about using the getch(); command??<

    What do you mean the code closes when a button is pressed?

    And, if you pay attention to the code, you'll notice I do indeed use getch().

    Press [a] to move the character left.
    Press [s] to move the character right.
    Press [w] to move the character up.
    Press [z] to move the character down.

    Hope that helps...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hi peeps!
    By beene in forum C++ Programming
    Replies: 11
    Last Post: 08-09-2006, 04:00 AM
  2. Pointer and Arrays
    By big146 in forum C++ Programming
    Replies: 5
    Last Post: 06-14-2004, 06:23 PM
  3. hey peeps, the lord of the nightmares is back
    By Null Shinji in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 11-13-2001, 12:17 AM