Page 2 of 2

Re: Console game

Posted: Mon Oct 26, 2009 11:54 am
by zeid
Well to remove the flickering I had to include windows.h

and here is the code related;

Code: Select all

LockWindowUpdate(GetConsoleWindow()); //disables drawing in the command console (freezing it so that you don't see the clearing of the screen)
system("cls");//Clear the console
//Do all your drawing/rendering/text
LockWindowUpdate(NULL);//re-enables drawing in the command console

Re: Console game

Posted: Mon Oct 26, 2009 12:19 pm
by avansc
dug through old stuff. i think i found this on the web at some time.
should be relativly fast as it uses a buffer.

this is just an example that makes a yellow X move in a circle on in the console. 100FPS.

as you will note this is limited to windows.

Code: Select all

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <math.h>

#define SCREEN_WIDTH 80
#define SCREEN_HEIGHT 25

int main( void )
{
	int x = 20;
	int y = 10;
	float ang = 0;
	float rad = 6;

	HANDLE hOutput = (HANDLE)GetStdHandle( STD_OUTPUT_HANDLE );
	COORD dwBufferSize = { SCREEN_WIDTH,SCREEN_HEIGHT };
	COORD dwBufferCoord = { 0, 0 };
	SMALL_RECT rcRegion = { 0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1 };

	CHAR_INFO buffer[SCREEN_HEIGHT][SCREEN_WIDTH];

	ReadConsoleOutput( hOutput, (CHAR_INFO *)buffer, dwBufferSize,
	dwBufferCoord, &rcRegion );

	while(1)
	{
		ang += 0.1;
		buffer[y+(int)(rad*sin(ang))][x+(int)(rad*cos(ang))].Char.AsciiChar = 'X';
		buffer[y+(int)(rad*sin(ang))][x+(int)(rad*cos(ang))].Attributes = 0x0E;
		WriteConsoleOutput( hOutput, (CHAR_INFO *)buffer, dwBufferSize,dwBufferCoord, &rcRegion );
		Sleep(10);

		buffer[y+(int)(rad*sin(ang))][x+(int)(rad*cos(ang))].Char.AsciiChar = ' ';
		WriteConsoleOutput( hOutput, (CHAR_INFO *)buffer, dwBufferSize,dwBufferCoord, &rcRegion );
	}

	return 0;
} 

Re: Console game

Posted: Mon Oct 26, 2009 12:48 pm
by ultimatedragoon69
interesting, guess ill have to dig in the windows api for a bit. thank you.

Re: Console game

Posted: Mon Oct 26, 2009 8:23 pm
by dandymcgee
avansc wrote:
yeah its quite impressive. i wouldn't be surprised tho if all it was is an actual 3d demo that was just converted to ascii art.
I'm pretty sure it is, there are textures in the folder that come with it. It's still a pretty good conversion and rendering engine though.

Re: Console game

Posted: Mon Oct 26, 2009 8:50 pm
by andrew
dandymcgee wrote:
avansc wrote:
yeah its quite impressive. i wouldn't be surprised tho if all it was is an actual 3d demo that was just converted to ascii art.
I'm pretty sure it is, there are textures in the folder that come with it. It's still a pretty good conversion and rendering engine though.
Yes, he is just converting it to ascii. If you are interested his notes are here.