Saturday, November 17, 2018

Moving Object on Screen


This program will move designed object (arrow sign "==>") on screen without use of <graphics.h> and system("cls") or clrscr() function.

#include <stdio.h>
#include <windows.h>

COORD c = {0, 0};
void setxy (int x, int y)
{
 c.X = x; c.Y = y; // Set X and Y coordinates
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}

int main() 

  int i;
  for(i=0; i<20; i++)
  {
    system("color A1");

    setxy(i, 5);
    printf("==>");

    setxy(i-3, 5); //For clearing previous position of arrow
    printf("   ");

    Sleep(200);
  }
  return 0;  
}

Output of Program

This program will move ==> sign on screen from Left side to Right side.


For more such interesting programs visit: C Program Practicals/Games

No comments:

Post a Comment