int Game_Main(void *parms = NULL, int num_parms = 0) { // this is the main loop of the game, do all your processing // here // make sure this isn't executed again if (window_closed) return(0); // for now test if user is hitting ESC and send WM_CLOSE if (KEYDOWN(VK_ESCAPE)) { PostMessage(main_window_handle,WM_CLOSE,0,0); window_closed = 1; } // end if // clear out the back buffer DDraw_Fill_Surface(lpddsback, 0); // lock primary buffer DDRAW_INIT_STRUCT(ddsd); if (FAILED(lpddsback->Lock(NULL,&ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL))) return(0); // do the graphics Draw_Polygon2D(&asteroid, (UCHAR *)ddsd.lpSurface, ddsd.lPitch); // test for scale if (KEYDOWN('A')) // scale up Scale_Polygon2D(&asteroid, 1.1, 1.1); else if (KEYDOWN('S')) // scale down Scale_Polygon2D(&asteroid, 0.9, 0.9); // rotate the polygon by 5 degrees Rotate_Polygon2D(&asteroid, 5); // unlock primary buffer if (FAILED(lpddsback->Unlock(NULL))) return(0); // perform the flip while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT))); // wait a sec Sleep(33); // return success or failure or your own return code here return(1); } // end Game_Main
int Game_Main(void *parms = NULL, int num_parms = 0) { // this is the main loop of the game, do all your processing // here // make sure this isn't executed again if (window_closed) return(0); // for now test if user is hitting ESC and send WM_CLOSE if (KEYDOWN(VK_ESCAPE)) { PostMessage(main_window_handle,WM_CLOSE,0,0); window_closed = 1; } // end if // clear out the back buffer DDraw_Fill_Surface(lpddsback, 0); // lock primary buffer DDRAW_INIT_STRUCT(ddsd); if (FAILED(lpddsback->Lock(NULL,&ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL))) return(0); // draw all the asteroids for (int curr_index = 0; curr_index < NUM_ASTEROIDS; curr_index++) { // do the graphics Draw_Polygon2D(&asteroids[curr_index], (UCHAR *)ddsd.lpSurface, ddsd.lPitch); // move the asteroid Translate_Polygon2D(&asteroids[curr_index], asteroids[curr_index].xv, asteroids[curr_index].yv); // rotate the polygon by 5 degrees Rotate_Polygon2D(&asteroids[curr_index], 5); // test for out of bounds if (asteroids[curr_index].x0 > SCREEN_WIDTH+100) asteroids[curr_index].x0 = - 100; if (asteroids[curr_index].y0 > SCREEN_HEIGHT+100) asteroids[curr_index].y0 = - 100; if (asteroids[curr_index].x0 < -100) asteroids[curr_index].x0 = SCREEN_WIDTH+100; if (asteroids[curr_index].y0 < -100) asteroids[curr_index].y0 = SCREEN_HEIGHT+100; } // end for curr_asteroid // unlock primary buffer if (FAILED(lpddsback->Unlock(NULL))) return(0); // perform the flip while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT))); // wait a sec Sleep(33); // return success or failure or your own return code here return(1); } // end Game_Main
int Game_Main(void *parms) { // this is the workhorse of your game it will be called // continuously in real-time this is like main() in C // all the calls for you game go here! int index; // looping var static rotate = 0; // start the timing clock Start_Clock(); // lock back buffer and copy background into it DDraw_Lock_Back_Surface(); // draw background Draw_Bitmap16(&background_bmp, back_buffer, back_lpitch,0); // draw shape Draw_Polygon2D16(&shape, back_buffer, back_lpitch); // have a little fun if (++rotate > 10) { Rotate_Polygon2D(&shape,1); rotate=0; } // unlock back surface DDraw_Unlock_Back_Surface(); // read keyboard DInput_Read_Keyboard(); // move the balls and compute collisions Compute_Collisions(); // draw the balls for (index=0; index < NUM_BALLS; index++) { balls[index].x = balls[index].varsF[INDEX_X]+0.5-BALL_RADIUS; balls[index].y = balls[index].varsF[INDEX_Y]+0.5-BALL_RADIUS; Draw_BOB16(&balls[index], lpddsback); } // end for // draw the velocity vectors DDraw_Lock_Back_Surface(); for (index=0; index < NUM_BALLS; index++) { Draw_Clip_Line16(balls[index].varsF[INDEX_X]+0.5, balls[index].varsF[INDEX_Y]+0.5, balls[index].varsF[INDEX_X]+2*balls[index].varsF[INDEX_XV]+0.5, balls[index].varsF[INDEX_Y]+2*balls[index].varsF[INDEX_YV]+0.5, RGB16Bit(255,255,255), back_buffer, back_lpitch); } // end for DDraw_Unlock_Back_Surface(); // draw the title Draw_Text_GDI("(16-Bit Version) Object to Contour Collision DEMO, Press <ESC> to Exit.",10, 10,RGB(255,255,255), lpddsback); // flip the surfaces DDraw_Flip(); // run collision algorithm here Compute_Collisions(); // sync to 30 fps = 1/30sec = 33 ms Wait_Clock(33); // check of user is trying to exit if (KEY_DOWN(VK_ESCAPE) || keyboard_state[DIK_ESCAPE]) { PostMessage(main_window_handle, WM_DESTROY,0,0); // stop all sounds DSound_Stop_All_Sounds(); } // end if // return success return(1); } // end Game_Main