                             
           
                                                       GAME X
                                                             BY
                                         U.Srinivas(srinivascse@yahoo.com)
                                                date : 28-03-2004 , 6:35 p.m 


This is a 2-d sprites based game. It involves important concepts of game design issues such as
timing a game, collision-detection etc. It is a DOS based game which uses MODE 13H which has
a resolution of  320x200 and a palette of 256 colors. 

Game Implementation

To start with any game design we can divide the goal in to 4 issues which are
---------------------------------------------------------------------------------------------------------------------------------
Issue 1:-

Choosing the platform and programming language for game development.in this game we have used 
c,c++ and INLINE ASSEMBLY as our programming languages.INLINE ASSEMBLY is a convention
of writing assembly code in between  our c,c++ code. we  used borland c++ 3.0 to compile this program
which has an inline assembler called BASM which decodes the assembly code. To write it we use the
following convention,
                                   asm{
                                           mov ah,00h
                                           mov  al,13h
                                           int 10h
                                         }
note:- the flower braces must be next to asm keyword.

The platform is DOS and we used MODE 13H  graphics mode which has an resolution of  320x200
pixels and a palette of 256 colors. The above code is used to set MODE 13H graphics mode. out next
aim is to write a graphics library for our game. Some common functions which our library must consists
of are
                  1. setvga13( ); //which sets to mode 13h
                  2. putpixel( ); //which puts a pixel on the screen
                  3.getpixel( );  //which return the color of the pixel at x,y
                  4.set_palette( );// which sets the color palette of a color
                  5.get_palette( ); //which get's the color palette of a color
                  6.wait_retrace( ); // wait's for vertical retrace of our monitor
                  7.draw_bitmap( ); // which draw's a bitmap at x,y
                  8.clear_bitmap( ); // which clears a bitmap at x,y
                       
note:- the definitions for all these functions are found in MODE_13.H header file. please see it for a
         clear understanding.

considering the function putpixel( ), there are 2 ways of displaying a pixel on the screen. they are
      1. displaying through interrupts
      2. displaying by directly manipulating the V.D.U memory.

the second method is fastest as what ever method we use we ultimately manipulate the vdu memory
The address of VDU memory is A000:0000, to understand clearly see the function definition of putpixel( )
---------------------------------------------------------------------------------------------------------------------------------
Issue 2:-
 
The second issue to be concerned is the art work of the game. we need the pictures of different objects 
used in our game. to do this we have 2 options

1. drawing them in Paint Programs
2.Using the Sprites of the objects drawn in an Sprite editor.

the first one is inefficient since we have very less memory in dos environment. the second one is the 
basic and most efficient one.
A Sprite is an 2-d character array which represents a picture.for example to draw a small triangle we use
the following array to draw it.
                                             char a[3][5]= { 0 , 0 , 1 , 0 , 0
                                                                    0 , 1 , 0 , 1 , 0
                                                                    1 , 1 , 1 , 1 , 1 };
 
observe this array,assume that we have only 2 colors 1--> white and 0-->black. when we draw this 2-d 
array in the screen we see a triangle since only the pixels with value 1 get's highlighed leaving the 0's.
the actual distance between the pixels is very close on the screen.

in our game we used a Sprite Editor named GRED  to draw the different objects of our game.drawing
the objects in editor and saving it will generate the corresponding 2-d array.
see the main file game.cpp for the sprites of different objects.
---------------------------------------------------------------------------------------------------------------------------------

Issue 3:-

After having the graphics library and the art work ready, we next consider the animations of different 
objects in our game. to proprely time this animations we in general use need a timer and depending on 
this timer we animate things. we in our game implemented this timer using the 8253 PIT(programmable 
interval timer).this is an I.C which is responsible for updating our pc clock, it is programmed to run at
18.2 hz ie. 18.2 times a second. Each time a clock cycle is generated a interrupt 8 is also generated
we then write a I.S.R(interrupt service routine) to this interrupt and increament a variable named timer
in that function. we can then use this variable as our timer because it is increamented in the background
independent of our program. we can program this 8253 PIT to run at desired frequency.see in the file
game.cpp the function //void interrupt newtimer( )   for the implementation of the timer.

the functions draw_bitmap and clear_bitmap are used  in synchronization with timer variable to have
a smooth animation of all the objects in the game.
---------------------------------------------------------------------------------------------------------------------------------

Issue 4:-

This is one important issue in some games having collision detection. collision detection is the process
of detecting wheather one object has hit another or not. In our game we used Pixel-wise collision detection
method for collision detection.the logic used by this method is every time we move forward we check
for the color of pixels in surroundings of  the object, if they are non-black(some object is there in
 that position) then we detected a collision and write a function for that.in our game we used this logic
to detect the collision of jet's bullet with alien ship.                                             

finally we write code to combine all the objects. Here it handle every object we used c++ rather than c
because, consider for example a object it has many properties(attributes) which can generally divided into
the following
                     1. posx,posy which determine the current position of the object
                     2. life_status which is 0(dead) or 1(alive).
                     3. next_time which denotes the next time it should be moved.
to handle many objects with these attributes and their related functions it is convinient to use c++ classes
other logic part is left to the programmer.

These are the generral issues to be considered to develop a game.

please try to understand the code in two files namely mode_13.h and game.cpp.
---------------------------------------------------------------------------------------------------------------------------------
some links for game programming tutorials:

1. atrevida game tutorials
2. alex russell's dos game programming tutorial

-------------------------------------------------------------------------

This game is compiled using turbo c++ 3.0. it works only on win98 O.S and does not work on winxp
and win2000 as they use virtual dos. if any one of you can fix this bug Please mail me.

for any doubts and suggestions feel free to mail me at : srinivascse@yahoo.com 

bye

