Console game

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
zeid
Chaos Rift Junior
Chaos Rift Junior
Posts: 201
Joined: Fri Apr 24, 2009 11:58 pm

Re: Console game

Post 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
Last edited by zeid on Mon Oct 26, 2009 1:13 pm, edited 2 times in total.
Axolotl Pop!
Image
Or, try it for free.

For many more free games online visit www.sam-zeid.com
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Console game

Post 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;
} 
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
ultimatedragoon69
Chaos Rift Regular
Chaos Rift Regular
Posts: 122
Joined: Tue Oct 28, 2008 1:57 pm
Current Project: Pangea's quest (text ~tile~ based rpg)
Favorite Gaming Platforms: Dreamcast, PC, playstation 1, Virtual Boy, Snes
Programming Language of Choice: c++
Contact:

Re: Console game

Post by ultimatedragoon69 »

interesting, guess ill have to dig in the windows api for a bit. thank you.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Console game

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
andrew
Chaos Rift Regular
Chaos Rift Regular
Posts: 121
Joined: Mon Dec 08, 2008 2:12 pm

Re: Console game

Post 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.
Post Reply