int Game_Shutdown(void *parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated

// shut everything down

// release all your resources created for the game here....

// now directsound
DSound_Stop_All_Sounds();
DSound_Delete_All_Sounds();
DSound_Shutdown();

// directmusic
DMusic_Delete_All_MIDI();
DMusic_Shutdown();

// shut down directinput
DInput_Release_Keyboard();

// shutdown directinput
DInput_Shutdown();

// shutdown directdraw last
DDraw_Shutdown();

Close_Error_File();

// return success
return(1);
} // end Game_Shutdown
int Game_Shutdown(void *parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated

// shut everything down

// kill all the bobs
Destroy_BOB(&ship);
Destroy_BOB(&black_hole);

// shutdown directdraw last
DDraw_Shutdown();

// now directsound
DSound_Stop_All_Sounds();
DSound_Shutdown();

// shut down directinput
DInput_Shutdown();

// return success
return(1);

} // end Game_Shutdown
int Game_Shutdown(void *parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated

// shut everything down

// release all your resources created for the game here....

// kill the reactor
Destroy_Bitmap(&reactor);

// kill skelaton
Destroy_BOB(&skelaton);

// now directsound
DSound_Stop_All_Sounds();
DSound_Delete_All_Sounds();
DSound_Shutdown();

// directmusic
DMusic_Delete_All_MIDI();
DMusic_Shutdown();

// shut down directinput
DInput_Shutdown();

// shutdown directdraw last
DDraw_Shutdown();

// return success
return(1);
} // end Game_Shutdown
int Game_Shutdown(void *parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated

// shut everything down

// kill all the bobs
for (int index=0; index<NUM_BALLS; index++)
    Destroy_BOB(&balls[index]);

// shutdown directdraw last
DDraw_Shutdown();

// now directsound
DSound_Stop_All_Sounds();
DSound_Shutdown();

// shut down directinput
DInput_Shutdown();

// return success
return(1);

} // end Game_Shutdown
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

// check of user is trying to exit
if (KEY_DOWN(VK_ESCAPE))
   {
   PostMessage(main_window_handle, WM_DESTROY,0,0);

   // stop all sounds
   DSound_Stop_All_Sounds();
   } // end if

// start the timing clock
Start_Clock();

// clear the drawing surface
DDraw_Fill_Surface(lpddsback, 0);

// lock back buffer and copy background into it
DDraw_Lock_Back_Surface();

// draw background
Draw_Bitmap16(&background_bmp, back_buffer, back_lpitch,0);

// unlock back surface
DDraw_Unlock_Back_Surface();

// process the fly ai, move them buzz around dead bodies
Flys_AI();

// draw the flys
for (index=0; index < MAX_FLYS; index++)
     Draw_BOB16(&flys[index], lpddsback);

// flip the surfaces
DDraw_Flip();

// sync to 30ish fps
Wait_Clock(30);

// return success
return(1);

} // end Game_Main
Exemple #6
0
int DSound_Shutdown(void)
{
   // this function releases all the memory allocated and the directsound object
   // itself

   // first turn all sounds off
   DSound_Stop_All_Sounds();

   // now release all sound buffers
   for (int index=0; index<MAX_SOUNDS; index++)
	   if (sound_fx[index].dsbuffer)
		   sound_fx[index].dsbuffer->Release();

   // now release the directsound interface itself
   if (lpds)
      lpds->Release();
   return(1);
} 
int Game_Shutdown(void *parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated

// shut everything down

// release all your resources created for the game here....
// kill the bug blaster
Destroy_BOB(&blaster);

// kill the mushroom maker
for (int index=0; index<4; index++)
    Destroy_Bitmap(&mushrooms[index]);

// kill the playfield bitmap
Destroy_Bitmap(&playfield);

// now directsound
DSound_Stop_All_Sounds();
DSound_Delete_All_Sounds();
DSound_Shutdown();

// directmusic
DMusic_Delete_All_MIDI();
DMusic_Shutdown();

// shut down directinput
DInput_Release_Keyboard();
DInput_Release_Joystick();

DInput_Shutdown();

// shutdown directdraw last
DDraw_Shutdown();

// return success
return(1);
} // end Game_Shutdown
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 int delay = 30; // initial delay per frame

// start the timing clock
DWORD start_time = 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);

// unlock back surface
DDraw_Unlock_Back_Surface();

// read keyboard
DInput_Read_Keyboard();

// update delay
if (keyboard_state[DIK_RIGHT]) 
   delay+=5;
else
if (delay > 5 && keyboard_state[DIK_LEFT]) 
   delay-=5;


// draw the ship
ship.x = ship.varsF[SHIP_X_POS]+0.5;
ship.y = ship.varsF[SHIP_Y_POS]+0.5;
ship.curr_frame = 0;
Draw_BOB(&ship, lpddsback);

// draw shadow
ship.curr_frame = 1;
ship.x-=64;
ship.y+=128;
Draw_BOB(&ship, lpddsback);

// draw the title
Draw_Text_GDI("(16-Bit Version) Time Based Kinematic Motion DEMO, Press <ESC> to Exit.",10, 10,RGB(255,255,255), lpddsback);

sprintf(buffer, "Frame rate = %f, use <RIGHT>, <LEFT> arrows to change load", 1000*1/(float)delay );
Draw_Text_GDI(buffer,10, 25,RGB(255,255,255), lpddsback);

sprintf(buffer,"Ship Velocity is %f pixels/sec",1000*ship.varsF[SHIP_X_VEL]);
Draw_Text_GDI(buffer,10, 40,RGB(255,255,255), lpddsback);

// this models the load in the game
Wait_Clock(delay);

// flip the surfaces
DDraw_Flip();

// move the ship based on time //////////////////////////////////
// x = x + v*dt

// compute dt
float dt = Get_Clock() - start_time; // in milliseconds

// move based on 30 pixels per seconds or .03 pixels per millisecond
ship.varsF[SHIP_X_POS]+=(ship.varsF[SHIP_X_VEL]*dt);

// test for off screen
if (ship.varsF[SHIP_X_POS] > screen_width+ship.width)
   ship.varsF[SHIP_X_POS] = -ship.width;

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

// 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
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

// start the timing clock
Start_Clock();

// clear the drawing surface
//DDraw_Fill_Surface(lpddsback, 0);

// lock back buffer and copy background into it
DDraw_Lock_Back_Surface();

// draw background
Draw_Bitmap16(&background_bmp, back_buffer, back_lpitch,0);

// draw table
HLine16(TABLE_MIN_X, TABLE_MAX_X, TABLE_MIN_Y, RGB16Bit(0,255,0), back_buffer, back_lpitch);
HLine16(TABLE_MIN_X, TABLE_MAX_X, TABLE_MAX_Y, RGB16Bit(0,255,0), back_buffer, back_lpitch);
VLine16(TABLE_MIN_Y, TABLE_MAX_Y, TABLE_MIN_X, RGB16Bit(0,255,0), back_buffer, back_lpitch);
VLine16(TABLE_MIN_Y, TABLE_MAX_Y, TABLE_MAX_X, RGB16Bit(0,255,0), back_buffer, back_lpitch);


// unlock back surface
DDraw_Unlock_Back_Surface();

// read keyboard
DInput_Read_Keyboard();


// check for change of e
if (keyboard_state[DIK_RIGHT])
    cof_E+=.01;
else
if (keyboard_state[DIK_LEFT])
    cof_E-=.01;

float total_ke_x = 0, total_ke_y = 0;

// move all the balls and compute system momentum
for (index=0; index < NUM_BALLS; index++)
    {
    // move the ball
    balls[index].varsF[INDEX_X]+=balls[index].varsF[INDEX_XV];
    balls[index].varsF[INDEX_Y]+=balls[index].varsF[INDEX_YV];

    // add x,y contributions to kinetic energy
    total_ke_x+=(balls[index].varsF[INDEX_XV]*balls[index].varsF[INDEX_XV]*balls[index].varsF[INDEX_MASS]);
    total_ke_y+=(balls[index].varsF[INDEX_YV]*balls[index].varsF[INDEX_YV]*balls[index].varsF[INDEX_MASS]);

    } // end fof
    
// test for boundary collision with virtual table edge, no need for collision
// response here, I know what's going to happen :)
for (index=0; index < NUM_BALLS; index++)
    {
    if ((balls[index].varsF[INDEX_X] >= TABLE_MAX_X-BALL_RADIUS) || 
        (balls[index].varsF[INDEX_X] <= TABLE_MIN_X+BALL_RADIUS))
        {
        // invert velocity
        balls[index].varsF[INDEX_XV] = -balls[index].varsF[INDEX_XV];

        balls[index].varsF[INDEX_X]+=balls[index].varsF[INDEX_XV];
        balls[index].varsF[INDEX_Y]+=balls[index].varsF[INDEX_YV];

        // start a hit sound
        Ball_Sound();

        } // end if

    if ((balls[index].varsF[INDEX_Y] >= TABLE_MAX_Y-BALL_RADIUS) || 
        (balls[index].varsF[INDEX_Y] <= TABLE_MIN_Y+BALL_RADIUS))
        {
        // invert velocity
        balls[index].varsF[INDEX_YV] =-balls[index].varsF[INDEX_YV];

        balls[index].varsF[INDEX_X]+=balls[index].varsF[INDEX_XV];
        balls[index].varsF[INDEX_Y]+=balls[index].varsF[INDEX_YV];

        // play sound
        Ball_Sound();

        } // end if

    } // end for index

// 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) ELASTIC Object-Object Collision Response DEMO, Press <ESC> to Exit.",10, 10,RGB(255,255,255), lpddsback);

// draw the title
sprintf(buffer,"Coefficient of Restitution e=%f, use <RIGHT>, <LEFT> arrow to change.", cof_E);
Draw_Text_GDI(buffer,10, 30,RGB(255,255,255), lpddsback);

sprintf(buffer,"Total System Kinetic Energy Sum(1/2MiVi^2)=%f ",0.5*sqrt(total_ke_x*total_ke_x+total_ke_y*total_ke_y));
Draw_Text_GDI(buffer,10, 465, RGB(255,255,255), lpddsback);


// flip the surfaces
DDraw_Flip();

// run collision response algorithm here
Collision_Response();

// 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
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
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 int   curr_angle = 0; // current angle of elevation from horizon
static float curr_vel   = 10; // current velocity of projectile

// start the timing clock
Start_Clock();

// clear the drawing surface
//DDraw_Fill_Surface(lpddsback, 0);

// lock back buffer and copy background into it
DDraw_Lock_Back_Surface();

// draw background
Draw_Bitmap(&background_bmp, back_buffer, back_lpitch,0);

// do the graphics
Draw_Polygon2D(&cannon, back_buffer, back_lpitch);

// unlock back surface
DDraw_Unlock_Back_Surface();

// read keyboard
DInput_Read_Keyboard();

// test for rotate
if ((curr_angle < 90) && keyboard_state[DIK_UP]) // rotate left
   {
   Rotate_Polygon2D_Mat(&cannon, -5);
   curr_angle+=5;
   } // end if
else
if ((curr_angle > 0) &&keyboard_state[DIK_DOWN]) // rotate right
   {
   Rotate_Polygon2D_Mat(&cannon, 5);
   curr_angle-=5;
   } // end if

// test for projectile velocity
if (keyboard_state[DIK_RIGHT])  
   { 
   if (curr_vel < 30) curr_vel+=0.1;
   } // end if
else
if (keyboard_state[DIK_LEFT]) 
   { 
   if (curr_vel > 0) curr_vel-=0.1;
   } // end if

// test for wind force
if (keyboard_state[DIK_W])  
   { 
   if (wind_force < 2) wind_force+=0.01;
   } // end if
else
if (keyboard_state[DIK_E]) 
   { 
   if (wind_force > -2) wind_force-=0.01;
   } // end if

// test for gravity force
if (keyboard_state[DIK_G])  
   { 
   if (gravity_force < 15) gravity_force+=0.1;
   } // end if
else
if (keyboard_state[DIK_B]) 
   { 
   if (gravity_force > -15) gravity_force-=0.1;
   } // end if

// test for fire!
if (keyboard_state[DIK_LCONTROL]) 
   { 
   Fire_Projectile(curr_angle, curr_vel);

   } // end fire

// move all the projectiles
Move_Projectiles();

// draw the projectiles
Draw_Projectiles();

// draw the title
Draw_Text_GDI("Trajectory DEMO, Press <ESC> to Exit.",10, 10,RGB(255,255,255), lpddsback);
Draw_Text_GDI("<RIGHT>, <LEFT> to adjust velocity, <UP>, <DOWN> to adjust angle",10, 25, RGB(255,255,255), lpddsback);
Draw_Text_GDI("<G>, <B> to adjust gravity, <W>, <E> to adjust wind, <CTRL> to fire.",10, 40, RGB(255,255,255), lpddsback);

sprintf(buffer, "Ang=%d, Vel=%f", curr_angle, curr_vel);
Draw_Text_GDI(buffer,10, 60, RGB(255,255,255), lpddsback);

sprintf(buffer, "Wind force=%f, Gravity Force=%f", wind_force, gravity_force);
Draw_Text_GDI(buffer,10, 75, RGB(255,255,255), lpddsback);

// flip the surfaces
DDraw_Flip();

// 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();

    // do a screen transition
    Screen_Transitions(SCREEN_DARKNESS,NULL,0);
    } // end if

// return success
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

// start the timing clock
Start_Clock();

// clear the drawing surface
DDraw_Fill_Surface(lpddsback, 0);

// lock back buffer and copy background into it
DDraw_Lock_Back_Surface();

// draw background
Draw_Bitmap(&background_bmp, back_buffer, back_lpitch,0);

// unlock back surface
DDraw_Unlock_Back_Surface();

// read keyboard
DInput_Read_Keyboard();


