Hi guys:
I just started my text based game programming today i tried some of my basic skill on it, i programmed this very simple text program that simply consists of a character moving around the Command prompt screen with support of very Simple collision detection when it hits the walls.
MY PROBLEM is that i programmed it so that when i hit either (a,w,s,d) keys the whole output buffer is cleared and a new updated one is created and displayed on the screen, you can feel the flashing screen during each operation, i wondered is there any solution for such glitching?? is there any function to overcome this problem ?? cause i just watched some videos on youtube some guys programmed their own text based games and it just works fine for them!!!
Code:
#include <stdio.h>
#include <conio.h>
#include <windows.h>
int main ()
{
void wall(int *, int *);
char ch;
int x , y ;
x = 5;
y = 40;
wall(&x , &y);
ch = getch();
while (1)
{
switch (ch)
{
case 'w':
case 'W':
if (x > 1)
x--;
break;
case 'a':
case 'A':
if (y > 1)
y--;
break;
case 's':
case 'S':
if (x < 10)
x++;
break;
case 'd':
case 'D':
if (y < 78)
y++;
break ;
}
system("cls");
wall(&x ,&y);
ch = getch();
}
getch();
return 0;
}
void wall (int *x, int *y )
{
int i;
int j;
for (i = 1; i <= 80 ; i++)
printf("X");
for ( i = 1; i <= 10 ; i++)
{
printf("X");
for (j = 1; j <= 78; j++)
{
if (i == *x && j == *y)
{
printf("G");
continue;
}
printf(" ");
}
printf ("X");
}
for (i = 1; i <= 80 ; i++)
printf("X");
}
Note: Iam using Bloodshed DEV-C++ compiler