Home   Easy-Code    Forum  Updater 
Twitter Facebook



Game using c graphics

Critics Rating:

Users Rating:

          /* GAME */



#include <stdio.h>

#include <conio.h>

#include <graphics.h>

#include <alloc.h>

#include <stdlib.h>

void main()

{

   int x,y,rx,ry,z,i,gd=DETECT,gm,score=0,ss,dd,lives,temp=1,errorcode,p;

   char *s,*d,*k,*kb,ans;

   initgraph(&gd,&gm,"");

   errorcode=graphresult();

   if (errorcode != grOk)

   {

      printf("Graphics error : %s\n",grapherrormsg(errorcode));

      printf("Press any key to halt");

      getch();

      exit(1);

   }

   outtextxy(200,110,"");

   ss=imagesize(195,106,215,130);

   s=malloc(ss);

   getimage(195,106,215,130,s);

   cleardevice();

   lives=5;

   for(p=1;p<=30;p++)

   {

      circle(getmaxx()/2,70,1*p);

      circle(getmaxx()/2,400,1*p);

      rectangle(90-2*p,200-2*p,570+2*p,260+2*p);

      settextstyle(3,0,5);

      outtextxy(100,200,"Press any key to start");

   }

   getch();

   k:x=126;y=279;z=0;

   cleardevice();

   rectangle(80,98,356,404);

   rectangle(82,100,358,406);

   f:do

   {

      z++;

      if ((x<326)&&(kb==75))

      {

         x--;

      }

      if (x<85)

      {

         goto g;

      }

      if ((x>90)&&(kb==77))

      {

         x++;

      }

      if (x>326)

      {

         goto g;

      }

      if ((y<379)&&(kb==72))

      {

         y--;

      }

      if (y<101)

      {

         goto g;

      }

      if((y>105)&&(kb==80))

      {

         y++;

      }

      if (y>379)

      {

         goto g;

      }

      if((x-rx<=5)&&(x-rx>-5)&&(y-ry<=5)&&(y-ry>-5))

      {

         temp=score;

         score=score+10;

      }

      if (score!=temp)

      {

         rx=random(400);ry=random(530);

         if ((rx<120)||(rx>320))

         {

            rx=-2;ry=-2;

         }

         if ((ry<110)||(ry>370))

         {

            rx=-2;

            ry=-2;

         }

      }

      putimage(x,y,s,0);delay(3);

      gotoxy(15,4);printf("Press any Arrow Key to Start");

      gotoxy(55,10);printf("Score = %d",score);

      gotoxy(55,13);printf("Lifes = %d",lives);

      gotoxy(55,16);printf("Press ESC to Quit");

      gotoxy(55,19);printf("Use Arrow Keys to move");

      if (z==100)

      {

         settextstyle(3,0,1);outtextxy(rx,ry,"");

         sound(z*400);delay(6);nosound();z=0;

      }

   }

   while(!kbhit());

   kb=getch();

   if (kb==77)

   {

      x=x+1;

      if(x>328)

      {

         goto g;

      }

   }

   if (kb==75)

   {

      x=x-1;

      if(x<85)

      {

         goto g;

      }

   }

   if (kb==80)

   {

      y=y+1;

      if(y>379)

      {

         goto g;

      }

   }

   if (kb==72)

   {

      y=y-1;

      if(y<101)

      {

         goto g;

      }

   }

   if (kb==27)

   {

      exit(1);

   }

   else

   {

      goto f;

   }

   g:cleardevice();

   sound(140);delay(350);nosound();

   settextstyle(3,0,4);

   outtextxy(200,180,"You lost one life");

   getch();

   lives=lives-1;

   if(lives>0)

   {

      goto k;

   }

   else

   cleardevice();

   settextstyle(3,0,4);

   outtextxy(200,200,"Game Over");

   getch();

   getch();

   {

      closegraph();

      outtextxy(200,200,"Do you want to Continue(Y/N)");

      read(ans);

      if (ans="N")

      {

         exit(1);

      }

   }

}



Courtesy, Source, References & Regards: Kishore AVGK

While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright@2009-2011 by KuGuNi.com. All Rights Reserved.