• Advertisement
Sign in to follow this  

Making ascii characters move aound the screen

This topic is 4315 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am just learning C++ programming using several online tutorials for basic learning. (www.cplusplus.com, www.programmingtutorials.com, etc.) I have been searching around for any good tutorials that deal in any way with little programs for making ascii characters move around on the screen. Does anyone know of any good online tutorials for this?

Share this post


Link to post
Share on other sites
Advertisement
You can't do it with IOstream, and you can't do it with C's IO functions. You need a console API. Here is the MSDN reference to the windows one:

linky

Share this post


Link to post
Share on other sites
Since I cant find the tutorial that I used so I post up some old code where you be able extract the imformation from.

This is only VERY basic and you can far more in the console then what is shown here (eg Back buffering) but hopefully it get you started.

/*----------------------------------------------//
| Date: 28/03/2003 |
| Author: Yaustar |
| Title: Fireman Test |
//----------------------------------------------*/


#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

/*----------------------------------------------*/

void gotoxy(int X, char Z){ /*Used to print a character anywhere on the
screen*/

COORD coord;
coord.X = X;
coord.Y = 20;

HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsole, coord);

cout << Z;
}

/*----------------------------------------------*/

int main(void){

int x = 0, currentLetter = 0;
char sequence[] = {'r', 'q', 'w', 'e', 'r', 'q'}, input = 'p';

while(1){ /*While loops does not stop*/

Sleep(100); /*Pause for a 1/2 of a second*/

if(kbhit()){ /*If a key is pressed*/
input = tolower(getch());
gotoxy(x, ' ');
}

// gotoxy(x, '@'); /*Display the updated character position*/

// gotoxy(x, ' ');

if(input == sequence[currentLetter + 1]){
/*If the button press is in direction right*/
// gotoxy(x, ' '); /*Blank the last position of the character*/
x = x + 1;
gotoxy(x, '@');
currentLetter = currentLetter + 1;
if(currentLetter == 5){currentLetter = 1;}
}

if(input == sequence[currentLetter - 1]){
/*If the button press is in direction left*/
// gotoxy(x, ' '); /*Blank the last position of the character*/
x = x - 1;
gotoxy(x, '@');
currentLetter = currentLetter - 1;
if(currentLetter == 0){currentLetter = 4;}
}

if(input == 27){return 0;} /*If esc is pressed, quit program*/

}

return 0;

}

/*----------------------------------------------*/

Share this post


Link to post
Share on other sites
http://www.adrianxw.dk/SoftwareSite has some good tutorials that can help you get started on using the win32 console.

yaustar - Maybe its just me but I fing your program quite confusing, you have a function called gotoxy but only set the x coordinate. Shouldn't it just be called gotox? Also what is char sequence[] = {'r', 'q', 'w', 'e', 'r', 'q'} meant to represent?

[Edited by - popcorn on April 28, 2006 9:26:20 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement