Exemple #1
0
int Game_Init(void *parms,  int num_parms)
{
// this function is where you do all the initialization 
// for your game

int index;         // looping var
char filename[80]; // used to build up files names

// initialize directdraw
DDraw_Init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP);

// load in texture maps
Load_Bitmap_File(&bitmap8bit, "SCROLLTEXTURES.BMP");

// set the palette to background image palette
Set_Palette(bitmap8bit.palette);

// create the texture bob
if (!Create_BOB(&textures,0,0,64,64,10, 
                BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_FRAME,DDSCAPS_SYSTEMMEMORY))
   return(0);

// load each texture bitmap into the texture BOB object
for (index = 0; index < NUM_TEXTURES; index++)
    Load_Frame_BOB(&textures,&bitmap8bit,index,index%4,index/4,BITMAP_EXTRACT_MODE_CELL); 

// unload the texture map bitmap
Unload_Bitmap_File(&bitmap8bit);

// set clipping rectangle to screen extents so mouse cursor
// doens't mess up at edges
RECT screen_rect = {0,0,screen_width,screen_height-32}; // 32 pixels at the bottom for controls

// notice at bottom of screen a blank rect, this would be for your
// control panel for example
lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);

// hide the mouse
ShowCursor(FALSE);

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms = NULL, int num_parms = 0)
{
// this is called once after the initial window is created and
// before the main event loop is entered, do all your initialization
// here

// create IDirectDraw interface 7.0 object and test for error
if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
   return(0);

// set cooperation to full screen
if (FAILED(lpdd->SetCooperativeLevel(main_window_handle, 
                                      DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | 
                                      DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
   return(0);

// set display mode to 640x480x8
if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0)))
   return(0);

// clear ddsd and set size
DDRAW_INIT_STRUCT(ddsd); 

// enable valid fields
ddsd.dwFlags = DDSD_CAPS;

// request primary surface
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

// create the primary surface
if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL)))
   return(0);

// load the 24-bit image
if (!Load_Bitmap_File(&bitmap,"bitmap24.bmp"))
   return(0);


// return success or failure or your own return code here
return(1);

} // end Game_Init
int Game_Init(void *parms = NULL, int num_parms = 0)
{
// this is called once after the initial window is created and
// before the main event loop is entered, do all your initialization
// here

// create IDirectDraw interface 7.0 object and test for error
if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
   return(0);

// set cooperation to full screen
if (FAILED(lpdd->SetCooperativeLevel(main_window_handle, 
                                      DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | 
                                      DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
   return(0);

// set display mode to 640x480x8
if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0)))
   return(0);

// we need a complex surface system with a primary and backbuffer

// clear ddsd and set size
DDRAW_INIT_STRUCT(ddsd); 

// enable valid fields
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;

// set the backbuffer count field to 1, use 2 for triple buffering
ddsd.dwBackBufferCount = 1;

// request a complex, flippable
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;

// create the primary surface
if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL)))
   return(0);

// now query for attached surface from the primary surface

// this line is needed by the call
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;

// get the attached back buffer surface
if (FAILED(lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsback)))
  return(0);

// build up the palette data array
for (int color=1; color < 255; color++)
    {
    // fill with random RGB values
    palette[color].peRed   = rand()%256;
    palette[color].peGreen = rand()%256;
    palette[color].peBlue  = rand()%256;

    // set flags field to PC_NOCOLLAPSE
    palette[color].peFlags = PC_NOCOLLAPSE;
    } // end for color

// now fill in entry 0 and 255 with black and white
palette[0].peRed     = 0;
palette[0].peGreen   = 0;
palette[0].peBlue    = 0;
palette[0].peFlags   = PC_NOCOLLAPSE;

palette[255].peRed   = 255;
palette[255].peGreen = 255;
palette[255].peBlue  = 255;
palette[255].peFlags = PC_NOCOLLAPSE;

// create the palette object
if (FAILED(lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | 
                                DDPCAPS_INITIALIZE, 
                                palette,&lpddpal, NULL)))
return(0);

// finally attach the palette to the primary surface
if (FAILED(lpddsprimary->SetPalette(lpddpal)))
   return(0);

// set clipper up on back buffer since that's where well clip
RECT screen_rect= {0,0,SCREEN_WIDTH-1,SCREEN_HEIGHT-1};
lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);

// load the 8-bit image
if (!Load_Bitmap_File(&bitmap,"alley8.bmp"))
   return(0);

// load it's palette into directdraw
if (FAILED(lpddpal->SetEntries(0,0,MAX_COLORS_PALETTE,bitmap.palette)))
   return(0);

// clean the surfaces
DDraw_Fill_Surface(lpddsprimary,0);
DDraw_Fill_Surface(lpddsback,0);

// create the buffer to hold the background
lpddsbackground = DDraw_Create_Surface(640,480,0,-1);

// copy the background bitmap image to the background surface 

// lock the surface
lpddsbackground->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);

// get video pointer to primary surfce
UCHAR *image_buffer = (UCHAR *)ddsd.lpSurface;       

// test if memory is linear
if (ddsd.lPitch == SCREEN_WIDTH)
   {
   // copy memory from double buffer to primary buffer
   memcpy((void *)image_buffer, (void *)bitmap.buffer, SCREEN_WIDTH*SCREEN_HEIGHT);
   } // end if
else
   { // non-linear

   // make copy of source and destination addresses
   UCHAR *dest_ptr = image_buffer;
   UCHAR *src_ptr  = bitmap.buffer;

   // memory is non-linear, copy line by line
   for (int y=0; y < SCREEN_HEIGHT; y++)
       {
       // copy line
       memcpy((void *)dest_ptr, (void *)src_ptr, SCREEN_WIDTH);

       // advance pointers to next line
       dest_ptr+=ddsd.lPitch;
       src_ptr +=SCREEN_WIDTH;
       } // end for

   } // end else

// now unlock the primary surface
if (FAILED(lpddsbackground->Unlock(NULL)))
   return(0);

// unload the bitmap file, we no longer need it
Unload_Bitmap_File(&bitmap);

// seed random number generator
srand(GetTickCount());

// initialize all the aliens (in real life do this in a loop or function)

// alien on level 1 of complex

aliens[0].x              = rand()%SCREEN_WIDTH;
aliens[0].y              = 116 - 72;                  
aliens[0].velocity       = 2+rand()%4;
aliens[0].current_frame  = 0;             
aliens[0].counter        = 0;       
aliens[0].width          = 72; // set real size
aliens[0].height         = 80;
aliens[0].scale          = ((float)(1+rand()%20))/10; // scale from 0.1 to 2.0
// fix up feet so they still contact floor
aliens[0].y+=(72 - aliens[0].scale*72);

// alien on level 2 of complex

aliens[1].x              = rand()%SCREEN_WIDTH;
aliens[1].y              = 246 - 72;                  
aliens[1].velocity       = 2+rand()%4;
aliens[1].current_frame  = 0;             
aliens[1].counter        = 0;  
aliens[1].width          = 72; // set real size
aliens[1].height         = 80;
aliens[1].scale          = ((float)(1+rand()%20))/10; // scale from 0.1 to 2.0
// fix up feet so they still contact floor
aliens[1].y+=(72 - aliens[1].scale*72);



// alien on level 3 of complex

aliens[2].x              = rand()%SCREEN_WIDTH;
aliens[2].y              = 382 - 72;                  
aliens[2].velocity       = 2+rand()%4;
aliens[2].current_frame  = 0;             
aliens[2].counter        = 0;  
aliens[2].width          = 72; // set real size
aliens[2].height         = 80;
aliens[2].scale          = ((float)(1+rand()%20))/10; // scale from 0.1 to 2.0

// fix up feet so they still contact floor
aliens[2].y+=(72 - aliens[2].scale*72);


// now load the bitmap containing the alien imagery
// then scan the images out into the surfaces of alien[0]
// and copy then into the other two, be careful of reference counts!

// load the 8-bit image
if (!Load_Bitmap_File(&bitmap,"dedsp0.bmp"))
   return(0);

// create each surface and load bits
for (int index = 0; index < 3; index++)
    {
    // create surface to hold image
    aliens[0].frames[index] = DDraw_Create_Surface(72,80,0);

    // now load bits...
    Scan_Image_Bitmap(&bitmap,                 // bitmap file to scan image data from
                      aliens[0].frames[index], // surface to hold data
                      index, 0);               // cell to scan image from    

    } // end for index

// unload the bitmap file, we no longer need it
Unload_Bitmap_File(&bitmap);

// now for the tricky part. There is no need to create more surfaces with the same
// data, so I'm going to copy the surface pointers member for member to each alien
// however, be careful, since the reference counts do NOT go up, you still only need
// to release() each surface once!

for (index = 0; index < 3; index++)
    aliens[1].frames[index] = aliens[2].frames[index] = aliens[0].frames[index];

// return success or failure or your own return code here
return(1);

} // end Game_Init
int Game_Init(void *parms,  int num_parms)
{
// this function is where you do all the initialization 
// for your game

int index;         // looping var
char filename[80]; // used to build up files names

// seed random number generator
srand(Get_Clock());

// initialize directdraw, very important that in the call
// to setcooperativelevel that the flag DDSCL_MULTITHREADED is used
// which increases the response of directX graphics to
// take the global critical section more frequently
DDraw_Init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP);

// load in the alien bob image
Load_Bitmap_File(&bitmap8bit, "ALIENSGLOW.BMP");

// set the palette to the palette of the aliens
Set_Palette(bitmap8bit.palette);

// create the master alien bob
if (!Create_BOB(&aliens[0],0,0,48,47,1, 
                BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME | BOB_ATTR_BOUNCE,DDSCAPS_SYSTEMMEMORY ))
   return(0);

// load the bitmap for alien -- only 1
Load_Frame_BOB(&aliens[0],&bitmap8bit,0,0,0,BITMAP_EXTRACT_MODE_CELL); 

// unload the map bitmap
Unload_Bitmap_File(&bitmap8bit);

// now create all the alien clones :)
for (index = 1; index < NUM_ALIENS; index++)
    Clone_BOB(&aliens[0],&aliens[index]);

// at this point everything has been cloned, now set up aliens at
// random positions
for (index = 0; index < NUM_ALIENS; index++)
    {
    // set position
    Set_Pos_BOB(&aliens[index], rand()%screen_width, rand()%screen_height);

    // set motion velocities
    Set_Vel_BOB(&aliens[index],-4+rand()%8, -4+rand()%8);

    } // end for index

// set clipping rectangle to screen extents so mouse cursor
// doens't mess up at edges
RECT screen_rect = {0,0,screen_width,screen_height}; 
lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);

// hide the mouse
ShowCursor(FALSE);

#ifdef USE_MULTITHREADING
// create the animation thread for color rotation
thread_handle = CreateThread(NULL,               // default security
			                    0,				    // default stack 
								Alien_Color_Thread,// use this thread function
								(LPVOID)index,      // user data sent to thread
								0,				    // creation flags, 0=start now.
								&thread_id);	// send id back in this var

    // increment number of active threads
    active_threads++;

#endif
 
// return success
return(1);

} // end Game_Init
int Game_Init(void *parms)
{
// this function is where you do all the initialization 
// for your game

int index; // looping varsIable

char filename[80]; // used to build up filenames

// seed random number generate
srand(Start_Clock());

// start up DirectDraw (replace the parms as you desire)
DDraw_Init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP);

// load background image
Load_Bitmap_File(&bitmap8bit, "GRAVSKY8.BMP");
Create_Bitmap(&background_bmp,0,0,640,480);
Load_Image_Bitmap(&background_bmp, &bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Set_Palette(bitmap8bit.palette);
Unload_Bitmap_File(&bitmap8bit);

// load the bitmaps for ship
Load_Bitmap_File(&bitmap8bit, "BLAZE8.BMP");

// create bob
Create_BOB(&ship,320,240,22,18,32,BOB_ATTR_MULTI_FRAME | BOB_ATTR_VISIBLE, DDSCAPS_SYSTEMMEMORY);

// well use varsI[0] to hold the direction 0..15, 0-360 degrees, clockwise
ship.varsI[0] = 0; // along +x axis to start

// use varsF[0,1] for the x and y velocity
ship.varsF[0] = 0;
ship.varsF[1] = 0;

// use varsF[2,3] for the x and y position, we need more accuracy than ints
ship.varsF[2] = ship.x;
ship.varsF[3] = ship.y;

// load the frames in
for (index=0; index < 32; index++)
    Load_Frame_BOB(&ship, &bitmap8bit, index, index%16,index/16,BITMAP_EXTRACT_MODE_CELL);

// unload bitmap image
Unload_Bitmap_File(&bitmap8bit);

// load the bitmaps for blackhole
Load_Bitmap_File(&bitmap8bit, "PHOTON8.BMP");

// create bob
Create_BOB(&black_hole,32+rand()%(SCREEN_WIDTH-64),32+rand()%(SCREEN_HEIGHT-64),
            44,44,7,BOB_ATTR_MULTI_FRAME | BOB_ATTR_VISIBLE, DDSCAPS_SYSTEMMEMORY);

// set animation speed
Set_Anim_Speed_BOB(&black_hole,3);

// load the frames in
for (index=0; index < 7; index++)
    Load_Frame_BOB(&black_hole, &bitmap8bit, index, index,0,BITMAP_EXTRACT_MODE_CELL);

// unload bitmap image
Unload_Bitmap_File(&bitmap8bit);

// initialize directinput
DInput_Init();

// acquire the keyboard only
DInput_Init_Keyboard();

// initilize DirectSound
DSound_Init();

// load background sounds
sound_id = DSound_Load_WAV("BHOLE.WAV");

// start the sounds
DSound_Play(sound_id, DSBPLAY_LOOPING);

// set clipping rectangle to screen extents so objects dont
// mess up at edges
RECT screen_rect = {0,0,screen_width,screen_height};
lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);

// hide the mouse
ShowCursor(FALSE);

// return success
return(1);

} // end Game_Init
Exemple #6
0
int Load_Object_MD2
(
	MD2_CONTAINER_PTR	obj_md2,		/* the loaded md2 file placed in container */
	char				*modelfile,		/* the filename of the .MD2 model */
	VECTOR4D_PTR		scale,			/* initial scaling factors */
	VECTOR4D_PTR		pos,			/* initial position */
	VECTOR4D_PTR		rot,			/* initial rotations (not implemented) */
	char				*texturefile,	/* the texture filename for the model */
	int					attr,			/* the lighting/model attributes for the model */
	int					color,			/* base color if no texturing */
	int					vertex_flags
)	/* control ordering etc. */
{

	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	/*
	 * this function loads in an md2 file, extracts all the data and stores it in the ;
	 * container class which will be used later to load frames into a the standard
	 * object ;
	 * type for rendering on the fl
	 */
	FILE			*fp = NULL;		/* file pointer to model */
	int				flength = -1;	/* general file length */
	UCHAR			*buffer = NULL; /* used to buffer md2 file data */
	MD2_HEADER_PTR	md2_header;		/* pointer to the md2 header */
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	/* begin by loading in the .md2 model file */
	if((fp = fopen(modelfile, "rb")) == NULL)
	{
		Write_Error("\nLoad_Object_MD2 - couldn't find file %s", modelfile);
		return(0);
	}	/* end if */

	/*
	 * find the length of the model file ;
	 * seek to end of file
	 */
	fseek(fp, 0, SEEK_END);

	/* where is the file pointer? */
	flength = ftell(fp);

	/*
	 * now read the md2 file into a buffer to analyze it ;
	 * re-position file pointer to beginning of file
	 */
	fseek(fp, 0, SEEK_SET);

	/* allocate memory to hold file */
	buffer = (UCHAR *) malloc(flength + 1);

	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	/* load data into buffer */
	int bytes_read = fread(buffer, sizeof(UCHAR), flength, fp);
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	/*
	 * the header is the first item in the buffer, so alias a pointer ;
	 * to it, so we can start analyzing it and creating the model
	 */
	md2_header = (MD2_HEADER_PTR) buffer;

	Write_Error("\nint identifier        = %d", md2_header->identifier);
	Write_Error("\nint version           = %d", md2_header->version);
	Write_Error("\nint skin_width        = %d", md2_header->skin_width);
	Write_Error("\nint skin_height       = %d", md2_header->skin_height);
	Write_Error("\nint framesize         = %d", md2_header->framesize);
	Write_Error("\nint num_skins         = %d", md2_header->num_skins);
	Write_Error("\nint num_verts         = %d", md2_header->num_verts);
	Write_Error("\nint num_textcoords    = %d", md2_header->num_textcoords);
	Write_Error("\nint num_polys         = %d", md2_header->num_polys);
	Write_Error("\nint num_openGLcmds    = %d", md2_header->num_openGLcmds);
	Write_Error("\nint num_frames        = %d", md2_header->num_frames);
	Write_Error("\nint offset_skins      = %d", md2_header->offset_skins);
	Write_Error("\nint offset_textcoords = %d", md2_header->offset_textcoords);
	Write_Error("\nint offset_polys      = %d", md2_header->offset_polys);
	Write_Error("\nint offset_frames     = %d", md2_header->offset_frames);
	Write_Error("\nint offset_openGLcmds = %d", md2_header->offset_openGLcmds);
	Write_Error("\nint offset_end        = %d", md2_header->offset_end);

	/* test for valid file */
	if(md2_header->identifier != MD2_MAGIC_NUM || md2_header->version != MD2_VERSION)
	{
		fclose(fp);
		return(0);
	}	/* end if */

	/* assign fields to container class */
	obj_md2->state = 0;		/* state of the model */
	obj_md2->attr = attr;	/* attributes of the model */
	obj_md2->color = color;
	obj_md2->num_frames = md2_header->num_frames;			/* number of frames in the model */
	obj_md2->num_polys = md2_header->num_polys;				/* number of polygons */
	obj_md2->num_verts = md2_header->num_verts;				/* number of vertices */
	obj_md2->num_textcoords = md2_header->num_textcoords;	/* number of texture coordinates */
	obj_md2->curr_frame = 0;	/* current frame in animation */
	obj_md2->skin = NULL;		/* pointer to texture skin for model */
	obj_md2->world_pos = *pos;	/* position object in world */

	/* allocate memory for mesh data */
	obj_md2->polys = (MD2_POLY_PTR) malloc(md2_header->num_polys * sizeof(MD2_POLY));	/* pointer to polygon list */
	obj_md2->vlist = (VECTOR3D_PTR) malloc(md2_header->num_frames * md2_header->num_verts * sizeof(VECTOR3D));	/* pointer
																												 * to
																												 * vertex
																												 * coordinate
																												 * list
																												 * */
	obj_md2->tlist = (VECTOR2D_PTR) malloc(md2_header->num_textcoords * sizeof(VECTOR2D));	/* pointer to texture
																							 * coordinate list */

#if (MD2_DEBUG == 1)
	Write_Error("\nTexture Coordinates:");
#endif
	for(int tindex = 0; tindex < md2_header->num_textcoords; tindex++)
	{
#if (MD2_DEBUG == 1)
		Write_Error
		(
			"\ntextcoord[%d] = (%d, %d)",
			tindex,
			((MD2_TEXTCOORD_PTR) (buffer + md2_header->offset_textcoords))[tindex].u,
			((MD2_TEXTCOORD_PTR) (buffer + md2_header->offset_textcoords))[tindex].v
		);
#endif

		/* insert texture coordinate into storage container */
		obj_md2->tlist[tindex].x = ((MD2_TEXTCOORD_PTR) (buffer + md2_header->offset_textcoords))[tindex].u;
		obj_md2->tlist[tindex].y = ((MD2_TEXTCOORD_PTR) (buffer + md2_header->offset_textcoords))[tindex].v;
	}	/* end for vindex */

#if (MD2_DEBUG == 1)
	Write_Error("\nVertex List:");
#endif
	for(int findex = 0; findex < md2_header->num_frames; findex++)
	{
#if (MD2_DEBUG == 1)
		Write_Error("\n\n******************************************************************************");
		Write_Error("\n\nF R A M E # %d", findex);
		Write_Error("\n\n******************************************************************************\n");
#endif

		/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
		MD2_FRAME_PTR	frame_ptr = (MD2_FRAME_PTR)
			(buffer + md2_header->offset_frames + md2_header->framesize * findex);
		/* extract md2 scale and translate, additionally use sent scale and translate */
		float			sx = frame_ptr->scale[0], sy = frame_ptr->scale[1], sz = frame_ptr->scale[2], tx = frame_ptr->
			translate[0], ty = frame_ptr->translate[1], tz = frame_ptr->translate[2];
		/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

#if (MD2_DEBUG == 1)
		Write_Error("\nScale: (%f, %f, %f)\nTranslate: (%f, %f, %f)", sx, sy, sz, tx, ty, tz);
#endif
		for(int vindex = 0; vindex < md2_header->num_verts; vindex++)
		{
			/*~~~~~~~~~~*/
			VECTOR3D	v;
			/*~~~~~~~~~~*/

			/* scale and translate compressed vertex */
			v.x = (float) frame_ptr->vlist[vindex].v[0] * sx + tx;
			v.y = (float) frame_ptr->vlist[vindex].v[1] * sy + ty;
			v.z = (float) frame_ptr->vlist[vindex].v[2] * sz + tz;

			/* scale final point based on sent data */
			v.x = scale->x * v.x;
			v.y = scale->y * v.y;
			v.z = scale->z * v.z;

			/*~~~~~~~~~*/
			float	temp;	/* used for swaping */
			/*~~~~~~~~~*/

			/* test for vertex modifications to winding order etc. */
			if(vertex_flags & VERTEX_FLAGS_INVERT_X) v.x = -v.x;
			if(vertex_flags & VERTEX_FLAGS_INVERT_Y) v.y = -v.y;
			if(vertex_flags & VERTEX_FLAGS_INVERT_Z) v.z = -v.z;
			if(vertex_flags & VERTEX_FLAGS_SWAP_YZ) SWAP(v.y, v.z, temp);
			if(vertex_flags & VERTEX_FLAGS_SWAP_XZ) SWAP(v.x, v.z, temp);
			if(vertex_flags & VERTEX_FLAGS_SWAP_XY) SWAP(v.x, v.y, temp);

#if (MD2_DEBUG == 1)
			Write_Error("\nVertex #%d = (%f, %f, %f)", vindex, v.x, v.y, v.z);
#endif

			/*
			 * insert vertex into vertex list which is laid out frame 0, frame 1,..., frame n ;
			 * frame i: vertex 0, vertex 1,....vertex j
			 */
			obj_md2->vlist[vindex + (findex * obj_md2->num_verts)] = v;
		}	/* end vindex */
	}		/* end findex */

#if (MD2_DEBUG == 1)
	Write_Error("\nPolygon List:");
#endif

	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	MD2_POLY_PTR	poly_ptr = (MD2_POLY_PTR) (buffer + md2_header->offset_polys);
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	for(int pindex = 0; pindex < md2_header->num_polys; pindex++)
	{

		/* insert polygon into polygon list in container */
		if(vertex_flags & VERTEX_FLAGS_INVERT_WINDING_ORDER)
		{

			/*
			 * inverted winding order ;
			 * vertices
			 */
			obj_md2->polys[pindex].vindex[0] = poly_ptr[pindex].vindex[2];
			obj_md2->polys[pindex].vindex[1] = poly_ptr[pindex].vindex[1];
			obj_md2->polys[pindex].vindex[2] = poly_ptr[pindex].vindex[0];

			/* texture coordinates */
			obj_md2->polys[pindex].tindex[0] = poly_ptr[pindex].tindex[2];
			obj_md2->polys[pindex].tindex[1] = poly_ptr[pindex].tindex[1];
			obj_md2->polys[pindex].tindex[2] = poly_ptr[pindex].tindex[0];
		}	/* end if */
		else
		{

			/*
			 * normal winding order ;
			 * vertices
			 */
			obj_md2->polys[pindex].vindex[0] = poly_ptr[pindex].vindex[0];
			obj_md2->polys[pindex].vindex[1] = poly_ptr[pindex].vindex[1];
			obj_md2->polys[pindex].vindex[2] = poly_ptr[pindex].vindex[2];

			/* texture coordinates */
			obj_md2->polys[pindex].tindex[0] = poly_ptr[pindex].tindex[0];
			obj_md2->polys[pindex].tindex[1] = poly_ptr[pindex].tindex[1];
			obj_md2->polys[pindex].tindex[2] = poly_ptr[pindex].tindex[2];
		}	/* end if */

#if (MD2_DEBUG == 1)
		Write_Error
		(
			"\npoly %d: v(%d, %d, %d), t(%d, %d, %d)",
			pindex,
			obj_md2->polys[pindex].vindex[0],
			obj_md2->polys[pindex].vindex[1],
			obj_md2->polys[pindex].vindex[2],
			obj_md2->polys[pindex].tindex[0],
			obj_md2->polys[pindex].tindex[1],
			obj_md2->polys[pindex].tindex[2]
		);
#endif
	}		/* end for vindex */

	/* close the file */
	fclose(fp);

	/* load the texture from disk */
	Load_Bitmap_File(&bitmap16bit, texturefile);

	/* create a proper size and bitdepth bitmap */
	obj_md2->skin = (BITMAP_IMAGE_PTR) malloc(sizeof(BITMAP_IMAGE));

	/* initialize bitmap */
	Create_Bitmap
	(
		obj_md2->skin,
		0,
		0,
		bitmap16bit.bitmapinfoheader.biWidth,
		bitmap16bit.bitmapinfoheader.biHeight,
		bitmap16bit.bitmapinfoheader.biBitCount
	);

	/* load the bitmap image */
	Load_Image_Bitmap16(obj_md2->skin, &bitmap16bit, 0, 0, BITMAP_EXTRACT_MODE_ABS);

	/* done, so unload the bitmap */
	Unload_Bitmap_File(&bitmap16bit);

	/* finally release the memory for the temporary buffer */
	if(buffer) free(buffer);

	/* return success */
	return(1);
}			/* end Load_Object_MD2 */
int Game_Init(void *parms,  int num_parms)
{
// this function is where you do all the initialization 
// for your game

int index;         // looping var
char filename[80]; // used to build up files names

// initialize directdraw
DDraw_Init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, WINDOWED_APP);

// start up DirectInput
DInput_Init();

// initialize the keyboard
DInput_Init_Keyboard();

// load the background
Load_Bitmap_File(&bitmap8bit, "REACTOR2.BMP");

// set the palette to background image palette
Set_Palette(bitmap8bit.palette);

// create and load the reactor bitmap image
Create_Bitmap(&reactor, 0,0, 640, 480);
Load_Image_Bitmap(&reactor,&bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap8bit);

// now let's load in all the frames for the skelaton!!!

// create skelaton bob
if (!Create_BOB(&skelaton,0,0,56,72,32,
           BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_ANIM,DDSCAPS_SYSTEMMEMORY))
   return(0);

// load the frames in 8 directions, 4 frames each
// each set of frames has a walk and a fire, frame sets
// are loaded in counter clockwise order looking down
// from a birds eys view or the x-z plane
for (int direction = 0; direction < 8; direction++)
    { 
    // build up file name
    sprintf(filename,"SKELSP%d.BMP",direction);

    // load in new bitmap file
    Load_Bitmap_File(&bitmap8bit,filename);
 
    Load_Frame_BOB(&skelaton,&bitmap8bit,0+direction*4,0,0,BITMAP_EXTRACT_MODE_CELL);  
    Load_Frame_BOB(&skelaton,&bitmap8bit,1+direction*4,1,0,BITMAP_EXTRACT_MODE_CELL);  
    Load_Frame_BOB(&skelaton,&bitmap8bit,2+direction*4,2,0,BITMAP_EXTRACT_MODE_CELL);  
    Load_Frame_BOB(&skelaton,&bitmap8bit,3+direction*4,0,1,BITMAP_EXTRACT_MODE_CELL);  

    // unload the bitmap file
    Unload_Bitmap_File(&bitmap8bit);

    // set the animation sequences for skelaton
    Load_Animation_BOB(&skelaton,direction,4,skelaton_anims[direction]);

    } // end for direction

// set up stating state of skelaton
Set_Animation_BOB(&skelaton, 0);
Set_Anim_Speed_BOB(&skelaton, 4);
Set_Vel_BOB(&skelaton, 0,0);
Set_Pos_BOB(&skelaton, 0, 128);

// set clipping rectangle to screen extents so mouse cursor
// doens't mess up at edges
RECT screen_rect = {0,0,screen_width,screen_height};
lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);

// hide the mouse
ShowCursor(FALSE);

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms)
{
// this function is where you do all the initialization 
// for your game

int index; // looping var

// start up DirectDraw (replace the parms as you desire)
DDraw_Init2(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP,0);

// initialize directinput
DInput_Init();

// acquire the keyboard 
DInput_Init_Keyboard();

// add calls to acquire other directinput devices here...

// initialize directsound and directmusic
DSound_Init();
DMusic_Init();

// hide the mouse
if (!WINDOWED_APP)
    ShowCursor(FALSE);

// seed random number generator
srand(Start_Clock()); 

Open_Error_File("ERROR.TXT");

// initialize math engine
Build_Sin_Cos_Tables();

// initialize the camera with 90 FOV, normalized coordinates
Init_CAM4DV1(&cam,      // the camera object
             CAM_MODEL_EULER, // the euler model
             &cam_pos,  // initial camera position
             &cam_dir,  // initial camera angles
             &cam_target,      // no target
             10.0,        // near and far clipping planes
             12000.0,
             120.0,      // field of view in degrees
             WINDOW_WIDTH,   // size of final screen viewport
             WINDOW_HEIGHT);
 


#if 0
VECTOR4D terrain_pos = {0,0,0,0}; 
Generate_Terrain_OBJECT4DV2(&obj_terrain,            // pointer to object
                            TERRAIN_WIDTH,           // width in world coords on x-axis
                            TERRAIN_HEIGHT,          // height (length) in world coords on z-axis
                            TERRAIN_SCALE,           // vertical scale of terrain
                            "checkerheight05.bmp",  // filename of height bitmap encoded in 256 colors
                            "checker256256.bmp",   // filename of texture map
                             RGB16Bit(255,255,255),  // color of terrain if no texture        
                             &terrain_pos,           // initial position
                             NULL,                   // initial rotations
                             POLY4DV2_ATTR_RGB16  
                             | POLY4DV2_ATTR_SHADE_MODE_CONSTANT
                             // | POLY4DV2_ATTR_SHADE_MODE_FLAT 
                             // | POLY4DV2_ATTR_SHADE_MODE_GOURAUD
                             | POLY4DV2_ATTR_SHADE_MODE_TEXTURE);

#endif

// set a scaling vector
VECTOR4D_INITXYZ(&vscale,TERRAIN_WIDTH,1.00,TERRAIN_HEIGHT); 
// set position
VECTOR4D_INITXYZ(&vpos, 0, 0, 0);

Load_OBJECT4DV2_COB2(&obj_terrain, "plane01.cob",  
                        &vscale, &vpos, &vrot, VERTEX_FLAGS_SWAP_YZ  | 
                                               VERTEX_FLAGS_TRANSFORM_LOCAL 
                                               /* VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD*/,0 );


// set a scaling vector
VECTOR4D_INITXYZ(&vscale,60.00,60.00,60.00); 

// load all the objects in
for (int index_obj=0; index_obj < NUM_OBJECTS; index_obj++)
    {
    Load_OBJECT4DV2_COB2(&obj_array[index_obj], object_filenames[index_obj],  
                        &vscale, &vpos, &vrot, VERTEX_FLAGS_SWAP_YZ  | 
                                               VERTEX_FLAGS_TRANSFORM_LOCAL 
                                               /* VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD*/,0 );

    } // end for index_obj

// position the scenery objects randomly
for (index = 0; index < NUM_SCENE_OBJECTS; index++)
    {
    // randomly position object
    scene_objects[index].x = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
    scene_objects[index].y = 75; // RAND_RANGE(-(UNIVERSE_RADIUS/2), (UNIVERSE_RADIUS/2));
    scene_objects[index].z = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);

    // select random object, use w to store value
    scene_objects[index].w = RAND_RANGE(0,NUM_OBJECTS-1);
    } // end for


// select random velocities
for (index = 0; index < NUM_SCENE_OBJECTS; index++)
    {
    // randomly position object
    scene_objects_vel[index].x = RAND_RANGE(-MAX_VEL, MAX_VEL);
    scene_objects_vel[index].y = 0; // RAND_RANGE(-MAX_VEL, MAX_VEL);
    scene_objects_vel[index].z = RAND_RANGE(-MAX_VEL, MAX_VEL);
    } // end for

// set up lights
Reset_Lights_LIGHTV2(lights2, MAX_LIGHTS);

// create some working colors
white.rgba = _RGBA32BIT(255,255,255,0);
gray.rgba  = _RGBA32BIT(150,150,150,0);
black.rgba = _RGBA32BIT(0,0,0,0);
red.rgba   = _RGBA32BIT(255,0,0,0);
green.rgba = _RGBA32BIT(0,255,0,0);
blue.rgba  = _RGBA32BIT(0,0,255,0);

// ambient light
Init_Light_LIGHTV2(lights2,               // array of lights to work with
                   AMBIENT_LIGHT_INDEX,   
                   LIGHTV2_STATE_ON,      // turn the light on
                   LIGHTV2_ATTR_AMBIENT,  // ambient light type
                   gray, black, black,    // color for ambient term only
                   NULL, NULL,            // no need for pos or dir
                   0,0,0,                 // no need for attenuation
                   0,0,0);                // spotlight info NA

VECTOR4D dlight_dir = {-1,0,-1,1}; 

// directional light
Init_Light_LIGHTV2(lights2,               // array of lights to work with
                   INFINITE_LIGHT_INDEX,  
                   LIGHTV2_STATE_ON,      // turn the light on
                   LIGHTV2_ATTR_INFINITE, // infinite light type
                   black, gray, black,    // color for diffuse term only
                   NULL, &dlight_dir,     // need direction only
                   0,0,0,                 // no need for attenuation
                   0,0,0);                // spotlight info NA


VECTOR4D plight_pos = {0,200,0,1};

// point light
Init_Light_LIGHTV2(lights2,               // array of lights to work with
                   POINT_LIGHT_INDEX,
                   LIGHTV2_STATE_ON,      // turn the light on
                   LIGHTV2_ATTR_POINT,    // pointlight type
                   black, green, black,    // color for diffuse term only
                   &plight_pos, NULL,     // need pos only
                   0,.002,0,              // linear attenuation only
                   0,0,1);                // spotlight info NA


VECTOR4D slight2_pos = {0,1000,0,1};
VECTOR4D slight2_dir = {-1,0,-1,1};

// spot light2
Init_Light_LIGHTV2(lights2,                  // array of lights to work with
                   SPOT_LIGHT2_INDEX,
                   LIGHTV2_STATE_ON,         // turn the light on
                   LIGHTV2_ATTR_SPOTLIGHT2,  // spot light type 2
                   black, red, black,        // color for diffuse term only
                   &slight2_pos, &slight2_dir, // need pos only
                   0,.001,0,                 // linear attenuation only
                   0,0,1);    


// create lookup for lighting engine
RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565,  // format we want to build table for
                                  palette,             // source palette
                                  rgblookup);          // lookup table

// create the z buffer
Create_Zbuffer(&zbuffer,
               WINDOW_WIDTH,
               WINDOW_HEIGHT,
               ZBUFFER_ATTR_32BIT);

// build alpha lookup table
RGB_Alpha_Table_Builder(NUM_ALPHA_LEVELS, rgb_alpha_table);


// load in the background
Create_BOB(&background, 0,0,800,600,1, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 16); 
Load_Bitmap_File(&bitmap16bit, "cloud03.bmp");
Load_Frame_BOB16(&background, &bitmap16bit,0,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms)
{
// this function is where you do all the initialization 
// for your game

int index; // looping varsIable

char filename[80]; // used to build up filenames

// seed random number generate
srand(Start_Clock());

// initialize directdraw, very important that in the call
// to setcooperativelevel that the flag DDSCL_MULTITHREADED is used
// which increases the response of directX graphics to
// take the global critical section more frequently
DDraw_Init(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

// load background image
Load_Bitmap_File(&bitmap8bit, "GREENGRID24.BMP");
Create_Bitmap(&background_bmp,0,0,640,480,16);
Load_Image_Bitmap16(&background_bmp, &bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap8bit);

// load the bitmaps
Load_Bitmap_File(&bitmap8bit, "POOLBALLS24.BMP");

// create master ball
Create_BOB(&balls[0],0,0,24,24,6,BOB_ATTR_MULTI_FRAME | BOB_ATTR_VISIBLE, DDSCAPS_SYSTEMMEMORY,0,16);

// load the imagery in
for (index=0; index < 6; index++)
    Load_Frame_BOB16(&balls[0], &bitmap8bit, index, index,0,BITMAP_EXTRACT_MODE_CELL);

// create all the clones
for (index=1; index < NUM_BALLS; index++)
    Clone_BOB(&balls[0], &balls[index]);

// now set the initial conditions of all the balls
for (index=0; index < NUM_BALLS; index++)
    {
    // set position randomly
    balls[index].varsF[INDEX_X] = RAND_RANGE(TABLE_MIN_X+20,TABLE_MAX_X-20);
    balls[index].varsF[INDEX_Y] = RAND_RANGE(TABLE_MIN_Y+20,TABLE_MAX_Y-20);

    // set initial velocity
    balls[index].varsF[INDEX_XV] = RAND_RANGE(-100, 100)/15;
    balls[index].varsF[INDEX_YV] = RAND_RANGE(-100, 100)/15;

    // set mass of ball in virtual kgs :)
    balls[index].varsF[INDEX_MASS] = 1; // 1 for now

    // set ball color
    balls[index].curr_frame = rand()%6;

    } // end for index

// unload bitmap image
Unload_Bitmap_File(&bitmap8bit);

// hide the mouse
if (!WINDOWED_APP)
   ShowCursor(FALSE);

// initialize directinput
DInput_Init();

// acquire the keyboard only
DInput_Init_Keyboard();

// initilize DirectSound
DSound_Init();

// load background sounds
ball_ids[0] = DSound_Load_WAV("PBALL.WAV");

// clone sounds
for (index=1; index<8; index++)
    ball_ids[index] = DSound_Replicate_Sound(ball_ids[0]);


// set clipping region
min_clip_x = TABLE_MIN_X;
min_clip_y = TABLE_MIN_Y;
max_clip_x = TABLE_MAX_X;
max_clip_y = TABLE_MAX_Y;

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms)
{
// this function is where you do all the initialization 
// for your game

int index; // looping varsIable

char filename[80]; // used to build up filenames

// seed random number generate
srand(Start_Clock());

// initialize directdraw, very important that in the call
// to setcooperativelevel that the flag DDSCL_MULTITHREADED is used
// which increases the response of directX graphics to
// take the global critical section more frequently
DDraw_Init(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

// load background image
Load_Bitmap_File(&bitmap8bit, "GREENGRID24.BMP");
Create_Bitmap(&background_bmp,0,0,640,480,16);
Load_Image_Bitmap16(&background_bmp, &bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap8bit);

// load the bitmaps
Load_Bitmap_File(&bitmap8bit, "POOLBALLS24.BMP");

// create master ball
Create_BOB(&balls[0],0,0,24,24,6,BOB_ATTR_MULTI_FRAME | BOB_ATTR_VISIBLE, DDSCAPS_SYSTEMMEMORY,0,16);

// load the imagery in
for (index=0; index < 6; index++)
    Load_Frame_BOB16(&balls[0], &bitmap8bit, index, index,0,BITMAP_EXTRACT_MODE_CELL);

// create all the clones
for (index=1; index < NUM_BALLS; index++)
    Clone_BOB(&balls[0], &balls[index]);

// now set the initial conditions of all the balls
for (index=0; index < NUM_BALLS; index++)
    {
    // set position in center of object
    balls[index].varsF[INDEX_X] = RAND_RANGE( SHAPE_CENTER_X-50,  SHAPE_CENTER_X+50);
    balls[index].varsF[INDEX_Y] = RAND_RANGE( SHAPE_CENTER_Y-50,  SHAPE_CENTER_Y+50);

   do
    {
    // set initial velocity
    balls[index].varsF[INDEX_XV] = RAND_RANGE(-100, 100)/30;
    balls[index].varsF[INDEX_YV] = RAND_RANGE(-100, 100)/30;
    }
    while (balls[index].varsF[INDEX_XV]==0 && balls[index].varsF[INDEX_XV]==0);

    // set ball color
    balls[index].curr_frame = rand()%6;

    } // end for index

// unload bitmap image
Unload_Bitmap_File(&bitmap8bit);

// define points of shape
VERTEX2DF shape_vertices[10] =  
{ 328-SHAPE_CENTER_X,60-SHAPE_CENTER_Y,
  574-SHAPE_CENTER_X,162-SHAPE_CENTER_Y,
  493-SHAPE_CENTER_X,278-SHAPE_CENTER_Y,
  605-SHAPE_CENTER_X,384-SHAPE_CENTER_Y,
  484-SHAPE_CENTER_X,433-SHAPE_CENTER_Y,
  306-SHAPE_CENTER_X,349-SHAPE_CENTER_Y,
  150-SHAPE_CENTER_X,413-SHAPE_CENTER_Y,
  28-SHAPE_CENTER_X,326-SHAPE_CENTER_Y,
  152-SHAPE_CENTER_X,281-SHAPE_CENTER_Y,
  73-SHAPE_CENTER_X,138-SHAPE_CENTER_Y };
 

// initialize shape
shape.state       = 1;   // turn it on
shape.num_verts   = 10;  
shape.x0          = SHAPE_CENTER_X;
shape.y0          = SHAPE_CENTER_Y;
shape.xv          = 0;
shape.yv          = 0;
shape.color       = RGB16Bit(0,255,0); // green
shape.vlist       = new VERTEX2DF [shape.num_verts];
 
for (index = 0; index < shape.num_verts; index++)
    shape.vlist[index] = shape_vertices[index];

// hide the mouse
if (!WINDOWED_APP)
   ShowCursor(FALSE);

// initialize directinput
DInput_Init();

// acquire the keyboard only
DInput_Init_Keyboard();

// build the 360 degree look ups
Build_Sin_Cos_Tables();

// initilize DirectSound
DSound_Init();

// load background sounds
ball_ids[0] = DSound_Load_WAV("PBALL.WAV");

// clone sounds
for (index=1; index<8; index++)
    ball_ids[index] = DSound_Replicate_Sound(ball_ids[0]);

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms,  int num_parms)
{
// this function is where you do all the initialization 
// for your game

int index;         // looping var
char filename[80]; // used to build up files names

// initialize directdraw
DDraw_Init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP);

// first create the direct input object
DirectInput8Create(main_instance,DIRECTINPUT_VERSION,IID_IDirectInput8, (void **)&lpdi,NULL);

// create a mouse device  /////////////////////////////////////
lpdi->CreateDevice(GUID_SysMouse, &lpdimouse, NULL);

// set cooperation level
lpdimouse->SetCooperativeLevel(main_window_handle, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);

// set data format
lpdimouse->SetDataFormat(&c_dfDIMouse);

// acquire the mouse
lpdimouse->Acquire();

/////////////////////////////////////////////////////////////////

// set the global mouse position
mouse_x = screen_height/2;
mouse_y = screen_height/2;

// load the master bitmap in with all the graphics
Load_Bitmap_File(&bitmap8bit, "PAINT.BMP");
Set_Palette(bitmap8bit.palette);

// make sure all the surfaces are clean before starting
DDraw_Fill_Surface(lpddsback, 0);
DDraw_Fill_Surface(lpddsprimary, 0);

// create the pointer bob
Create_BOB(&pointer,mouse_x,mouse_y,32,34,1,
           BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME,DDSCAPS_SYSTEMMEMORY);    

// load the image for the pointer in
Load_Frame_BOB(&pointer,&bitmap8bit,0,0,2,BITMAP_EXTRACT_MODE_CELL);  

// create the button bob
Create_BOB(&buttons,0,0,32,34,8,
           BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_FRAME,DDSCAPS_SYSTEMMEMORY);    

// load buttons in, two banks of 4, all the off's, then all the on's
for (index=0; index<8; index++)
     Load_Frame_BOB(&buttons,&bitmap8bit,index, index%4,index/4,BITMAP_EXTRACT_MODE_CELL);  

// create the bitmap to hold the control panel
Create_Bitmap(&cpanel,500,0,104,424);
Load_Image_Bitmap(&cpanel, &bitmap8bit,150,0,BITMAP_EXTRACT_MODE_ABS);

// create the drawing canvas bitmap
Create_Bitmap(&canvas,0,0,500,SCREEN_HEIGHT);
memset(canvas.buffer,0,canvas.width*canvas.height);
canvas.attr = BITMAP_ATTR_LOADED;

// clear out the canvas
// memset(canvas.buffer,0,canvas.width*canvas.height);

// set clipping rectangle to screen extents so mouse cursor
// doens't mess up at edges
RECT screen_rect = {0,0,screen_width,screen_height};
lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);

// hide the mouse
ShowCursor(FALSE);

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms)
{
// this function is where you do all the initialization 
// for your game

int index; // looping varsIable

char filename[80]; // used to build up filenames

// seed random number generate
srand(Start_Clock());

// start up DirectDraw (replace the parms as you desire)
DDraw_Init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP);

// load background image
Load_Bitmap_File(&bitmap8bit, "TANKGRID.BMP");
Create_Bitmap(&background_bmp,0,0,640,480);
Load_Image_Bitmap(&background_bmp, &bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Set_Palette(bitmap8bit.palette);
Unload_Bitmap_File(&bitmap8bit);


// hide the mouse
ShowCursor(FALSE);

// initialize directinput
DInput_Init();

// acquire the keyboard only
DInput_Init_Keyboard();

// initilize DirectSound
DSound_Init();

// load background sounds
cannon_ids[0] = DSound_Load_WAV("CANNON.WAV");

// clone sounds
for (index=1; index < 8; index++)
    cannon_ids[index] = DSound_Replicate_Sound(cannon_ids[0]);

// define points of cannon
VERTEX2DF cannon_vertices[4] =  { 0,-2, 30,0, 30,2, 0,2, };

// initialize ship
cannon.state       = 1;   // turn it on
cannon.num_verts   = 4;  
cannon.x0          = CANNON_X0; // position it
cannon.y0          = CANNON_Y0;
cannon.xv          = 0;
cannon.yv          = 0;
cannon.color       = 250; // green
cannon.vlist       = new VERTEX2DF [cannon.num_verts];
 
for (index = 0; index < cannon.num_verts; index++)
    cannon.vlist[index] = cannon_vertices[index];

// build the 360 degree look ups
Build_Sin_Cos_Tables();

// initialize the missiles
Init_Projectiles();

// set clipping rectangle to screen extents so objects dont
// mess up at edges
RECT screen_rect = {0,0,screen_width,screen_height};
lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);

// set clipping region
min_clip_x = 0;
max_clip_x = screen_width - 1;
min_clip_y = 0;
max_clip_y = screen_height - 1;

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms)
{
// this function is where you do all the initialization 
// for your game

int index; // looping variable

// initialize directdraw, very important that in the call
// to setcooperativelevel that the flag DDSCL_MULTITHREADED is used
// which increases the response of directX graphics to
// take the global critical section more frequently
DDraw_Init(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

// load background image
Load_Bitmap_File(&bitmap16bit, "FLYBACK_24.BMP");
Create_Bitmap(&background_bmp,0,0,640,480,16);
Load_Image_Bitmap16(&background_bmp, &bitmap16bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);

// load the fly bitmaps
Load_Bitmap_File(&bitmap16bit, "FLYS8_24.BMP");

// create master fly bob
Create_BOB(&flys[0],320,200, 8,8, 4, BOB_ATTR_MULTI_FRAME | BOB_ATTR_VISIBLE, DDSCAPS_SYSTEMMEMORY, 0, 16);
Set_Anim_Speed_BOB(&flys[0], 1);

// load the fly in 
for (index=0; index<4; index++)
    Load_Frame_BOB16(&flys[0], &bitmap16bit, index, index, 0, BITMAP_EXTRACT_MODE_CELL);

// unload flys
Unload_Bitmap_File(&bitmap16bit);

// now replicate flys
for (index = 1; index < MAX_FLYS; index++)
    Clone_BOB(&flys[0], &flys[index]);

// now set all of their values
for (index=0; index<MAX_FLYS; index++)
    {
    // set positions
    Set_Pos_BOB(&flys[index], 320-32+rand()%64, 450-rand()%32);

    // set start frame randomly
    flys[index].curr_frame = 0;

    } // end for index

// initilize DirectSound
DSound_Init();

// load fly sound
fly_sound_id = DSound_Load_WAV("FLYS.WAV");

// start the sound
DSound_Play(fly_sound_id, DSBPLAY_LOOPING);

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms)
{
// this function is where you do all the initialization 
// for your game

int index; // looping var

// start up DirectDraw (replace the parms as you desire)
DDraw_Init(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

// initialize directinput
DInput_Init();

// acquire the keyboard 
DInput_Init_Keyboard();

// initialize the joystick
DInput_Init_Joystick(-24,24,-24,24);

// initialize directsound and directmusic
DSound_Init();
DMusic_Init();

// hide the mouse
ShowCursor(FALSE);

// seed random number generator
srand(Start_Clock());

// load the background
Load_Bitmap_File(&bitmap8bit, "MUSH.BMP");

// set the palette to background image palette
Set_Palette(bitmap8bit.palette);

// load in the four frames of the mushroom
for (index=0; index<4; index++)
    {
    // create mushroom bitmaps
    Create_Bitmap(&mushrooms[index],0,0,32,32);
    Load_Image_Bitmap(&mushrooms[index],&bitmap8bit,index,0,BITMAP_EXTRACT_MODE_CELL);  
    } // end for index

// now create the bug blaster bob
Create_BOB(&blaster,0,0,32,32,3,
           BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_ANIM | BOB_ATTR_ANIM_ONE_SHOT,
           DDSCAPS_SYSTEMMEMORY);

// load in the four frames of the mushroom
for (index=0; index<3; index++)
     Load_Frame_BOB(&blaster,&bitmap8bit,index,index,1,BITMAP_EXTRACT_MODE_CELL);  

// unload the bitmap file
Unload_Bitmap_File(&bitmap8bit);

// set the animation sequences for bug blaster
Load_Animation_BOB(&blaster,0,5,blaster_anim);

// set up stating state of bug blaster
Set_Pos_BOB(&blaster,320, 400);
Set_Anim_Speed_BOB(&blaster,3);

// set clipping rectangle to screen extents so objects dont
// mess up at edges
RECT screen_rect = {0,0,screen_width,screen_height};
lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);

// create mushroom playfield bitmap
Create_Bitmap(&playfield,0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
playfield.attr |= BITMAP_ATTR_LOADED;

// fill in the background
Load_Bitmap_File(&bitmap8bit, "GRASS.BMP");

// load the grass bitmap image
Load_Image_Bitmap(&playfield,&bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap8bit);

// create the random mushroom patch
for (index=0; index<50; index++)
    {
    // select a mushroom
    int mush = rand()%4;

    // set mushroom to random position
    mushrooms[mush].x = rand()%(SCREEN_WIDTH-32);
    mushrooms[mush].y = rand()%(SCREEN_HEIGHT-128);

    // now draw the mushroom into playfield
    Draw_Bitmap(&mushrooms[mush], playfield.buffer, playfield.width,1);

    } // end for

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms)
{
// this function is where you do all the initialization 
// for your game

int index; // looping varsIable

char filename[80]; // used to build up filenames

// seed random number generate
srand(Start_Clock());

// initialize directdraw, very important that in the call
// to setcooperativelevel that the flag DDSCL_MULTITHREADED is used
// which increases the response of directX graphics to
// take the global critical section more frequently
DDraw_Init(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

// load background image
Load_Bitmap_File(&bitmap16bit, "LAVA24.BMP");
Create_Bitmap(&background_bmp,0,0,640,480,16);
Load_Image_Bitmap16(&background_bmp, &bitmap16bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);

// load the bitmaps
Load_Bitmap_File(&bitmap16bit, "LAVASHIP24.BMP");

// create ship
Create_BOB(&ship,0,0,80,32,2,BOB_ATTR_MULTI_FRAME | BOB_ATTR_VISIBLE, DDSCAPS_SYSTEMMEMORY,0,16);

// load the imagery in
for (index=0; index < 2; index++)
    Load_Frame_BOB16(&ship, &bitmap16bit, index, index,0,BITMAP_EXTRACT_MODE_CELL);

// unload bitmap image
Unload_Bitmap_File(&bitmap16bit);

// position the ship to left of screen

// use element 0,1 to hold float accurate position
ship.varsF[SHIP_X_POS] = 0;
ship.varsF[SHIP_Y_POS] = screen_height/2;

// use index 2 to hold x velocity
ship.varsF[SHIP_X_VEL] = SHIP_INITIAL_VELOCITY; 

// hide the mouse
if (!WINDOWED_APP)
   ShowCursor(FALSE);

// initialize directinput
DInput_Init();

// acquire the keyboard only
DInput_Init_Keyboard();

// initilize DirectSound
DSound_Init();

// load background sounds
engine_id = DSound_Load_WAV("PULSAR.WAV");

// start the sounds
DSound_Play(engine_id, DSBPLAY_LOOPING);


// return success
return(1);

} // end Game_Init
int Game_Init(void *parms,  int num_parms)
{
// this function is where you do all the initialization 
// for your game

int index;         // looping var
char filename[80]; // used to build up files names

// initialize directdraw
DDraw_Init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP);


#if 0 // directinput7 method

// first create the direct input object
if (DirectInputCreateEx(main_instance,DIRECTINPUT_VERSION,IID_IDirectInput7, (void **)&lpdi,NULL)!=DI_OK)
   return(0);

// create a keyboard device  //////////////////////////////////
if (lpdi->CreateDeviceEx(GUID_SysKeyboard, IID_IDirectInputDevice7, (void **)&lpdikey, NULL)!=DI_OK)
   return(0);

#endif


// first create the direct input object
if (DirectInput8Create(main_instance,DIRECTINPUT_VERSION,IID_IDirectInput8, (void **)&lpdi,NULL)!=DI_OK)
   return(0);

// create a keyboard device  //////////////////////////////////
if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdikey, NULL)!=DI_OK)
   return(0);


// set cooperation level
if (lpdikey->SetCooperativeLevel(main_window_handle, 
                 DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
    return(0);

// set data format
if (lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK)
   return(0);

// acquire the keyboard
if (lpdikey->Acquire()!=DI_OK)
   return(0);

///////////////////////////////////////////////////////////

// load the background
Load_Bitmap_File(&bitmap8bit, "REACTOR.BMP");

// set the palette to background image palette
Set_Palette(bitmap8bit.palette);

// create and load the reactor bitmap image
Create_Bitmap(&reactor, 0,0, 640, 480);
Load_Image_Bitmap(&reactor,&bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap8bit);

// now let's load in all the frames for the skelaton!!!

// create skelaton bob
if (!Create_BOB(&skelaton,0,0,56,72,32,
           BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_ANIM,DDSCAPS_SYSTEMMEMORY))
   return(0);

// load the frames in 8 directions, 4 frames each
// each set of frames has a walk and a fire, frame sets
// are loaded in counter clockwise order looking down
// from a birds eys view or the x-z plane
for (int direction = 0; direction < 8; direction++)
    { 
    // build up file name
    sprintf(filename,"SKELSP%d.BMP",direction);

    // load in new bitmap file
    Load_Bitmap_File(&bitmap8bit,filename);
 
    Load_Frame_BOB(&skelaton,&bitmap8bit,0+direction*4,0,0,BITMAP_EXTRACT_MODE_CELL);  
    Load_Frame_BOB(&skelaton,&bitmap8bit,1+direction*4,1,0,BITMAP_EXTRACT_MODE_CELL);  
    Load_Frame_BOB(&skelaton,&bitmap8bit,2+direction*4,2,0,BITMAP_EXTRACT_MODE_CELL);  
    Load_Frame_BOB(&skelaton,&bitmap8bit,3+direction*4,0,1,BITMAP_EXTRACT_MODE_CELL);  

    // unload the bitmap file
    Unload_Bitmap_File(&bitmap8bit);

    // set the animation sequences for skelaton
    Load_Animation_BOB(&skelaton,direction,4,skelaton_anims[direction]);

    } // end for direction

// set up stating state of skelaton
Set_Animation_BOB(&skelaton, 0);
Set_Anim_Speed_BOB(&skelaton, 4);
Set_Vel_BOB(&skelaton, 0,0);
Set_Pos_BOB(&skelaton, 0, 128);

// set clipping rectangle to screen extents so mouse cursor
// doens't mess up at edges
RECT screen_rect = {0,0,screen_width,screen_height};
lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);

// hide the mouse
ShowCursor(FALSE);

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms)
{
// this function is where you do all the initialization 
// for your game

int index; // looping var

// start up DirectDraw (replace the parms as you desire)
DDraw_Init(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

// initialize directinput
DInput_Init();

// acquire the keyboard 
DInput_Init_Keyboard();

// add calls to acquire other directinput devices here...

// initialize directsound and directmusic
DSound_Init();
DMusic_Init();

// hide the mouse
if (!WINDOWED_APP)
    ShowCursor(FALSE);

// seed random number generator
srand(Start_Clock()); 

Open_Error_File("ERROR.TXT");

// initialize math engine
Build_Sin_Cos_Tables();

// initialize the camera with 90 FOV, normalized coordinates
Init_CAM4DV1(&cam,            // the camera object
             CAM_MODEL_EULER, // the euler model
             &cam_pos,        // initial camera position
             &cam_dir,        // initial camera angles
             &cam_target,     // no target
             40.0,            // near and far clipping planes
             12000.0,
             90.0,            // field of view in degrees
             WINDOW_WIDTH,    // size of final screen viewport
             WINDOW_HEIGHT);

VECTOR4D terrain_pos = {0,0,0,0};

Generate_Terrain_OBJECT4DV2(&obj_terrain,            // pointer to object
                            TERRAIN_WIDTH,           // width in world coords on x-axis
                            TERRAIN_HEIGHT,          // height (length) in world coords on z-axis
                            TERRAIN_SCALE,           // vertical scale of terrain
                            "checkerheight01.bmp",  // filename of height bitmap encoded in 256 colors
                            "checker256256.bmp",   // filename of texture map
                             RGB16Bit(255,255,255),  // color of terrain if no texture        
                             &terrain_pos,           // initial position
                             NULL,                   // initial rotations
                             POLY4DV2_ATTR_RGB16  
                             | POLY4DV2_ATTR_SHADE_MODE_FLAT 
                             // | POLY4DV2_ATTR_SHADE_MODE_GOURAUD
                             | POLY4DV2_ATTR_SHADE_MODE_TEXTURE);

// the shading attributes we would like


// set up lights
Reset_Lights_LIGHTV2(lights2, MAX_LIGHTS);

// create some working colors
white.rgba = _RGBA32BIT(255,255,255,0);
gray.rgba  = _RGBA32BIT(100,100,100,0);
black.rgba = _RGBA32BIT(0,0,0,0);
red.rgba   = _RGBA32BIT(255,0,0,0);
green.rgba = _RGBA32BIT(0,255,0,0);
blue.rgba  = _RGBA32BIT(0,0,255,0);

// ambient light
Init_Light_LIGHTV2(lights2,
                   AMBIENT_LIGHT_INDEX,   
                   LIGHTV2_STATE_ON,      // turn the light on
                   LIGHTV2_ATTR_AMBIENT,  // ambient light type
                   gray, black, black,    // color for ambient term only
                   NULL, NULL,            // no need for pos or dir
                   0,0,0,                 // no need for attenuation
                   0,0,0);                // spotlight info NA

VECTOR4D dlight_dir = {-1,1,-1,1};

// directional light
Init_Light_LIGHTV2(lights2,
                   INFINITE_LIGHT_INDEX,  
                   LIGHTV2_STATE_ON,      // turn the light on
                   LIGHTV2_ATTR_INFINITE, // infinite light type
                   black, gray, black,    // color for diffuse term only
                   NULL, &dlight_dir,     // need direction only
                   0,0,0,                 // no need for attenuation
                   0,0,0);                // spotlight info NA


VECTOR4D plight_pos = {0,200,0,1};

// point light
Init_Light_LIGHTV2(lights2,
                   POINT_LIGHT_INDEX,
                   LIGHTV2_STATE_ON,      // turn the light on
                   LIGHTV2_ATTR_POINT,    // pointlight type
                   black, green, black,   // color for diffuse term only
                   &plight_pos, NULL,     // need pos only
                   0,.001,0,              // linear attenuation only
                   0,0,1);                // spotlight info NA


// point light
Init_Light_LIGHTV2(lights2,
                   POINT_LIGHT2_INDEX,
                   LIGHTV2_STATE_ON,     // turn the light on
                   LIGHTV2_ATTR_POINT,   // pointlight type
                   black, blue, black,   // color for diffuse term only
                   &plight_pos, NULL,    // need pos only
                   0,.002,0,            // linear attenuation only
                   0,0,1);               // spotlight info NA

VECTOR4D slight2_pos = {0,200,0,1};
VECTOR4D slight2_dir = {-1,1,-1,1};


// create lookup for lighting engine
RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565,  // format we want to build table for
                                  palette,             // source palette
                                  rgblookup);          // lookup table

// create the z buffer
Create_Zbuffer(&zbuffer,
               WINDOW_WIDTH,
               WINDOW_HEIGHT,
               ZBUFFER_ATTR_32BIT);


// load background sounds
wind_sound_id = DSound_Load_WAV("WIND.WAV");

// start the sounds
DSound_Play(wind_sound_id, DSBPLAY_LOOPING);
DSound_Set_Volume(wind_sound_id, 100);

#if 0
// load in the cockpit image
Load_Bitmap_File(&bitmap16bit, "lego01.BMP");
Create_BOB(&cockpit, 0,0,800,600,1, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 16); 
Load_Frame_BOB16(&cockpit, &bitmap16bit,0,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);
#endif

// set single precission
//_control87( _PC_24, MCW_PC );

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms)
{
// this function is where you do all the initialization
// for your game

    int index; // looping var

// start up DirectDraw (replace the parms as you desire)
    DDraw_Init2(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP,1);

// initialize directinput
    DInput_Init();

// acquire the keyboard
    DInput_Init_Keyboard();

// add calls to acquire other directinput devices here...

// initialize directsound and directmusic
    DSound_Init();
    DMusic_Init();

// hide the mouse
    if (!WINDOWED_APP)
        ShowCursor(FALSE);

// seed random number generator
    srand(Start_Clock());

    Open_Error_File("ERROR.TXT");

// initialize math engine
    Build_Sin_Cos_Tables();

// initialize the camera with 90 FOV, normalized coordinates
    Init_CAM4DV1(&cam,      // the camera object
                 CAM_MODEL_EULER, // the euler model
                 &cam_pos,  // initial camera position
                 &cam_dir,  // initial camera angles
                 &cam_target,      // no target
                 10.0,        // near and far clipping planes
                 12000.0,
                 120.0,      // field of view in degrees
                 WINDOW_WIDTH,   // size of final screen viewport
                 WINDOW_HEIGHT);

// set a scaling vector
    VECTOR4D_INITXYZ(&vscale,20.00,20.00,20.00);

// load all the objects in
    for (int index_obj=0; index_obj < NUM_OBJECTS; index_obj++)
    {
        Load_OBJECT4DV2_COB2(&obj_array[index_obj], object_filenames[index_obj],
                             &vscale, &vpos, &vrot, VERTEX_FLAGS_SWAP_YZ
                             | VERTEX_FLAGS_TRANSFORM_LOCAL
                             // | VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD
                             | VERTEX_FLAGS_INVERT_TEXTURE_V
                             ,0 );

    } // end for index_obj

// set current object
    curr_object = 0;
    obj_work = &obj_array[curr_object];

// position the scenery objects randomly
    for (index = 0; index < NUM_SCENE_OBJECTS; index++)
    {
        // set master object link
        scene_objects[index].obj = obj_work;

        // randomly position object
        scene_objects[index].pos.x = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
        scene_objects[index].pos.y = RAND_RANGE(-200, 200);
        scene_objects[index].pos.z = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
        scene_objects[index].rot.y = RAND_RANGE(0,360);
        scene_objects[index].auxi[0] = RAND_RANGE(1,5);

        // set state of object container
        scene_objects[index].state = ((OBJECT4DV2_PTR)scene_objects[index].obj)->state;

        // set attributes
        scene_objects[index].attr = ((OBJECT4DV2_PTR)scene_objects[index].obj)->attr;
    } // end for

// set up lights
    Reset_Lights_LIGHTV2(lights2, MAX_LIGHTS);

// create some working colors
    white.rgba = _RGBA32BIT(255,255,255,0);
    gray.rgba  = _RGBA32BIT(150,150,150,0);
    black.rgba = _RGBA32BIT(0,0,0,0);
    red.rgba   = _RGBA32BIT(255,0,0,0);
    green.rgba = _RGBA32BIT(0,255,0,0);
    blue.rgba  = _RGBA32BIT(0,0,255,0);

// ambient light
    Init_Light_LIGHTV2(lights2,               // array of lights to work with
                       AMBIENT_LIGHT_INDEX,
                       LIGHTV2_STATE_ON,      // turn the light on
                       LIGHTV2_ATTR_AMBIENT,  // ambient light type
                       gray, black, black,    // color for ambient term only
                       NULL, NULL,            // no need for pos or dir
                       0,0,0,                 // no need for attenuation
                       0,0,0);                // spotlight info NA

    VECTOR4D dlight_dir = {-1,0,-1,1};

// directional light
    Init_Light_LIGHTV2(lights2,               // array of lights to work with
                       INFINITE_LIGHT_INDEX,
                       LIGHTV2_STATE_ON,      // turn the light on
                       LIGHTV2_ATTR_INFINITE, // infinite light type
                       black, gray, black,    // color for diffuse term only
                       NULL, &dlight_dir,     // need direction only
                       0,0,0,                 // no need for attenuation
                       0,0,0);                // spotlight info NA


    VECTOR4D plight_pos = {0,200,0,1};

// point light
    Init_Light_LIGHTV2(lights2,               // array of lights to work with
                       POINT_LIGHT_INDEX,
                       LIGHTV2_STATE_ON,      // turn the light on
                       LIGHTV2_ATTR_POINT,    // pointlight type
                       black, green, black,    // color for diffuse term only
                       &plight_pos, NULL,     // need pos only
                       0,.002,0,              // linear attenuation only
                       0,0,1);                // spotlight info NA


    VECTOR4D slight2_pos = {0,1000,0,1};
    VECTOR4D slight2_dir = {-1,0,-1,1};

// spot light2
    Init_Light_LIGHTV2(lights2,                  // array of lights to work with
                       SPOT_LIGHT2_INDEX,
                       LIGHTV2_STATE_ON,         // turn the light on
                       LIGHTV2_ATTR_SPOTLIGHT2,  // spot light type 2
                       black, red, black,        // color for diffuse term only
                       &slight2_pos, &slight2_dir, // need pos only
                       0,.001,0,                 // linear attenuation only
                       0,0,1);


// create lookup for lighting engine
    RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565,  // format we want to build table for
                                      palette,             // source palette
                                      rgblookup);          // lookup table

// create the z buffer
    Create_Zbuffer(&zbuffer,
                   WINDOW_WIDTH,
                   WINDOW_HEIGHT,
                   ZBUFFER_ATTR_32BIT);

// create the alpha lookup table
    RGB_Alpha_Table_Builder(NUM_ALPHA_LEVELS, rgb_alpha_table);

// load in the background
    Create_BOB(&background, 0,0,800,600,1, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 16);
    Load_Bitmap_File(&bitmap16bit, "nebblue01.bmp");
    Load_Frame_BOB16(&background, &bitmap16bit,0,0,0,BITMAP_EXTRACT_MODE_ABS);
    Unload_Bitmap_File(&bitmap16bit);

// build the bounding hierarchical volume tree with 3 divisions per level
    BHV_Build_Tree(&bhv_tree,
                   scene_objects,
                   NUM_SCENE_OBJECTS,
                   0,
                   3,
                   UNIVERSE_RADIUS);

// return success
    return(1);

} // end Game_Init
int Game_Init(void *parms,  int num_parms)
{
// this function is where you do all the initialization 
// for your game

int index;         // looping var
char filename[80]; // used to build up files names

// start up DirectDraw (replace the parms as you desire)
DDraw_Init(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

// joystick creation section ////////////////////////////////

/// start up DirectInput
DInput_Init();

// initialize the joystick
DInput_Init_Joystick(-24,24,-24,24);

///////////////////////////////////////////////////////////

// load the background
Load_Bitmap_File(&bitmap16bit, "MUSH_24.BMP");

// load in the four frames of the mushroom
for (index=0; index<4; index++)
    {
    // create mushroom bitmaps
    Create_Bitmap(&mushrooms[index],0,0,32,32,16);
    Load_Image_Bitmap16(&mushrooms[index],&bitmap16bit,index,0,BITMAP_EXTRACT_MODE_CELL);  
    } // end for index

// now create the bug blaster bob
Create_BOB(&blaster,0,0,32,32,3,
           BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_ANIM | BOB_ATTR_ANIM_ONE_SHOT,
           DDSCAPS_SYSTEMMEMORY,0,16);

// load in the four frames of the mushroom
for (index=0; index < 3; index++)
     Load_Frame_BOB16(&blaster,&bitmap16bit,index,index,1,BITMAP_EXTRACT_MODE_CELL);  

// unload the bitmap file
Unload_Bitmap_File(&bitmap16bit);

// set the animation sequences for bug blaster
Load_Animation_BOB(&blaster,0,5,blaster_anim);

// set up stating state of bug blaster
Set_Pos_BOB(&blaster,320, 400);
Set_Anim_Speed_BOB(&blaster,3);

// create mushroom playfield bitmap
Create_Bitmap(&playfield,0,0,SCREEN_WIDTH,SCREEN_HEIGHT, 16);
playfield.attr |= BITMAP_ATTR_LOADED;

// fill in the background
Load_Bitmap_File(&bitmap16bit, "GRASS_24.BMP");

// load the grass bitmap image
Load_Image_Bitmap16(&playfield,&bitmap16bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);

// seed random number generator
srand(Start_Clock());

// create the random mushroom patch
for (index=0; index<50; index++)
    {
    // select a mushroom
    int mush = rand()%4;

    // set mushroom to random position
    mushrooms[mush].x = rand()%(SCREEN_WIDTH-32);
    mushrooms[mush].y = rand()%(SCREEN_HEIGHT-128);

    // now draw the mushroom into playfield
    Draw_Bitmap16(&mushrooms[mush], playfield.buffer, playfield.width*2,1);

    } // end for

// hide the mouse
if (!WINDOWED_APP)
    ShowCursor(FALSE);

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms)
{
// this function is where you do all the initialization 
// for your game

int index; // looping var

// start up DirectDraw (replace the parms as you desire)
DDraw_Init2(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP,0);

// initialize directinput
DInput_Init();

// acquire the keyboard 
DInput_Init_Keyboard();

// add calls to acquire other directinput devices here...

// initialize directsound and directmusic
DSound_Init();
DMusic_Init();

// hide the mouse
if (!WINDOWED_APP)
    ShowCursor(FALSE);

// seed random number generator
srand(Start_Clock()); 

Open_Error_File("MD2ERROR.TXT");

// initialize math engine
Build_Sin_Cos_Tables();

// initialize the camera with 90 FOV, normalized coordinates
Init_CAM4DV1(&cam,            // the camera object
             CAM_MODEL_EULER, // the euler model
             &cam_pos,        // initial camera position
             &cam_dir,        // initial camera angles
             &cam_target,     // no target
             10.0,            // near and far clipping planes
             12000.0,
             90.0,            // field of view in degrees
             WINDOW_WIDTH,    // size of final screen viewport
             WINDOW_HEIGHT);

VECTOR4D terrain_pos = {0,0,0,0}; 

Generate_Terrain_OBJECT4DV2(&obj_terrain,            // pointer to object
                            TERRAIN_WIDTH,           // width in world coords on x-axis
                            TERRAIN_HEIGHT,          // height (length) in world coords on z-axis
                            TERRAIN_SCALE,           // vertical scale of terrain
                            "height_grass_40_40_01.bmp",  // filename of height bitmap encoded in 256 colors
                            "stone256_256_01.bmp", // "grass256_256_01.bmp", //"checker2562562.bmp",   // filename of texture map
                             RGB16Bit(255,255,255),  // color of terrain if no texture        
                             &terrain_pos,           // initial position
                             NULL,                   // initial rotations
                             POLY4DV2_ATTR_RGB16  
                             //| POLY4DV2_ATTR_SHADE_MODE_FLAT 
                             | POLY4DV2_ATTR_SHADE_MODE_GOURAUD
                             | POLY4DV2_ATTR_SHADE_MODE_TEXTURE);


// set a scaling vector
VECTOR4D_INITXYZ(&vscale, 20, 20, 20); 

// load all the light objects in
for (int index_obj=0; index_obj < NUM_LIGHT_OBJECTS; index_obj++)
    {
    Load_OBJECT4DV2_COB2(&obj_light_array[index_obj], object_light_filenames[index_obj],  
                        &vscale, &vpos, &vrot, VERTEX_FLAGS_INVERT_WINDING_ORDER 
                                               | VERTEX_FLAGS_TRANSFORM_LOCAL 
                                               | VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD
                                              ,0 );
    } // end for index
   
// set current object
curr_light_object = 0;
obj_light    = &obj_light_array[curr_light_object];


// set up lights
Reset_Lights_LIGHTV2(lights2, MAX_LIGHTS);

// create some working colors
white.rgba   = _RGBA32BIT(255,255,255,0);
gray.rgba    = _RGBA32BIT(100,100,100,0);
black.rgba   = _RGBA32BIT(0,0,0,0);
red.rgba     = _RGBA32BIT(255,0,0,0);
green.rgba   = _RGBA32BIT(0,255,0,0);
blue.rgba    = _RGBA32BIT(0,0,255,0);
orange.rgba  = _RGBA32BIT(255,128,0,0);
yellow.rgba  = _RGBA32BIT(255,255,0,0);

// ambient light
Init_Light_LIGHTV2(lights2,
                   AMBIENT_LIGHT_INDEX,   
                   LIGHTV2_STATE_ON,      // turn the light on
                   LIGHTV2_ATTR_AMBIENT,  // ambient light type
                   gray, black, black,    // color for ambient term only
                   NULL, NULL,            // no need for pos or dir
                   0,0,0,                 // no need for attenuation
                   0,0,0);                // spotlight info NA

VECTOR4D dlight_dir = {-1,1,-1,1};

// directional light
Init_Light_LIGHTV2(lights2,
                   INFINITE_LIGHT_INDEX,  
                   LIGHTV2_STATE_ON,      // turn the light on
                   LIGHTV2_ATTR_INFINITE, // infinite light type
                   black, gray, black,    // color for diffuse term only
                   NULL, &dlight_dir,     // need direction only
                   0,0,0,                 // no need for attenuation
                   0,0,0);                // spotlight info NA


VECTOR4D plight_pos = {0,500,0,1};

// point light
Init_Light_LIGHTV2(lights2,
                   POINT_LIGHT_INDEX,
                   LIGHTV2_STATE_ON,      // turn the light on
                   LIGHTV2_ATTR_POINT,    // pointlight type
                   black, orange, black,   // color for diffuse term only
                   &plight_pos, NULL,     // need pos only
                   0,.001,0,              // linear attenuation only
                   0,0,1);                // spotlight info NA


// point light
Init_Light_LIGHTV2(lights2,
                   POINT_LIGHT2_INDEX,
                   LIGHTV2_STATE_ON,     // turn the light on
                   LIGHTV2_ATTR_POINT,   // pointlight type
                   black, yellow, black,  // color for diffuse term only
                   &plight_pos, NULL,    // need pos only
                   0,.002,0,             // linear attenuation only
                   0,0,1);               // spotlight info NA

VECTOR4D slight2_pos = {0,200,0,1};
VECTOR4D slight2_dir = {-1,1,-1,1};


// create lookup for lighting engine
RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565,  // format we want to build table for
                                  palette,             // source palette
                                  rgblookup);          // lookup table

// create the z buffer
Create_Zbuffer(&zbuffer,
               WINDOW_WIDTH,
               WINDOW_HEIGHT,
               ZBUFFER_ATTR_32BIT);
 

// build alpha lookup table
RGB_Alpha_Table_Builder(NUM_ALPHA_LEVELS, rgb_alpha_table);

// load background sounds
wind_sound_id = DSound_Load_WAV("STATIONTHROB.WAV");

// start the sounds
DSound_Play(wind_sound_id, DSBPLAY_LOOPING);
DSound_Set_Volume(wind_sound_id, 100);

#if 0
// load in the cockpit image
Create_BOB(&cockpit, 0,0,800,600,2, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 16); 
Load_Bitmap_File(&bitmap16bit, "lego02.BMP");
Load_Frame_BOB16(&cockpit, &bitmap16bit,0,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);

Load_Bitmap_File(&bitmap16bit, "lego02b.BMP");
Load_Frame_BOB16(&cockpit, &bitmap16bit,1,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);
#endif

// load background image that scrolls 
Load_Bitmap_File(&bitmap16bit, "sunset800_600_03.bmp");
Create_Bitmap(&background_bmp,0,0,800,600,16);
Load_Image_Bitmap16(&background_bmp, &bitmap16bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);


static VECTOR4D vs = {4,4,4,1};
static VECTOR4D vp = {0,0,0,1};

// load the md2 object
Load_Object_MD2(&obj_md2,                            // the loaded md2 file placed in container
     "./md2/q2mdl-tekkblade/tris.md2", //  "D:/Games/quakeII/baseq2/players/male/tris.md2",    // the filename of the .MD2 model
     &vs, 
     &vp,
     NULL,          
     "./md2/q2mdl-tekkblade/blade_black.bmp", //"D:/Games/quakeII/baseq2/players/male/claymore.bmp",   // the texture filename for the model
     POLY4DV2_ATTR_RGB16 | POLY4DV2_ATTR_SHADE_MODE_FLAT | POLY4DV2_ATTR_SHADE_MODE_TEXTURE,
     RGB16Bit(255,255,255),
     VERTEX_FLAGS_SWAP_YZ);                          // control ordering etc.

// prepare OBJECT4DV2 for md2
Prepare_OBJECT4DV2_For_MD2(&obj_model,   // pointer to destination object
                           &obj_md2);    // md2 object to extract frame from

// set the animation
Set_Animation_MD2(&obj_md2,MD2_ANIM_STATE_STANDING_IDLE, MD2_ANIM_LOOP);

#if 0
// play with these for more speed :)
// set single precission
_control87( _PC_24, _MCW_PC );

// set to flush mode
_control87( _DN_FLUSH, _MCW_DN );

// set rounding mode
_control87( _RC_NEAR, _MCW_RC );

#endif

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms,  int num_parms)
{
// this function is where you do all the initialization 
// for your game

int index;         // looping var
char filename[80]; // used to build up files names

// start up DirectDraw (replace the parms as you desire)
DDraw_Init(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

// joystick creation section ////////////////////////////////

// first create the direct input object
if (DirectInput8Create(main_instance,DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&lpdi,NULL)!=DI_OK)
   return(0);

// first find the f*****g GUID of your particular joystick
lpdi->EnumDevices(DI8DEVCLASS_GAMECTRL, 
                  DI_Enum_Joysticks, 
                  &joystickGUID, 
                  DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK); 

if (lpdi->CreateDevice(joystickGUID, &lpdijoy, NULL)!=DI_OK)
   return(0);

// set cooperation level
if (lpdijoy->SetCooperativeLevel(main_window_handle, 
	                 DISCL_EXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
   return(0);

// set data format
if (lpdijoy->SetDataFormat(&c_dfDIJoystick2)!=DI_OK)
   return(0);

// set the range of the joystick
DIPROPRANGE joy_axis_range;

// first x axis
joy_axis_range.lMin = -32;
joy_axis_range.lMax = 32;

joy_axis_range.diph.dwSize       = sizeof(DIPROPRANGE); 
joy_axis_range.diph.dwHeaderSize = sizeof(DIPROPHEADER); 
joy_axis_range.diph.dwObj        = DIJOFS_X;
joy_axis_range.diph.dwHow        = DIPH_BYOFFSET;

lpdijoy->SetProperty(DIPROP_RANGE,&joy_axis_range.diph);

// now y-axis
joy_axis_range.lMin = -32;
joy_axis_range.lMax = 32;

joy_axis_range.diph.dwSize       = sizeof(DIPROPRANGE); 
joy_axis_range.diph.dwHeaderSize = sizeof(DIPROPHEADER); 
joy_axis_range.diph.dwObj        = DIJOFS_Y;
joy_axis_range.diph.dwHow        = DIPH_BYOFFSET;

lpdijoy->SetProperty(DIPROP_RANGE,&joy_axis_range.diph);

// and now the dead band

DIPROPDWORD dead_band; // here's our property word

dead_band.diph.dwSize       = sizeof(dead_band);
dead_band.diph.dwHeaderSize = sizeof(dead_band.diph);
dead_band.diph.dwObj        = DIJOFS_X;
dead_band.diph.dwHow        = DIPH_BYOFFSET;

// 4 will be used on both sides of the range +/-
dead_band.dwData            = 1000;

// finally set the property
lpdijoy->SetProperty(DIPROP_DEADZONE,&dead_band.diph);

dead_band.diph.dwSize       = sizeof(dead_band);
dead_band.diph.dwHeaderSize = sizeof(dead_band.diph);
dead_band.diph.dwObj        = DIJOFS_Y;
dead_band.diph.dwHow        = DIPH_BYOFFSET;

// 4 will be used on both sides of the range +/-
dead_band.dwData            = 1000;

// finally set the property
lpdijoy->SetProperty(DIPROP_DEADZONE,&dead_band.diph);


// acquire the joystick
if (lpdijoy->Acquire()!=DI_OK)
   return(0);


// force feedback setup
DWORD      dwAxes[2] = { DIJOFS_X, DIJOFS_Y };
LONG       lDirection[2] = { 0, 0 };


DIPERIODIC diPeriodic;      // type-specific parameters
DIENVELOPE diEnvelope;      // envelope
DIEFFECT   diEffect;        // general parameters

// setup the periodic structure
diPeriodic.dwMagnitude = DI_FFNOMINALMAX; 
diPeriodic.lOffset = 0; 
diPeriodic.dwPhase = 0; 
diPeriodic.dwPeriod = (DWORD) (0.05 * DI_SECONDS); 

// set the modulation envelope 
diEnvelope.dwSize = sizeof(DIENVELOPE);
diEnvelope.dwAttackLevel = 0; 
diEnvelope.dwAttackTime = (DWORD) (0.01 * DI_SECONDS); 
diEnvelope.dwFadeLevel = 0; 
diEnvelope.dwFadeTime = (DWORD) (3.0 * DI_SECONDS); 
 
// set up the effect structure itself
diEffect.dwSize = sizeof(DIEFFECT); 
diEffect.dwFlags = DIEFF_POLAR | DIEFF_OBJECTOFFSETS; 
diEffect.dwDuration = (DWORD) INFINITE; // (1 * DI_SECONDS);
 
// set up details of effect
diEffect.dwSamplePeriod = 0;               // = default 
diEffect.dwGain = DI_FFNOMINALMAX;         // no scaling
diEffect.dwTriggerButton = DIJOFS_BUTTON0; // connect effect to trigger button
diEffect.dwTriggerRepeatInterval = 0;      
diEffect.cAxes = 2; 
diEffect.rgdwAxes = dwAxes; 
diEffect.rglDirection = &lDirection[0]; 
diEffect.lpEnvelope = &diEnvelope; 
diEffect.cbTypeSpecificParams = sizeof(diPeriodic);
diEffect.lpvTypeSpecificParams = &diPeriodic;  
 
// create the effect and get the interface to it 
lpdijoy->CreateEffect(GUID_Square,  // standard GUID 
                     &diEffect,      // where the data is
                     &lpdieffect,    // where to put interface pointer
                     NULL);          // no aggregation


///////////////////////////////////////////////////////////

// load the background
Load_Bitmap_File(&bitmap16bit, "MUSH_24.BMP");

// load in the four frames of the mushroom
for (index=0; index<4; index++)
    {
    // create mushroom bitmaps
    Create_Bitmap(&mushrooms[index],0,0,32,32,16);
    Load_Image_Bitmap16(&mushrooms[index],&bitmap16bit,index,0,BITMAP_EXTRACT_MODE_CELL);  
    } // end for index

// now create the bug blaster bob
Create_BOB(&blaster,0,0,32,32,3,
           BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_ANIM | BOB_ATTR_ANIM_ONE_SHOT,
           DDSCAPS_SYSTEMMEMORY,0,16);

// load in the four frames of the mushroom
for (index=0; index<3; index++)
     Load_Frame_BOB16(&blaster,&bitmap16bit,index,index,1,BITMAP_EXTRACT_MODE_CELL);  

// unload the bitmap file
Unload_Bitmap_File(&bitmap16bit);

// set the animation sequences for bug blaster
Load_Animation_BOB(&blaster,0,5,blaster_anim);

// set up stating state of bug blaster
Set_Pos_BOB(&blaster,320, 400);
Set_Anim_Speed_BOB(&blaster,3);

// create mushroom playfield bitmap
Create_Bitmap(&playfield,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,16);
playfield.attr |= BITMAP_ATTR_LOADED;

// fill in the background
Load_Bitmap_File(&bitmap16bit, "GRASS_24.BMP");

// load the grass bitmap image
Load_Image_Bitmap16(&playfield,&bitmap16bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);

// seed random number generator
srand(Start_Clock());

// create the random mushroom patch
for (index=0; index<50; index++)
    {
    // select a mushroom
    int mush = rand()%4;

    // set mushroom to random position
    mushrooms[mush].x = rand()%(SCREEN_WIDTH-32);
    mushrooms[mush].y = rand()%(SCREEN_HEIGHT-128);

    // now draw the mushroom into playfield
    Draw_Bitmap16(&mushrooms[mush], playfield.buffer, playfield.width*2,1);

    } // end for

// hide the mouse
if (!WINDOWED_APP)
   ShowCursor(FALSE);

// return success
return(1);

} // end Game_Init
int Game_Init(void *parms)
{
// this function is where you do all the initialization 
// for your game

char filename[80]; // used to read files

// start up DirectDraw (replace the parms as you desire)
DDraw_Init(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

// initialize directinput
DInput_Init();

// acquire the keyboard 
DInput_Init_Keyboard();

// add calls to acquire other directinput devices here...


// initialize directsound and directmusic
DSound_Init();
DMusic_Init();

// hide the mouse
ShowCursor(FALSE);

// seed random number generator
srand(Start_Clock());

// all your initialization code goes here...

///////////////////////////////////////////////////////////

// load the background
Load_Bitmap_File(&bitmap8bit, "REACTOR.BMP");

// set the palette to background image palette
Set_Palette(bitmap8bit.palette);

// create and load the reactor bitmap image
Create_Bitmap(&reactor, 0,0, 640, 480);
Load_Image_Bitmap(&reactor,&bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap8bit);

// now let's load in all the frames for the skelaton!!!

// create skelaton bob
if (!Create_BOB(&skelaton,0,0,56,72,32,
           BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_ANIM,DDSCAPS_SYSTEMMEMORY))
   return(0);

// load the frames in 8 directions, 4 frames each
// each set of frames has a walk and a fire, frame sets
// are loaded in counter clockwise order looking down
// from a birds eys view or the x-z plane
for (int direction = 0; direction < 8; direction++)
    { 
    // build up file name
    sprintf(filename,"SKELSP%d.BMP",direction);

    // load in new bitmap file
    Load_Bitmap_File(&bitmap8bit,filename);
 
    Load_Frame_BOB(&skelaton,&bitmap8bit,0+direction*4,0,0,BITMAP_EXTRACT_MODE_CELL);  
    Load_Frame_BOB(&skelaton,&bitmap8bit,1+direction*4,1,0,BITMAP_EXTRACT_MODE_CELL);  
    Load_Frame_BOB(&skelaton,&bitmap8bit,2+direction*4,2,0,BITMAP_EXTRACT_MODE_CELL);  
    Load_Frame_BOB(&skelaton,&bitmap8bit,3+direction*4,0,1,BITMAP_EXTRACT_MODE_CELL);  

    // unload the bitmap file
    Unload_Bitmap_File(&bitmap8bit);

    // set the animation sequences for skelaton
    Load_Animation_BOB(&skelaton,direction,4,skelaton_anims[direction]);

    } // end for direction

// set up stating state of skelaton
Set_Animation_BOB(&skelaton, 0);
Set_Anim_Speed_BOB(&skelaton, 4);
Set_Vel_BOB(&skelaton, 0,0);
Set_Pos_BOB(&skelaton, 0, 128);

// return success
return(1);

} // end Game_Init
Exemple #23
0
int Game_Init(void *parms = NULL, int num_parms = 0)
{
// this is called once after the initial window is created and
// before the main event loop is entered, do all your initialization
// here

// create IDirectDraw interface 7.0 object and test for error
if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
   return(0);

// set cooperation to full screen
if (FAILED(lpdd->SetCooperativeLevel(main_window_handle, 
                                      DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | 
                                      DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
   return(0);

// set display mode to 640x480x24
if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0)))
   return(0);

// clear ddsd and set size
DDRAW_INIT_STRUCT(ddsd); 

// enable valid fields
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;

ddsd.dwBackBufferCount = 1;

//
// request primary surface
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;

// create the primary surface
if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL)))
   return(0);

ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;

if(FAILED(lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsback))) return 0;



// 把主屏和缓冲屏都填充为黑色初始化
DDraw_Fill_Surface(lpddsprimary, _RGB32BIT(0, 0,0,0));
DDraw_Fill_Surface(lpddsback, _RGB32BIT(0, 0,0,0));

// load the 24-bit image
char* bmp_wc = "WarCraft24.bmp";
char* bmp_b8 = "bitmap8b.bmp";
char* bmp_b24 = "bitmap24.bmp";
char* bmp_b24e = "bitmap24_edit.bmp";

char* bmp_mo24 = "mosaic-600x.bmp";
char* bmp_ni24 = "nightelf-640x.bmp";
char* bmp_alley24 = "alley8_24bit.bmp";




// 载入背景图片
if (!Load_Bitmap_File(&bitmap, bmp_ni24))
   return(0);


// 创建背景表面、但实际上不是直接用背景表面来显示的、而是拷贝去缓冲表面和人物动作混合
// 后才一次性打到显示表面
// 这里头两个参数是指在屏幕的高和宽、第二个是指表面建立的地点、0指在显存建立、其它表示在
// 系统内存建立、当然速度自然是在显存建立快了、最后一个参数是是否设置为色彩键、这里设定为-1
// 也就是不设定任何色彩过滤、因为这个是背景表面、所以不需要任何透明的色彩键
lpddsbackground = DDraw_Create_Surface(640,480,0,-1);


// 把bmp的内容拷贝至缓冲表面中
Bmp2Surface(lpddsbackground, SCREEN_WIDTH, SCREEN_HEIGHT);












// 从现在开始创建人物动作了
if (!Load_Bitmap_File(&bitmap, "Dedsp0_24bit.bmp"))
   return(0);


// seed random number generator
// GetTickCount是一个系统启动至今的毫秒数、
// 配合srandg来产生一个随机数
srand(GetTickCount());

// initialize all the aliens

// alien on level 1 of complex

//
//系统在调用rand()之前都会自动调用srand(),如果用户在rand()之前曾调用过srand()给参数seed指定了一个值,
//那么rand()就会将seed的值作为产生伪随机数的初始值;
//而如果用户在rand()前没有调用过srand(),那么rand()就会自动调用srand(1),即系统默认将1作为伪随机数的初始值。
//所以前面要调用一次srand来确保以下调用rand()的值会产生不同
//
aliens[0].x              = rand()%SCREEN_WIDTH;
aliens[0].y              = 116 - 72;                  
aliens[0].velocity       = 2+rand()%4;
aliens[0].current_frame  = 0;             
aliens[0].counter        = 0;       

// alien on level 2 of complex

aliens[1].x              = rand()%SCREEN_WIDTH;
aliens[1].y              = 246 - 72;                  
aliens[1].velocity       = 2+rand()%4;
aliens[1].current_frame  = 0;             
aliens[1].counter        = 0;  

// alien on level 3 of complex

aliens[2].x              = rand()%SCREEN_WIDTH;
aliens[2].y              = 382 - 72;                  
aliens[2].velocity       = 2+rand()%4;
aliens[2].current_frame  = 0;             
aliens[2].counter        = 0;  




// now load the bitmap containing the alien imagery
// then scan the images out into the surfaces of alien[0]
// and copy then into the other two, be careful of reference counts!

// 现在开始载入人物的动画帧图片了
if (!Load_Bitmap_File(&bitmap,"Dedsp0_24bit.bmp"))
   return(0);


// create each surface and load bits
// 初始化异形0号的三个动作帧表面、
// 其实、所有的异形动作帧表面都一样的、所以没有必要为每个异形都创建相应的动作帧、
// 所以其它异形的动作帧都指向这个异形0号的动作帧就可以了
for (int index = 0; index < 3; index++)
    {
    // create surface to hold image
    aliens[0].frames[index] = DDraw_Create_Surface(72,80,0);

    // now load bits...
    Scan_Image_Bitmap(&bitmap,                 // bitmap file to scan image data from
                      aliens[0].frames[index], // surface to hold data
                      index, 0);               // cell to scan image from    

    } // end for index

// unload the bitmap file, we no longer need it
Unload_Bitmap_File(&bitmap);


// now for the tricky part. There is no need to create more surfaces with the same
// data, so I'm going to copy the surface pointers member for member to each alien
// however, be careful, since the reference counts do NOT go up, you still only need
// to release() each surface once!

for (index = 0; index < 3; index++)
    aliens[1].frames[index] = aliens[2].frames[index] = aliens[0].frames[index];


// return success or failure or your own return code here
return(1);

} // end Game_Init