?? demo9_3a_16b.cpp
字號:
// return success
return(1);
} // end if
// couldn't start missile
return(0);
} // end Start_Missile
///////////////////////////////////////////////////////////
int Move_Missile(void)
{
// this function moves the missle
// test if missile is alive
if (missile_state==1)
{
// move the missile upward
if ((missile_y-=10) < 0)
{
missile_state = 0;
return(1);
} // end if
// lock secondary buffer
DDraw_Lock_Back_Surface();
// add missile collision here
// unlock surface
DDraw_Unlock_Back_Surface();
// return success
return(1);
} // end if
// return failure
return(0);
} // end Move_Missle
///////////////////////////////////////////////////////////
int Draw_Missile(void)
{
// this function draws the missile
// test if missile is alive
if (missile_state==1)
{
// lock secondary buffer
DDraw_Lock_Back_Surface();
// draw the missile in green
Draw_Clip_Line16(missile_x, missile_y,
missile_x, missile_y+6,
RGB16Bit(255,255,255),back_buffer, back_lpitch);
// unlock surface
DDraw_Unlock_Back_Surface();
// return success
return(1);
} // end if
// return failure
return(0);
} // end Draw_Missle
///////////////////////////////////////////////////////////
// GAME PROGRAMMING CONSOLE FUNCTIONS ////////////////
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_Shutdown(void *parms, int num_parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated
// 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);
// release joystick
DInput_Release_Joystick();
// shutdown DirectInput
DInput_Shutdown();
// shutdonw directdraw
DDraw_Shutdown();
// return success
return(1);
} // end Game_Shutdown
///////////////////////////////////////////////////////////
int Game_Main(void *parms, int num_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
int dx,dy; // general deltas used in collision detection
// check of user is trying to exit
if (KEY_DOWN(VK_ESCAPE) || KEY_DOWN(VK_SPACE))
PostMessage(main_window_handle, WM_DESTROY,0,0);
// start the timing clock
Start_Clock();
// clear the drawing surface
DDraw_Fill_Surface(lpddsback, 0);
// get the joystick data
DInput_Read_Joystick();
// lock the back buffer
DDraw_Lock_Back_Surface();
// draw the background reactor image
Draw_Bitmap16(&playfield, back_buffer, back_lpitch, 0);
// unlock the back buffer
DDraw_Unlock_Back_Surface();
// is the player moving?
blaster.x+=joy_state.lX;
blaster.y+=joy_state.lY;
// test bounds
if (blaster.x > SCREEN_WIDTH-32)
blaster.x = SCREEN_WIDTH-32;
else
if (blaster.x < 0)
blaster.x = 0;
if (blaster.y > SCREEN_HEIGHT-32)
blaster.y = SCREEN_HEIGHT-32;
else
if (blaster.y < SCREEN_HEIGHT-128)
blaster.y = SCREEN_HEIGHT-128;
// is player firing?
if (joy_state.rgbButtons[0])
Start_Missile();
// move and draw missle
Move_Missile();
Draw_Missile();
// is it time to blink eyes
if ((rand()%100)==50)
Set_Animation_BOB(&blaster,0);
// draw blaster
Animate_BOB(&blaster);
Draw_BOB16(&blaster,lpddsback);
// draw some text
Draw_Text_GDI("(16-Bit Version) Make My Centipede!",0,0,RGB(255,255,255),lpddsback);
// display joystick and buttons 0-7
sprintf(buffer,"Joystick Stats: X-Axis=%d, Y-Axis=%d, buttons(%d,%d,%d,%d,%d,%d,%d,%d)",
joy_state.lX,joy_state.lY,
joy_state.rgbButtons[0],
joy_state.rgbButtons[1],
joy_state.rgbButtons[2],
joy_state.rgbButtons[3],
joy_state.rgbButtons[4],
joy_state.rgbButtons[5],
joy_state.rgbButtons[6],
joy_state.rgbButtons[7]);
Draw_Text_GDI(buffer,0,SCREEN_HEIGHT-20,RGB(255,255,50),lpddsback);
// print out name of joystick
sprintf(buffer, "Joystick Name & Vendor: %s",joyname);
Draw_Text_GDI(buffer,0,SCREEN_HEIGHT-40,RGB(255,255,50),lpddsback);
// flip the surfaces
DDraw_Flip();
// sync to 30 fps
Wait_Clock(30);
// return success
return(1);
} // end Game_Main
//////////////////////////////////////////////////////////
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -