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 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 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) { // 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 200.0, // near and far clipping planes 12000.0, 120.0, // field of view in degrees WINDOW_WIDTH, // size of final screen viewport WINDOW_HEIGHT); // load flat shaded cube VECTOR4D_INITXYZ(&vscale,20.00,20.00,20.00); Load_OBJECT4DV2_COB(&obj_flat_cube,"cube_flat_textured_01.cob", &vscale, &vpos, &vrot, VERTEX_FLAGS_SWAP_YZ | VERTEX_FLAGS_TRANSFORM_LOCAL | VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD ); // set up lights Reset_Lights_LIGHTV1(); // 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_LIGHTV1(AMBIENT_LIGHT_INDEX, LIGHTV1_STATE_ON, // turn the light on LIGHTV1_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,0}; // directional light Init_Light_LIGHTV1(INFINITE_LIGHT_INDEX, LIGHTV1_STATE_ON, // turn the light on LIGHTV1_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,0}; // point light Init_Light_LIGHTV1(POINT_LIGHT_INDEX, LIGHTV1_STATE_ON, // turn the light on LIGHTV1_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 VECTOR4D slight2_pos = {0,200,0,0}; VECTOR4D slight2_dir = {-1,0,-1,0}; // spot light2 Init_Light_LIGHTV1(SPOT_LIGHT2_INDEX, LIGHTV1_STATE_ON, // turn the light on LIGHTV1_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 // 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 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()); // 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