// check the player controls

// is the player turning right or left?
if (keyboard_state[DIK_RIGHT])
   {
    // there are 16 possible positions for the ship to point in
    if (++ship.varsI[0] >= 16)
        ship.varsI[0] = 0;
   } // end if
else
if (keyboard_state[DIK_LEFT])
   {
    // there are 16 possible positions for the ship to point in
    if (--ship.varsI[0] < 0)
        ship.varsI[0] = 15;
   } // end if

// now test for forward thrust
if (keyboard_state[DIK_UP])
    {
    // thrust ship in current direction
    
    float rad_angle = (float)ship.varsI[0]*(float)3.14159/(float)8;
    float xv = cos(rad_angle);
    float yv = sin(rad_angle);

    ship.varsF[0]+=xv;
    ship.varsF[1]+=yv;

    // animate the ship
    ship.curr_frame = ship.varsI[0]+16*(rand()%2);

    } // end if
else // show non thrust version
   ship.curr_frame = ship.varsI[0];  

// move ship
ship.varsF[2]+=ship.varsF[0];
ship.varsF[3]+=ship.varsF[1];

// always apply friction in direction opposite current trajectory
float fx = -ship.varsF[0];
float fy = -ship.varsF[1];
float length_f = sqrt(fx*fx+fy*fy); // normally we would avoid square root at all costs!

// compute the frictional resitance

if (fabs(length_f) > 0.1)
    { 
    fx = FRICTION_FACTOR*fx/length_f;
    fy = FRICTION_FACTOR*fy/length_f;
    } // end if
else
    fx=fy=0;

// now apply friction to forward velocity
ship.varsF[0]+=fx;
ship.varsF[1]+=fy;

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

// gravity calculation section

// step 1: compute vector from black hole to ship, note that the centers
// of each object are used
float grav_x = (black_hole.x + black_hole.width/2)  - (ship.x + ship.width/2);
float grav_y = (black_hole.y + black_hole.height/2) - (ship.y + ship.height/2);
float radius_squared = grav_x*grav_x + grav_y*grav_y; // equal to radius squared
float length_grav = sqrt(radius_squared);

// step 2: normalize the length of the vector to 1.0
grav_x = grav_x/length_grav;
grav_y = grav_y/length_grav;

// step 3: compute the gravity force
float grav_force = (VIRTUAL_GRAVITY_CONSTANT) * (SHIP_MASS * BLACK_HOLE_MASS) / radius_squared;

// step 4: apply gforce in the direction of grav_x, grav_y with the magnitude of grav_force
ship.varsF[0]+=grav_x*grav_force;
ship.varsF[1]+=grav_y*grav_force;

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

// test if ship is off screen
if (ship.varsF[2] > SCREEN_WIDTH)
   ship.varsF[2] = -ship.width;
else
if (ship.varsF[2] < -ship.width)
   ship.varsF[2] = SCREEN_WIDTH;

if (ship.varsF[3] > SCREEN_HEIGHT)
   ship.varsF[3] = -ship.height;
else
if (ship.varsF[3] < -ship.height)
   ship.varsF[3] = SCREEN_HEIGHT;

// test if velocity is insane
if ( (ship.varsF[0]*ship.varsF[0] + ship.varsF[1]*ship.varsF[1]) > MAX_VEL)
   {
   // scale velocity down
   ship.varsF[0]*=.95;
   ship.varsF[1]*=.95;

   } // end if

// animate the black hole
Animate_BOB(&black_hole);

// draw the black hole
Draw_BOB(&black_hole, lpddsback);

// copy floating point position to bob x,y
ship.x = ship.varsF[2];
ship.y = ship.varsF[3];

// draw the ship
Draw_BOB(&ship,lpddsback);

// draw the title
Draw_Text_GDI("GRAVITY MASS DEMO - Use Arrows to Control Ship.",10, 10,RGB(0,255,255), lpddsback);

sprintf(buffer,"Friction: X=%f, Y=%f",fx, fy);
Draw_Text_GDI(buffer,10,420,RGB(0,255,0), lpddsback);

sprintf(buffer,"Velocity: X=%f, Y=%f",ship.varsF[0], ship.varsF[1]);
Draw_Text_GDI(buffer,10,440,RGB(0,255,0), lpddsback);

sprintf(buffer,"Gravity: X=%f, Y=%f",ship.varsF[2], ship.varsF[3]);
Draw_Text_GDI(buffer,10,460,RGB(0,255,0), lpddsback);

// flip the surfaces
DDraw_Flip();

// 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();

    // do a screen transition
    Screen_Transitions(SCREEN_DARKNESS,NULL,0);
    } // end if

// return success
return(1);

} // end Game_Main