Code:
/*ASCII robot animation */
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <windows.h>
#define VMAX 3
#define HMAX 3
void printRobot(char robot[][3],int x, int y);
void fillIn(int x,int y);
int main(void) {
int i,x,y;
clock_t pause = 15;
//clock_t timerNew,timerOld;
char robot[VMAX][HMAX]={
{'.','o','.'},
{'-','¦','-'},
{'/',' ','\\'}
};
printf("Say I want this 'robot', to get animated, but slow down as he travels\n\n");
for(i=0;i<304;i++)
printf("%c%c%c%c%c",'.','.','.','.','.');
x=2;y=6;
for(i=0;i<108;i++) {
_gotoxy(x,y);
printRobot(robot,x,y);
Sleep(pause);
fillIn(x,y);
x+=1;
if(x>75){
x=2;
y+=VMAX;
}
if(i>95) {
++y;
pause+=4;
}
pause+=3;
}
x+=10; y+=VMAX;
_gotoxy(x,y);
printRobot(robot,x,y);
_gotoxy(1,23);
printf("\n");
return 0;
}
void printRobot(char robot[][3],int x, int y) {
int r,c;
for(c=0,r=2;c<HMAX;c++)
printf("%c",robot[r][c]);
_gotoxy(x,y-1);
for(c=0,r=1;c<HMAX;c++)
printf("%c",robot[r][c]);
_gotoxy(x,y-2);
for(c=0,r=0;c<HMAX;c++)
printf("%c",robot[r][c]);
}
void fillIn(int x,int y) {
int i;
for(i=VMAX;i>-1;i--) {
_gotoxy(x,y-i);
printf("...");
}
}