Help... robot flickering.. ASAP plz

//robot is flickering while moving



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

using namespace std;
void gotoxy(int, int); //Parameter of Ftn gotoxy()


void robot(int,int); //Parameter of Ftn robot()

void main()
{


HANDLE hOut; //screen handling in SetConsoleTextAttribute statement
hOut = GetStdHandle(STD_OUTPUT_HANDLE);

char array[25][80]={0};


for(char i=0;i<18;i++) //for blue background upto 18 row
{
for(char j=0;j<80;j++)
{
SetConsoleTextAttribute(hOut,BACKGROUND_BLUE | FOREGROUND_BLUE | BACKGROUND_INTENSITY);

cout<<char(array[i][j]=219);

}
}


for(char k=18; k<23; k++) //for green background from row 18 to 23
{
for(char l=0;l<80;l++)
{
SetConsoleTextAttribute(hOut,BACKGROUND_GREEN | FOREGROUND_GREEN | BACKGROUND_INTENSITY);
cout<<char(array[k][l]=219);



}
}

for(char m=23; m<25; m++) //for yellow background in last 2 rows

{
for(char n=0; n<80; n++)

{
SetConsoleTextAttribute(hOut,BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_INTENSITY);
cout<<char(array[m][n]=176);
}
}
//to change foreground colour back to white with green background

SetConsoleTextAttribute(hOut,FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE |FOREGROUND_INTENSITY |BACKGROUND_GREEN);
cout<<flush;

//for movement

int a=10;
int b=18;

int x=a;
while(1)

{
robot(x,b); //calling robot function

if (GetAsyncKeyState(VK_RIGHT) && x<72)
{
Sleep(400);
x++;
}

else if(GetAsyncKeyState(VK_LEFT) && x>0 )

{
Sleep(400);
x--;
}




} //end while



} //end main



//defining gotoxy() function

void gotoxy(int x,int y)
{

HANDLE console_handle;
COORD cursor_coord;
cursor_coord.X=x;
cursor_coord.Y=y;
console_handle=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(console_handle,cursor_coord);
}

//defining function of robot

void robot(int a,int b)
{

gotoxy(a,b);

cout<< char(0);
cout<< char (92) ;
cout<< char(0);

gotoxy(a+1,b);
cout<< char(0);
cout<< char(45);
cout<< char(0);

gotoxy(a+2,b);
cout<< char(0);
cout<< char (194);
cout<< char(0);

gotoxy(a+3,b);
cout<< char(0);
cout<< char(45);
cout<< char(0);

gotoxy(a+4,b);
cout<< char(0);
cout<< char(47);
cout<< char(0);

gotoxy(a+2,b+1);
cout<< char(0);
cout<< char(124);
cout<< char(0);

gotoxy(a+4,b+1);
cout<< char(0);
cout<< char(2);
cout<< char(0);

gotoxy(a+2,b+2);
cout<< char(0);
cout<< char(192);
cout<< char(0);

gotoxy(a+3,b+2);
cout<< char(0);
cout<< char(45);
cout<< char(0);

gotoxy(a+4,b+2);
cout<< char(0);
cout<< char(199);
cout<< char(0);

gotoxy(a+5,b+2);
cout<< char(0);
cout<< char(45);
cout<< char(0);

gotoxy(a+6,b+2);
cout<< char(0);
cout<< char(170);
cout<< char(0);

gotoxy(a+4,b+3);
cout<< char(0);
cout<< char(208);
cout<< char(0);

gotoxy(a+3,b+3);
cout<< char(0);
cout<< char(218);
cout<< char(0);

gotoxy(a+5,b+3);
cout<< char(0);
cout<< char(191);
cout<< char(0);

}

closed account (3qX21hU5)
First and foremost please use codetags whenever you post code on the forums. They are the <> box right off to the right under Format: when your replying.

But on to your question, I'm not really sure what you mean by robot is flickering while moving. But the main thing I see is thisvoid main() main is a int not a void. It should be int main() I don't know what IDE your using that doesn't put our a error for that but I would consider upgrading.
I don't know what IDE your using that doesn't put our a error for that but I would consider upgrading.

His IDE has nothing to do with the errors given by the compiler. It's his compiler that needs to be "upgraded", not his IDE.
Last edited on
closed account (3qX21hU5)
Yes that is true but for beginners the two usually go hand in hand so just thought I would say IDE since really all updated modern IDE's come with up to date compilers.
Topic archived. No new replies allowed.