Want to see if I am using gotoxy the right way ...

This is a discussion on Want to see if I am using gotoxy the right way ... within the C++ Programming forums, part of the General Programming Boards category; I have come to the part in my rpg game where I need to start making the character move around ...

  1. #1
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138

    Want to see if I am using gotoxy the right way ...

    I have come to the part in my rpg game where I need to start making the character move around . I just wanted to make sure that I am going about it all the right away. Here is my code:
    Code:
    //testing the gotoxy() function :)
    #include <iostream>
    #include <windows.h>
    #include <stdio.h> 
    #include <conio.h>
    
    using namespace std;
    void gotoxy();
    
    int x,y,oldx,oldy;
    void gotoxy(int, int)
    {
      COORD coord;
      coord.X = x;
      coord.Y = y;
      SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }
    
    /* System dependent key codes */
    enum
    {
      KEY_ESC     = 27,
      ARROW_UP    = 256 + 72,
      ARROW_DOWN  = 256 + 80,
      ARROW_LEFT  = 256 + 75,
      ARROW_RIGHT = 256 + 77
    };
    
    static int get_code ( void )
    {
      int ch = getch();
    
      if ( ch == 0 || ch == 224 )
        ch = 256 + getch();
    
      return ch;
    }
    char smiley = 1;
    
    int main ( void )
    {
        x=0,y=0;
    	int ch;
    	putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);
        putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);
        putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);
        putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);
        putchar(2);putchar(2);
        putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);putchar(2);
        putchar(2);putchar(2);	
    while ( ( ch = get_code() ) != KEY_ESC ) {
        switch ( ch ) {
        case ARROW_UP:
          gotoxy(x,y--);
    	  putchar(1);
    	  gotoxy(x,y++);
    	  putchar(2);
    	  gotoxy(x,y--);
          break;
        case ARROW_DOWN:
          gotoxy(x,y++);
    	  putchar(1);
    	  gotoxy(x,y--);
    	  putchar(2);
    	  gotoxy(x,y++);
          break;
        case ARROW_LEFT:
          gotoxy(x--,y);
    	  putchar(1);
    	  gotoxy(x++,y);
    	  putchar(2);
    	  gotoxy(x--,y);
    		   
          break;
        case ARROW_RIGHT:
          gotoxy(x++,y);
    	  putchar(1);
    	  gotoxy(x--,y);
    	  putchar(2);
    	  gotoxy(x++,y);
          break;
        }
      }
      system("PAUSE");
      return 0;
    }
    it works the way I want, but is it right? Thanks!

  2. #2
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138
    so I dont have to know what the char my smiley will cover each time, is there a way to get the the char, then cover it with smiley, then use that char and put it back when I move the smiley again?

    for example:
    Code:
    gotoxy(x++, y)
    cin >> temp; //note- I already tried using cin but it didnt work
    putchar(1);
    gotoxy(x--,y)
    putchar(temp);
    gotoxy(x++,y)

  3. #3
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    You could store the entire area in an array like I do...

    Code:
    struct block_struct {
    int forecolor;
    int backcolor;
    int asciichar;
    };
    block_struct board[MAX_HEIGHT][MAX_WIDTH];
    Then to replace the character's coordinates, just get the data from that.

    I've attached my code so you can see. It'll compile under BCC 3.1.
    Attached Files Attached Files

  4. #4
    Registered User slaveofthenet's Avatar
    Join Date
    Apr 2003
    Posts
    80
    I would highly suggest putting all of those putchars into a loop
    Code:
    for (int i = 0; i < 793; i++)
         putchar(2);

  5. #5
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138
    thanks for replies! I normally wouldnt do all the putchars like that, but I was in kind of a rush and I just wanted to test out gotoxy.

  6. #6
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    typing out that loop would be faster than even cutting and pasting all that :P
    Away.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is gotoxy??
    By Beachblue in forum C Programming
    Replies: 6
    Last Post: 11-23-2008, 12:24 AM
  2. Tic Tac Toe movement
    By $l4xklynx in forum Game Programming
    Replies: 4
    Last Post: 11-06-2008, 06:22 PM
  3. gotoxy(); help!!
    By clique in forum C Programming
    Replies: 2
    Last Post: 10-07-2008, 04:08 AM
  4. Is gotoxy ansi?
    By MeneLaus in forum C Programming
    Replies: 2
    Last Post: 05-18-2002, 02:48 PM
  5. is gotoxy a part of ANSI C 89 standard
    By kendals in forum C Programming
    Replies: 1
    Last Post: 03-20-2002, 06:43 PM

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