Car Movement

On October 7, 2008, in Animation, Drawing, by , Views : 7055


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
 
int scan, ascii;
 
void getkey()
{
    union REGS ii, oo;
    ii.h.ah = 0;
    int86(22, &ii, &oo);
    scan = oo.h.ah;
    ascii = oo.h.al;
}
 
void car(int x, int c)
{
    setcolor(c);
    line(x + 150, 100, x + 242, 100);
    ellipse(x + 242, 105, 0, 90, 10, 5);
    line(x + 150, 100, x + 120, 150);
    line(x + 252, 105, x + 280, 150);
    line(x + 100, 150, x + 320, 150);
    line(x + 100, 150, x + 100, 200);
    line(x + 320, 150, x + 320, 200);
    line(x + 100, 200, x + 110, 200);
    line(x + 320, 200, x + 310, 200);
    arc(x + 130, 200, 0, 180, 20);
    arc(x + 290, 200, 0, 180, 20);
    line(x + 270, 200, x + 150, 200);
    circle(x + 130, 200, 17);
    circle(x + 290, 200, 17);
 
}
 
void main()
{
    int gd = DETECT, gm = DETECT, i = 0, c = 1, prev = 80;
    initgraph(&gd, &gm, "");
 
    cleardevice();
 
    car(0, 15);
 
    while (!kbhit());
 
    while (1) {
	getkey();
	if (scan == 72) {
	    c++;
	    scan = prev;
	}
 
	if (scan == 80) {
	    if (c != 1)
		c--;
	    scan = prev;
	}
 
	if (ascii == 13)
	    break;
	if (scan == 77) {
	    prev = 77;
	    while (!kbhit()) {
		car(i, 0);
		i += c;
		car(i, 15);
		delay(20);
	    }
	}
	if (scan == 75) {
	    prev = 75;
	    while (!kbhit()) {
		car(i, 0);
		i -= c;
		car(i, 15);
		delay(20);
	    }
 
 
	}
	if (ascii == 32) {
	    prev = 80;
	    car(i, 15);
	    while (!kbhit());
	}
    }
 
    getch();
}

Hope, it helps! 🙂



Leave a Reply

Your email address will not be published. Required fields are marked *


*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

  • Dipin Krishna

Archives

All entries, chronologically...

Read more:
CIRCLE
Draw a Circle using Bresenham’s Circle Algorithm

man_rain
A man walking with umbrella in the rain.

Car
Car movement during Traffic Signal

MinMaxClose