Add to Favorites    Make Home Page 1257 Online  
 Language Categories  
 Our Services  

Home » C Home » Games and Graphics Home » Oil Spill Game in C.

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Oil Spill Game in C.
Author Pabolu Kalyan Srinivas
Author Email mail_to_kalyan_mca [at] yahoo.com
Description You have to collect the oil drops falling from tubes. if you lost to catch drops you will lose a life for every collection your score will increased have fun.
Category C » Games and Graphics
Hits 369883
Code Select and Copy the Code
/* OIL SPIL GAME DEVELOPED BY P.KALYAN SRINIVAS*/ #include<graphics.h> #include<stdio.h> #include<stdlib.h> #include<time.h> #include<dos.h> #define L 75 #define R 77 /* variable initialisations */ union REGS i,o; int ch1,ch2; int mx,my,vx=270,vy; int temp,retval; char s[20],s1[20]; char ch; int gd=DETECT,gm; int x,y=400,r,c=7,score=0,lifes=4,flag=0,dlyfactor=0; /* main function */ main() { initialise(); firstscreen(); displaylifes(); displayscore(); welcome(); while(1) { condition1(); display_drop(); is_keyhit(); check_catchdrop(); check_looselife(); } nosound(); } /* sub functions */ initialise() { initgraph(&gd,&gm,""); mx=getmaxx();my=getmaxy(); setcolor(4); x=mx/2; image(x,y,c); vy=20; } firstscreen() { button3d(100,0,430,5); button3d(100,0,5,450); button3d(100,450,430,5); button3d(525,0,5,455); setfillstyle(1,7); bar(270,5,275,10); bar(320,5,325,10); bar(370,5,375,10); setfillstyle(1,8); bar(267,10,278,15); bar(317,10,328,15); bar(367,10,378,15); button3d(280,448,80,9); setcolor(4); outtextxy(290,450,"OIL SPIL"); } welcome() { setfillstyle(1,0); bar(200,250,450,350); clk_but3d(200,250,250,100); settextstyle(0,0,2); setcolor(4); outtextxy(240,280," WELCOME"); outtextxy(215,310, " TO OILSPIL"); getch(); setfillstyle(1,0); bar(200,250,453,353); return; } is_keyhit() { if(kbhit()) { i.h.ah=0; int86(22,&i,&o); if(o.h.ah==1) { nosound();closegraph();exit(0); } if(o.h.ah==75) { sound(1800);image(x,y,0);x=x-10;image(x,y,c);nosound(); } if(o.h.ah==77) { sound(1800);image(x,y,0);x=x+10;image(x,y,c);nosound(); } if(o.h.ah==80) { dlyfactor+=250; } if(o.h.ah==72) { dlyfactor-=250; } } } image(int x,int y,int c) { int b; setcolor(c); rectangle(x-10,y+6,x+10,y+20); setcolor(0); line(x-9,y+6,x+9,y+6); setfillstyle(1,c); bar(x-9,y+6,x+9,y+19); setfillstyle(1,0); bar(x-6,y+6,x+6,y+19); setcolor(c); for(b=1;b<=6;b++) line(x-10+b,y+19+b,x+10-b,y+19+b); setfillstyle(1,c); bar(x-1,y+19+b,x+1,y+25+b); fillellipse(x,y+25+b+3,8,3); } object(int x,int y,int c) { setcolor(c); setfillstyle(1,c); fillellipse(x,y+5,4,8); } condition1() { if(flag==1||vy>410) { vy = 20; temp = random(3); if(temp==0) vx=270; else if(temp==1) vx=320; else if(temp==2) vx =370; flag=0; } } check_looselife() { if(lifes==0) { setfillstyle(1,0); bar(200,250,450,350); clk_but3d(200,250,250,100); settextstyle(0,0,2); setcolor(1); outtextxy(240,290,"GAME OVER"); getch(); closegraph(); play_again(); exit(0); } } display_drop() { object(vx,vy,8); delay(3000+dlyfactor); object(vx,vy,0); vy+=10; } check_catchdrop() { if((x-5<=vx)&&(vx<=x+5)&&vy==410) displayscore(); else if(vy>410) displaylifes(); nosound(); } displaylifes() { settextstyle(0,0,1); clk_but3d(0,440,90,13); setcolor(7); outtextxy(5,445,s1); lifes = lifes -1; sprintf(s1,"LIFES = %d", lifes); setcolor(4); outtextxy(5,445,s1); flag=0; } displayscore() { settextstyle(0,0,1); clk_but3d(540,440,90,13); setcolor(7); outtextxy(545,445,s); score=score+1; sprintf(s,"SCORE = %d",score); setcolor(4); outtextxy(545,445,s); flag=1; vy=20; } button3d(int x,int y,int l,int w) { setcolor(LIGHTGRAY); setfillstyle(1,LIGHTGRAY); bar(x,y,x+l,y+w); setcolor(WHITE); line(x,y,x+l,y); line(x,y,x,y+w); setcolor(DARKGRAY); line(x+l+1,y,x+l+1,y+w+1); line(x,y+w+1,x+l+1,y+w+1); } clk_but3d(int x,int y,int l,int w) { setcolor(LIGHTGRAY); setfillstyle(1,LIGHTGRAY); bar(x,y,x+l,y+w); setcolor(DARKGRAY); line(x,y,x+l,y); line(x,y,x,y+w); setcolor(WHITE); line(x+l+1,y,x+l+1,y+w+1); line(x,y+w+1,x+l+1,y+w+1); } letter(int x,int y,int l,int w) { char s[1]; int ch=3; setcolor(RED); sprintf(s,"%c",ch); outtextxy(x + l/4 + 2,y + w/5, s); } restore_defaults() { y=400;c=7;score=0;lifes=4;flag=0;dlyfactor=0; } play_again() { printf("To Play again Press 'y'"); if(getch()=='y') { restore_defaults(); main(); } else printf(" Thanks for Playing this game. Bye Kalyan "); }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi ¦Õ¤ ?¤Ð Ãß??ÝÐÝ
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=487


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review