Thread: Help me in c graphics basic!!

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    5

    Help me in c graphics basic!!

    Actually , i am making a game in C using graphics.h
    game have 2 parts ie. a bucket which is at the bottom which will accept balls coming from the top of screen!!

    So game is ball in bucket!
    if the co-ordinates of ball lies inside the bucket it means that ball has fallen into the bucket.

    Else not!!

    I have given 2 option for bucket that is, A and D to shift the bucket on x axis!!
    My problem starts here:http://im.cprogramming.com/images/smilies/mad.png

    In main i have 2 fuctions ie.
    position()- which accepts ch=getch() value and checks that is it A or D and move the bucket accordingly!!
    And randomizer ()- which can randomly makes circle at random x and y increasing (falling from top).

    My problem is how can i achieve that if user doesn't press anything in during ch=getch() then after 1 sec my next line(fuction) of randomizer() will execute!!

    I hope you got it!!!
    http://im.cprogramming.com/images/smilies/confused.png






  2. #2
    Registered User
    Join Date
    Nov 2013
    Posts
    5
    Please help me!!

  3. #3
    Registered User
    Join Date
    Nov 2013
    Posts
    5
    My source code!!!
    Code:
    #include <stdio.h>
      #include <conio.h>
      #include <graphics.h>
      #include <dos.h>
      #include<stdlib.h>
    
    
      int i, maxx, midy;
    	int k=160,ch,l=-160,z;
    	int ran_pos_x,ran_pos_y,ran_rad;
    
    
      void randomizer()
      {
    	randomize();
    	ran_pos_x=random(random(random(maxx)));
    	ran_pos_y=30;
    	ran_rad=5;
    	circle(ran_pos_x,ran_pos_y,ran_rad);
    
    
    	for(z=0;z<650;z++)
    	{
    
    
    	   circle(ran_pos_x,ran_pos_y+z,ran_rad);
    	   delay(10);
    	   cleardevice();
    	}
      }
      void direction(int ch)
      {
          /*	if(ch==119)
    		{
    			cleardevice();
    			setcolor(YELLOW);
    			setfillstyle(SOLID_FILL, YELLOW);
    			line((maxx/2+l),midy+k,(maxx/2+l),(midy+30+k));
    			line((maxx/2+l),(midy+30+k),((maxx/2)+100+l),(midy+30+k));
    			line(((maxx/2)+100+l),(midy+30+k),((maxx/2)+100+l),midy+k);
    			line((maxx/2+l),midy+k,((maxx/2)+100+l),midy+k);
    
    
    			k=k-2;
    		}
    		else if(ch==115)
    		{
    			cleardevice();
    			setcolor(YELLOW);
    			setfillstyle(SOLID_FILL, YELLOW);
    			line((maxx/2+l),midy+k,(maxx/2+l),(midy+30+k));
    			line((maxx/2+l),(midy+30+k),((maxx/2)+100+l),(midy+30+k));
    			line(((maxx/2)+100+l),(midy+30+k),((maxx/2)+100+l),midy+k);
    			line((maxx/2+l),midy+k,((maxx/2)+100+l),midy+k);
    			k=k+2;
    		}       */
    		 if(ch==97)
    		{
    
    
    			cleardevice();
    			setcolor(YELLOW);
    			setfillstyle(SOLID_FILL, YELLOW);
    			line((maxx/2+l),(midy+k-1),(maxx/2+l),(midy+30+k-1));
    			line((maxx/2+l-1),midy+k,(maxx/2+l-1),(midy+30+k));
    			line((maxx/2+l),midy+k+3,(maxx/2+l),(midy+30+k)+3);
    			line((maxx/2+l),(midy+30+k),((maxx/2)+100+l),(midy+30+k));
    			line((maxx/2+l),(midy+30+k+1),((maxx/2)+100+l),(midy+30+k+1));
    			line((maxx/2+l),(midy+30+k+2),((maxx/2)+100+l),(midy+30+k+2));
    			line(((maxx/2)+100+l),(midy+30+k),((maxx/2)+100+l),midy+k);
    			line(((maxx/2)+100+l+1),(midy+30+k),((maxx/2)+100+l+1),midy+k);
    			line(((maxx/2)+100+l+2),(midy+30+k),((maxx/2)+100+l+2),midy+k);
    			 setcolor(WHITE);
    			line(0, midy + 200 , maxx, midy + 200);
    			gotoxy(maxx-20,midy+210);
    			printf("\nSCORE :  000");
    		      // line((maxx/2+l),midy+k,((maxx/2)+100+l),midy+k);
    			l=l-5;
    		}
    		else if(ch==100)
    		{
    
    
    			cleardevice();
    			setcolor(YELLOW);
    			setfillstyle(SOLID_FILL, YELLOW);
    			line((maxx/2+l),(midy+k-1),(maxx/2+l),(midy+30+k-1));
    			line((maxx/2+l-1),midy+k,(maxx/2+l-1),(midy+30+k));
    			line((maxx/2+l),midy+k+3,(maxx/2+l),(midy+30+k)+3);
    			line((maxx/2+l),(midy+30+k),((maxx/2)+100+l),(midy+30+k));
    			line((maxx/2+l),(midy+30+k+1),((maxx/2)+100+l),(midy+30+k+1));
    			line((maxx/2+l),(midy+30+k+2),((maxx/2)+100+l),(midy+30+k+2));
    			line(((maxx/2)+100+l),(midy+30+k),((maxx/2)+100+l),midy+k);
    			line(((maxx/2)+100+l+1),(midy+30+k),((maxx/2)+100+l+1),midy+k);
    			line(((maxx/2)+100+l+2),(midy+30+k),((maxx/2)+100+l+2),midy+k);
    			 setcolor(WHITE);
    			line(0, midy + 200, maxx, midy + 200);
    			gotoxy(maxx-20,midy+210);
    			printf("\nSCORE :  000");
    		       //	line((maxx/2+l),midy+k,((maxx/2)+100+l),midy+k);
    
    
    			l=l+5;
    		}
      }
    
    
      int main() {
    	/* request auto detection */
    	int gdriver = DETECT, gmode, err;
    
    
    	/* initialize graphic mode */
    	initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");
    	err = graphresult();
    
    
    	if (err != grOk) {
    		/* error occurred */
    		printf("Graphics Error: %s\n",
    				grapherrormsg(err));
    		return 0;
    	}
    
    
    	/* max position in x-axis */
    	maxx = getmaxx();
    	/* mid position in y-axis */
    	midy = getmaxy() / 2;
    
    
    		 /* clears the graphic screen */
    
    
    		do
    		{
    
    
    		ch=getch();
    		if(ch==27)
    		{
    			exit(0);
    		}
    	      //	randomizer();
    		direction(ch);
    
    
    
    
    		}while(ch!=27);
    	getch();
    
    
    	/* deallocate memory allocated for graphic screen */
    	closegraph();
    
    
      }

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    My suggestion is to use OpenGL or Direct3D 11. Do not use that outdated (even before it was released) graphics.h. I am surprised that even works at all on newer hardware.

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Please stop screaming at me!!! Exclaiming everything is rude!!! RRAAAGE

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with basic graphics
    By cico in forum Linux Programming
    Replies: 5
    Last Post: 02-21-2012, 10:33 AM
  2. Basic PC graphics
    By A34Chris in forum Game Programming
    Replies: 18
    Last Post: 11-09-2011, 02:25 PM
  3. Basic Graphics in C++
    By JCML in forum C++ Programming
    Replies: 1
    Last Post: 09-28-2010, 06:32 PM
  4. Best way of drawing basic graphics
    By Jelte in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2010, 05:15 PM
  5. Basic Graphics Libraries (C)
    By mkylman in forum Game Programming
    Replies: 15
    Last Post: 02-17-2010, 10:06 PM