Language C - Position my Printf in X and Y on the screen.

  • Thread starter Max0007
  • Start date
  • #1
66
1

Homework Statement


I work on Microsoft Visual studio 2010 on Win7.

Ok so let me explain the problem here, The functions works very good to position my printf in X and Y on my screen ONLY when my 2D Array labyrinth Map is NOT printed on the screen.

But once I printf my Map on the screen I cannot position the printf in X and Y.

This is the current code I use to position my printf and only works when my Map is not printed on the screen.

gotoxy(posx,5); clreoscr();
textcolor(15);
posx = printf("\nSpeed of Character: %d / %d",speed, m1);
textcolor(15);
posx = printf("\nSpeed of enemie: %d / %d", speed_e, m2);


This is the functions I have to use to give my printf a position on my screen.
----------------------------------------------------------------------------------------------------------------------------
void gotoxy(int x,int y) //positions text cursor at (x, y) screen position
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo; //variable declarations
HANDLE hConsoleOut;

hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);

csbiInfo.dwCursorPosition.X = x; //cursor position X coordinate
csbiInfo.dwCursorPosition.Y = y; //cursor position Y coordinate
SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition); //set cursor at the given screen coordinate
}


/*-------------------------wherex()------------------------------------*/

int wherex() //returns current text cursor (x) coordinate
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
return csbiInfo.dwCursorPosition.X;
}

/*-------------------------wherey()----------------------------------*/

int wherey() //returns current text cursor (y) coordinate
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
return csbiInfo.dwCursorPosition.Y;
}




Homework Equations


n/A

The Attempt at a Solution


N/A
 

Answers and Replies

  • #2
12,031
5,693
If this is a character based game then have you looked at ANSI codes?

http://en.m.wikipedia.org/wiki/ANSI_codes

I've,used them a lot in my character based programs and scripts to control where I print things to the display. They work in all sorts of languages once you learn how to represent escape codes in your program.
 

Related Threads on Language C - Position my Printf in X and Y on the screen.

  • Last Post
Replies
8
Views
1K
  • Last Post
Replies
5
Views
1K
  • Last Post
Replies
6
Views
2K
  • Last Post
Replies
13
Views
2K
  • Last Post
Replies
1
Views
4K
Replies
8
Views
536
  • Last Post
Replies
1
Views
834
  • Last Post
Replies
1
Views
2K
Replies
4
Views
2K
Replies
12
Views
13K
Top