My Game: Egg Catcher

Discussion in 'Game Programming' started by alok, Sep 27, 2004.

?

Do u like the Game

  1. Yes

    63.2%
  2. No

    5.3%
  3. Some What

    31.6%
Multiple votes are allowed.
  1. alok

    alok New Member

    Joined:
    Jul 24, 2004
    Messages:
    127
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    S/W Engg
    Home Page:
    http://www.thatsalok.com

    Introduction:



    Hi and welcome to my article, this article is a small game using graphics in c++(DOS Based).I programmed this game and all of the graphics design is imagined by my friend Amit Mehta.

    here is little description of game

    "This is a simple game for new programmers. It will help them to get a clear view of 2D Graphics The output is a game where the player catches eggs droped by a egg thrower and goes on to various levels "
    ---- By my Friend Amit
    Here i explain some of the class I created and some of my logic.

    Here is main Class that move the egg catcher using keyboard

    The Code



    Code:
    class EggCatcher
    {
    	int strx,stry,endx,endy; //coordinate of the moving box
    	void *buff;////for handlling the box image
    	short bool;
    	board *Board;
    	
    	void BackGround();
    	void DrawCatcher(int,int);
    public:
    	char Player[10];
    	
    	EggCatcher(int,int,board&);
    	void Start(int,int);
    	void End();
    	void CatcherMove(int);
    	void PreScreen();
    	void SayByeBye();
    	~EggCatcher()
    	{free(buff);
    	delete Board;
    	}
    };
    
    This is little function that read the keyboard input, I found this function in Mr. Yashwant Kanetkar book "let us C"

    Code:
    #define UP 72
    #define DOWN 80
    #define RIGHT 77
    #define LEFT 75
    #define ENTER 28
    #define END 28
    #define ESC 1
    
    int getscan()
    { 
    	REGS i,o;
    	//while(!kbhit());
    	i.h.ah=0;
    	int86(22,&i,&o);
    	return(o.h.ah);
    };
    
    This function will return current key state by return the ASCII value of it and using switch statement i can track the movement of direction keys and some special keys.

    Like thisà

    Code:
    switch(ch)
    {
    case RIGHT: Box.CatcherMove(ch);
    	break;
    case LEFT:Box.CatcherMove(ch);
    	break;
    case ESC:Box.SayByeBye();
    	Thrower1.EndGameProperties();
    	exit(0);
    }
    
    Now I have created special bitmap class of my own to display images

    Here it Class (it is defined and declared in second.cpp)

    Code:
    struct bitmap
    {
    	short bit[20][20];
    };
    class BITMAP
    {
        void *character;
    public:
    	// BITMAP();
    	void* DrawImage(bitmap &bit,int x,int y);
    };
    void* BITMAP::DrawImage(bitmap &bit,int x,int y)
    {
    	int i,j;
    	for(j=y;j<y+20;j++)
    	{
    		for(i=x;i<x+20;i++)
    		{
    			putpixel(i,j,bit.bit[j-y][i-x]);
    		}
    	}
    	int size=imagesize(x,y,x+20,y+20);
    	character=malloc(size);
    	getimage(x,y,x+20,y+20,character);
    	putimage(x,y,character,XOR_PUT);
    	return character;
    };
    
    here how to use it-à

    first create a bitmap bits using thisà
    Code:
    const short W=15;//white
    const short Y=14;//yellow
    const short S=10;
    const short E=11;
    bitmap Egg1=
                               {0,0,0,0,0,0,0,0,0,W,W,W,0,0,0,0,0,0,0,0,
                                0,0,0,0,0,0,0,0,W,W,W,W,W,0,0,0,0,0,0,0,
                                0,0,0,0,0,0,0,W,Y,Y,Y,Y,Y,W,0,0,0,0,0,0,
                                0,0,0,0,0,0,W,W,0,Y,Y,Y,Y,W,W,0,0,0,0,0,
                                0,0,0,0,0,W,W,0,Y,Y,Y,Y,Y,Y,W,W,0,0,0,0,
                                0,0,0,0,W,W,0,Y,Y,Y,Y,Y,Y,Y,Y,W,0,0,0,0,
                                0,0,0,0,W,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,W,0,0,0,0,
                                0,0,0,0,W,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,W,0,0,0,0,
                                0,0,0,0,W,Y,Y,Y,Y,Y,8,8,Y,Y,Y,W,0,0,0,0,
                                0,0,0,0,W,Y,Y,Y,Y,8,8,8,8,Y,Y,W,0,0,0,0,
                                0,0,0,0,W,Y,Y,Y,Y,8,8,8,8,Y,Y,W,0,0,0,0,
                                0,0,0,0,0,W,Y,Y,Y,8,8,8,8,Y,Y,W,0,0,0,0,
                                0,0,0,0,0,W,Y,Y,Y,Y,8,8,Y,Y,Y,W,0,0,0,0,
                                0,0,0,0,0,W,Y,Y,Y,Y,Y,Y,Y,Y,W,0,0,0,0,0,
                                0,0,0,0,0,0,W,Y,Y,Y,Y,Y,Y,W,0,0,0,0,0,0,
                                0,0,0,0,0,0,W,Y,Y,Y,Y,Y,W,0,0,0,0,0,0,0,
                                0,0,0,0,0,0,0,W,Y,Y,Y,W,0,0,0,0,0,0,0,0,
                                0,0,0,0,0,0,0,W,W,W,W,0,0,0,0,0,0,0,0,0,
                                0,0,0,0,0,0,0,0,W,W,0,0,0,0,0,0,0,0,0,0,
                                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    
    now in any part of function
    Code:
    void show
    {
    	BITMAP *bit;
    	void * eggbuff=bit.DrawImage(egg,40,40);
    	//and to show
    	putimage(x,y,eggbuff,XOR_PUT);
    }
    
    and this will show up the image of bitmap

    The Logic Behind It:-

    I am just using random function to generate the egg and at any given time all the egg move downward on the board matrix that is defined in start and if at end it found the catcher the score is incremented by one or you lose the chance.

    Let me explain it more, I have a board according to which graphics displayed on the screen if the board matrix element is 0 is doesn’t display anything, same case for egg and egg catcher

    Logic behind moving of eggs->every time thrower want to drop egg he put egg value in top of matrix, since every 100 msec the matrix is reviewed and screen is redrawn the egg can be shown on the screen, now for moving action each time top row is copied in it lower row and soon that and last row is discarded this is the logic of moving multiple egg in screen.

    Note--> due limitation of size i can't able to upload the Executable File.now you have to compile the same
     

    Attached Files:

  2. rai_gandalf

    rai_gandalf New Member

    Joined:
    Nov 4, 2005
    Messages:
    46
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Final Year Comp Engg
    Location:
    Mumbai
    Home Page:
    http://mindpuncture.blogspot.com
    Hello Alok, I am not very familiar with the BGI Graphics under windows or even advanced C, so please 4giv me for asking what may be really silly questions.

    Now, when I compile ur game : "eggcatcher", i.e. ur main.cpp,
    it shows an ERROR : "BGI Graphics Not Supported under Windows"
    What does this mean?? Does it mean that my compiler is not compatible or maybe, my Windows is not??

    Also, I tried the TicTacToe Game that Shabbir has posted (He used BGI Graphics) & that program is compiling & working fine.

    Please reply to my doubts.

    Ciao,
    Rajiv
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I havent used any BGI graphics. Its Drawn using the plain C without Graphics.
     
  4. alok

    alok New Member

    Joined:
    Jul 24, 2004
    Messages:
    127
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    S/W Engg
    Home Page:
    http://www.thatsalok.com
    BGI graphics is not supported by The Visual Studio Compilers... they are supported only by Good Old Turbo C++ 3.0 compiler/Studio.
     
  5. imrantechi

    imrantechi New Member

    Joined:
    Feb 12, 2008
    Messages:
    116
    Likes Received:
    4
    Trophy Points:
    0
    the game is a nice one ...............

    well done.....................
     
  6. lead.smart34

    lead.smart34 New Member

    Joined:
    Feb 14, 2008
    Messages:
    77
    Likes Received:
    0
    Trophy Points:
    0
  7. crazytolearn57

    crazytolearn57 New Member

    Joined:
    Feb 14, 2008
    Messages:
    48
    Likes Received:
    0
    Trophy Points:
    0
  8. XXxxImmortalxxXX

    XXxxImmortalxxXX New Member

    Joined:
    Jun 27, 2007
    Messages:
    561
    Likes Received:
    19
    Trophy Points:
    0
    shouldnt

    Code:
     int i,j;
        for(j=y;j<y+20;j++)
        {
            for(i=x;i<x+20;i++)
            {
                putpixel(i,j,bit.bit[j-y][i-x]);
            }
        }
    
    be

    Code:
     int i,j;
        for(x=y;j<y+20;j++)
        {
            for(y=x;i<x+20;i++)
            {
                putpixel(i,j,bit.bit[j-y][i-x]);
            }
        }
    
    ?
     
  9. skp819

    skp819 New Member

    Joined:
    Dec 8, 2008
    Messages:
    89
    Likes Received:
    3
    Trophy Points:
    0
    game is very nice..

    My friend is searching for the ebook on internet.
    but I and my friend fail to find the ebook on internet.
    can you tell me any ebook link to download ebook.
    or any online learning site.
    plz..........
     
  10. rockyrakster

    rockyrakster New Member

    Joined:
    Aug 21, 2009
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Chennai,India
    Good Program tommorow I will release my first game in this forum.It was my 12th project...
    I am new here.But once again I loved this idea
     
  11. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    814
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    It was ok. When there were two many eggs, the graphics didnt go smooth. My name was going out of the screen (either limit the number of lettters to be accepted or something). What i didnt like was that, movment wasn't smooth enough to enjoy the game, i don't know how you'll make it smooth coz i know its all on delays and clrscr() (i assume). Over all 3/5....
     
  12. shipra123

    shipra123 New Member

    Joined:
    Oct 13, 2009
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    can you please help what exactly is BGI Graphics?
     
  13. mani999

    mani999 New Member

    Joined:
    Aug 2, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    hi,


    It is a good program and i want to learn more about of this game. Please you can suggest to me.


    I hope a nice reply
     
  14. parrytellus

    parrytellus Banned

    Joined:
    Aug 9, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.accutellus.com
    hi...

    Thanks many to share the game programming...!!! meet again.

    :goofy:
     
  15. umairaraza100

    umairaraza100 Banned

    Joined:
    Jul 29, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.earnmoney.pk/
    well its nice graphically game
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice