In c there is limited feature of graphics but, you can build the fighter plane in C and give it wing to fly.
For creating the fighter plane it’s the game of line and getimage and putimage.
Code–
#include<stdio.h> #include<graphics.h> #include<alloc.h> #include<conio.h> int stx=150; int sty=100; int x1,y1,x2,y2; int x[25]={0,10,30,27,52,58,56,94,109,115,115,110,100,80,80,60,130,130,125,140,70,100,105}; int y[25]={0,-3,6,-8,-16,-13,-8,-5,-25,-25,-5,-2,-1,3, 5 , 8, 5 ,-21,-21,15,16,16,12}; int SIGN=1; void drawplane(); void plainsize(int size); void plainsize(int size) { int i; for(i=1;i<23;i++) { x[i]=x[i]*size/10; y[i]=y[i]*size/10; } } void drawplane() { line(stx,sty,stx+x[1],sty+y[1]); line(stx+x[1]*SIGN,sty+y[1],stx+x[2]*SIGN,sty+y[2]); line(stx+x[2]*SIGN,sty+y[2],stx+x[3]*SIGN,sty+y[3]); line(stx+x[1]*SIGN,sty+y[1],stx+x[3]*SIGN,sty+y[3]); line(stx+x[3]*SIGN,sty+y[3],stx+x[4]*SIGN,sty+y[4]); line(stx+x[4]*SIGN,sty+y[4],stx+x[5]*SIGN,sty+y[5]); line(stx+x[5]*SIGN,sty+y[5],stx+x[6]*SIGN,sty+y[6]); line(stx+x[3]*SIGN,sty+y[3],stx+x[6]*SIGN,sty+y[6]); line(stx+x[5]*SIGN,sty+y[5],stx+x[7]*SIGN,sty+y[7]); line(stx+x[7]*SIGN,sty+y[7],stx+x[8]*SIGN,sty+y[8]); line(stx+x[8]*SIGN,sty+y[8],stx+x[9]*SIGN,sty+y[9]); line(stx+x[9]*SIGN,sty+y[9],stx+x[10]*SIGN,sty+y[10]); line(stx+x[10]*SIGN,sty+y[10],stx+x[11]*SIGN,sty+y[11]); line(stx+x[11]*SIGN,sty+y[11],stx+x[12]*SIGN,sty+y[12]); line(stx+x[12]*SIGN,sty+y[12],stx+x[13]*SIGN,sty+y[13]); line(stx+x[7]*SIGN,sty+y[7],stx+x[12]*SIGN,sty+y[12]); line(stx+x[13]*SIGN,sty+y[13],stx+x[14]*SIGN,sty+y[14]); line(stx+x[15]*SIGN,sty+y[15],stx+x[16]*SIGN,sty+y[16]); line(stx+x[2]*SIGN,sty+y[2],stx+x[15]*SIGN,sty+y[15]); line(stx+x[16]*SIGN,sty+y[16],stx+x[17]*SIGN,sty+y[17]); line(stx+x[17]*SIGN,sty+y[17],stx+x[18]*SIGN,sty+y[18]); line(stx+x[10]*SIGN,sty+y[10],stx+x[18]*SIGN,sty+y[18]); line(stx+x[16]*SIGN,sty+y[16],stx+x[19]*SIGN,sty+y[19]); line(stx+x[14]*SIGN,sty+y[14],stx+x[19]*SIGN,sty+y[19]); line(stx+x[15]*SIGN,sty+y[15],stx+x[20]*SIGN,sty+y[20]); line(stx+x[20]*SIGN,sty+y[20],stx+x[21]*SIGN,sty+y[21]); line(stx+x[22]*SIGN,sty+y[22],stx+x[21]*SIGN,sty+y[21]); setcolor(WHITE); //for proper visible x2=stx+x[19]*SIGN; y2=sty+y[19]; } int main(void) { void *area; int size=20; int s,x,y,gd=DETECT,gm,r; initgraph(&gd,&gm,"f:\tc"); setcolor(RED); plainsize(5); drawplane(); setbkcolor(RED); //line(10,100,500,100); s=imagesize(stx,sty,x2,y2); area=(void*)malloc(s); getimage(stx,sty,x2,y2,area); putimage(stx,sty,area,XOR_PUT); while(!kbhit()) { //setcolor(10); putimage(stx,sty,area,XOR_PUT); line(10,100,500,100); drawplane(); delay(100); line(10,100,500,100); putimage(stx,sty,area,XOR_PUT); setcolor(0); //it make my palne in visble drawplane(); r=rand(); switch(r%4) { case 0:stx=stx+10; break; case 1:stx=stx-10; break; case 2:sty=sty+10; break; case 3:sty=sty-10;break; } if(stx>640) stx-=40; if(stx<40) stx+=40; if(sty>479) sty-=40; if(sty<40) sty+=40; } getch(); closegraph(); return 0; }
Description:
For graphics in c, remember this thing:
1. Include “graphic.h” header file.
2. Declare the two integer type variables gd,gm,
3. Declare the function initgraph(&gd,&gm,”c:\tc\bgi”) in main().