Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- C code to display the simple motion of a rocket
- Sandipan Dey
- BCSE, JU, Kolkata
- 2002
- */
- #include <stdio.h>
- #include <conio.h>
- #include <graphics.h>
- #include <stdlib.h>
- #include <string.h>
- #include <dos.h>
- #define INPUTFILE "rocket.bmp" // a rocket image
- #define MAX 256
- #define MAXF 500
- void Name() {
- rectangle(515,335,630,465);
- outtextxy(520,340,"SANDIPAN DEY");
- outtextxy(520,350,"BCSE-IV");
- outtextxy(520,360,"Roll-99710");
- line(515,370,630,370);
- outtextxy(520,375,"Press Keys:");
- line(515,388,630,388);
- outtextxy(520,395,"'->'-Speed Up");
- outtextxy(520,410,"'<-'- ,, Down");
- outtextxy(520,425,"'S'-Sound On");
- outtextxy(520,439,"'M'-Sound Off");
- outtextxy(520,455,"'X'-Exit");
- }
- void TwinkleStar(int c) {
- int x=random(300),y=random(480),c1=getmaxcolor();
- putpixel(x-1,y-1,c1);
- putpixel(x-1,y,c1);
- putpixel(x,y,c1);
- putpixel(x,y-1,c1);
- x=random(400)+300;y=random(480);
- putpixel(x-1,y-1,c1);
- putpixel(x-1,y,c1);
- putpixel(x,y,c1);
- putpixel(x,y-1,c1);
- for(int i=0;i<300;++i) {
- x=random(300);y=random(480);
- putpixel(x,y,c);
- putpixel(x+1,y+1,c);
- putpixel(x,y+1,c);
- }
- for(i=0;i<300;++i) {
- x=random(400)+300;y=random(480);
- putpixel(x,y,c);
- putpixel(x+1,y,c);
- putpixel(x+1,y+1,c);
- }
- }
- void Meteor(int c) {
- int x=random(320),y=random(480);
- for(int i=x,j=y;i>=0;--i,--j) {
- putpixel(i,j,getmaxcolor());
- putpixel(i-1,j-1,getmaxcolor());
- putpixel(i,j-1,getmaxcolor());
- putpixel(i-1,j,getmaxcolor());
- /////////////////////
- delay(1);
- putpixel(i+1,j+1,c);
- putpixel(i,j,c);
- putpixel(i+1,j,c);
- putpixel(i,j+1,c);
- }
- }
- void main(int argc,char* argv[]) {
- FILE* fp=NULL,*fo=NULL;
- void* bmp;
- int freq=0;
- if((fp=fopen(INPUTFILE,"rb"))==NULL)
- {printf("\n File Not Found!");fclose(fp);getch();exit(0);} // File Not Found
- long int imgoffset;
- if(fgetc(fp)!='B' || fgetc(fp)!='M') { // Check Signature
- printf("\n Not a valid BMP File!!!");
- fclose(fp);
- fclose(fo);
- getch();
- exit(0);
- }
- fseek(fp,10,0); // Find Offset of Data
- imgoffset=fgetc(fp)+(fgetc(fp)<<8)+(fgetc(fp)<<16)+(fgetc(fp)<<24); // Data Offset
- long int w,h;
- fseek(fp,18,0);
- w=fgetc(fp)+(fgetc(fp)<<8)+(fgetc(fp)<<16)+(fgetc(fp)<<24);
- h=fgetc(fp)+(fgetc(fp)<<8)+(fgetc(fp)<<16)+(fgetc(fp)<<24);
- int gd=VGA,gm=VGAHI,x=0,y=h,c;
- struct palettetype pal;
- //int gd=DETECT,gm,x=0,y=h,c;
- initgraph(&gd,&gm,"");
- getpalette(&pal);
- for (int i=0; i<16; i++)
- setrgbpalette(pal.colors[i],i*2,i*3,i*4);
- fseek(fp,imgoffset,0);
- while(!feof(fp)) {
- c=fgetc(fp);
- putpixel(x,y,c/16);
- x=(x+1)%w;
- if(!x){--y;}
- }
- fclose(fp);
- c=getpixel(64,86);
- Name();
- outtextxy(25,25,"PRESS ANY KEY TO START");
- getch();
- setcolor(c);
- outtextxy(25,25,"PRESS ANY KEY TO START");
- setcolor(getmaxcolor());
- int size=imagesize(300,315,330,439);
- bmp=malloc(size);
- getimage(300,315,330,439,bmp);
- x=300;y=315;
- setfillstyle(SOLID_FILL,c);
- int c1,c2,d=10,flag=0;
- randomize();
- do {
- if(c1==0 && c2==75){d+=10;if(freq<MAXF)++freq;}
- else if(c1==0 && c2==77){d-=10;if(freq>10)--freq;}
- if(d>=500)d=500;
- else if(d<=1)d=1;
- while(!kbhit()) {
- putimage(x,y,bmp,COPY_PUT);
- delay(d);
- y-=1;
- if(y<=-10) {
- y=350;bar(300,0,330,480);
- }
- TwinkleStar(c);
- //if(!(y%100))Meteor(c);
- if(flag) {
- if(freq<MAXF){
- ++freq;sound(freq);
- }
- }
- Name();
- }
- if ((c1=getch())==0){
- c2=getch();
- }
- else if(c1=='s' || c1=='S')flag=1;
- else if(c1=='m' || c1=='M'){
- flag=0;nosound();freq=0;
- }
- //fflush(stdin);
- }
- while(c1!='x' && c1!='X');
- closegraph();
- free(bmp);
- nosound();
- }
Add Comment
Please, Sign In to add comment