#include <graphics.
h>
#include <conio.h>
#include <dos.h> // For delay()
// Function to draw the road
void drawRoad() {
setcolor(WHITE);
setfillstyle(SOLID_FILL, DARKGRAY);
rectangle(0, 400, getmaxx(), getmaxy());
floodfill(1, 401, WHITE);
// Road lines
setcolor(WHITE);
for (int i = 0; i < getmaxx(); i += 80) {
rectangle(i, 470, i + 40, 475);
}
}
// Function to draw buildings (cityscape)
void drawBuildings() {
setcolor(LIGHTBLUE);
setfillstyle(SOLID_FILL, LIGHTBLUE);
// Building 1
rectangle(50, 100, 120, 300);
floodfill(51, 101, LIGHTBLUE);
// Building 2
rectangle(170, 50, 240, 300);
floodfill(171, 51, LIGHTBLUE);
// Building 3
rectangle(290, 150, 360, 300);
floodfill(291, 151, LIGHTBLUE);
// Building 4
rectangle(410, 80, 500, 300);
floodfill(411, 81, LIGHTBLUE);
}
// Function to draw the auto rickshaw at a given (x, y)
void drawAutoRickshaw(int x, int y) {
// Body
setcolor(YELLOW);
setfillstyle(SOLID_FILL, YELLOW);
rectangle(x, y, x + 100, y + 50);
floodfill(x + 1, y + 1, YELLOW);
// Roof
setcolor(GREEN);
setfillstyle(SOLID_FILL, GREEN);
rectangle(x + 10, y - 30, x + 90, y);
floodfill(x + 11, y - 29, GREEN);
// Front cover
setcolor(GREEN);
setfillstyle(SOLID_FILL, GREEN);
rectangle(x + 90, y - 10, x + 120, y + 40);
floodfill(x + 91, y - 9, GREEN);
// Wheels
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
circle(x + 20, y + 60, 10);
floodfill(x + 20, y + 60, BLACK);
circle(x + 80, y + 60, 10);
floodfill(x + 80, y + 60, BLACK);
circle(x + 110, y + 50, 8);
floodfill(x + 110, y + 50, BLACK);
}
int main() {
int gd = DETECT, gm;
int x = 0; // starting x position
int y = 400; // base y position for road level
initgraph(&gd, &gm, "c:\\TurboC3\\BGI");
while (!kbhit()) { // keep moving until a key is pressed
cleardevice(); // clear screen
drawRoad(); // Draw static road
drawBuildings(); // Draw static buildings
drawAutoRickshaw(x, y - 100); // Draw auto rickshaw
delay(50); // slow down movement
x += 5; // move right
if (x > getmaxx()) {
x = -150; // Reset to start once offscreen
}
}
getch();
closegraph();
return 0;
}