?? demo9_1a_16b.cpp
字號:
// create skelaton bob
if (!Create_BOB(&skelaton,0,0,56,72,32,
BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_ANIM,DDSCAPS_SYSTEMMEMORY,0,16))
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_24.BMP",direction);
// load in new bitmap file
Load_Bitmap_File(&bitmap16bit,filename);
Load_Frame_BOB16(&skelaton,&bitmap16bit,0+direction*4,0,0,BITMAP_EXTRACT_MODE_CELL);
Load_Frame_BOB16(&skelaton,&bitmap16bit,1+direction*4,1,0,BITMAP_EXTRACT_MODE_CELL);
Load_Frame_BOB16(&skelaton,&bitmap16bit,2+direction*4,2,0,BITMAP_EXTRACT_MODE_CELL);
Load_Frame_BOB16(&skelaton,&bitmap16bit,3+direction*4,0,1,BITMAP_EXTRACT_MODE_CELL);
// unload the bitmap file
Unload_Bitmap_File(&bitmap16bit);
// 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);
// 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 reactor
Destroy_Bitmap(&reactor);
// kill skelaton
Destroy_BOB(&skelaton);
// release keyboard
DInput_Release_Keyboard();
// 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
static int player_moving = 0; // tracks player motion
// 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);
// lock the back buffer
DDraw_Lock_Back_Surface();
// draw the background reactor image
Draw_Bitmap16(&reactor, back_buffer, back_lpitch, 0);
// unlock the back buffer
DDraw_Unlock_Back_Surface();
// get player input
// get the keyboard data
lpdikey->GetDeviceState(256, (LPVOID)keyboard_state);
// reset motion flag
player_moving = 0;
// test direction of motion, this is a good example of testing the keyboard
// although the code could be optimized this is more educational
if (keyboard_state[DIK_RIGHT] && keyboard_state[DIK_UP])
{
// move skelaton
skelaton.x+=2;
skelaton.y-=2;
dx=2; dy=-2;
// set motion flag
player_moving = 1;
// check animation needs to change
if (skelaton.curr_animation != SKELATON_NEAST)
Set_Animation_BOB(&skelaton,SKELATON_NEAST);
} // end if
else
if (keyboard_state[DIK_LEFT] && keyboard_state[DIK_UP])
{
// move skelaton
skelaton.x-=2;
skelaton.y-=2;
dx=-2; dy=-2;
// set motion flag
player_moving = 1;
// check animation needs to change
if (skelaton.curr_animation != SKELATON_NWEST)
Set_Animation_BOB(&skelaton,SKELATON_NWEST);
} // end if
else
if (keyboard_state[DIK_LEFT] && keyboard_state[DIK_DOWN])
{
// move skelaton
skelaton.x-=2;
skelaton.y+=2;
dx=-2; dy=2;
// set motion flag
player_moving = 1;
// check animation needs to change
if (skelaton.curr_animation != SKELATON_SWEST)
Set_Animation_BOB(&skelaton,SKELATON_SWEST);
} // end if
else
if (keyboard_state[DIK_RIGHT] && keyboard_state[DIK_DOWN])
{
// move skelaton
skelaton.x+=2;
skelaton.y+=2;
dx=2; dy=2;
// set motion flag
player_moving = 1;
// check animation needs to change
if (skelaton.curr_animation != SKELATON_SEAST)
Set_Animation_BOB(&skelaton,SKELATON_SEAST);
} // end if
else
if (keyboard_state[DIK_RIGHT])
{
// move skelaton
skelaton.x+=2;
dx=2; dy=0;
// set motion flag
player_moving = 1;
// check animation needs to change
if (skelaton.curr_animation != SKELATON_EAST)
Set_Animation_BOB(&skelaton,SKELATON_EAST);
} // end if
else
if (keyboard_state[DIK_LEFT])
{
// move skelaton
skelaton.x-=2;
dx=-2; dy=0;
// set motion flag
player_moving = 1;
// check animation needs to change
if (skelaton.curr_animation != SKELATON_WEST)
Set_Animation_BOB(&skelaton,SKELATON_WEST);
} // end if
else
if (keyboard_state[DIK_UP])
{
// move skelaton
skelaton.y-=2;
dx=0; dy=-2;
// set motion flag
player_moving = 1;
// check animation needs to change
if (skelaton.curr_animation != SKELATON_NORTH)
Set_Animation_BOB(&skelaton,SKELATON_NORTH);
} // end if
else
if (keyboard_state[DIK_DOWN])
{
// move skelaton
skelaton.y+=2;
dx=0; dy=+2;
// set motion flag
player_moving = 1;
// check animation needs to change
if (skelaton.curr_animation != SKELATON_SOUTH)
Set_Animation_BOB(&skelaton,SKELATON_SOUTH);
} // end if
// only animate if player is moving
if (player_moving)
{
// animate skelaton
Animate_BOB(&skelaton);
// see if skelaton hit a wall
// lock surface, so we can scan it
DDraw_Lock_Back_Surface();
// call the color scanner with WALL_COLOR the color of the walls
// try to center the scan on the feet of the player
// note since we are uin 16-bit mode, we need to scan the 16 bit value then compare
// it against the 16-bit color code for the green pixel which has values RB(41,231,41)
// but depending if this is a 5.5.5 or 5.6.5 the 16-bit value will be different, however
// during ddraw_init RGB16Bit() was vectored (function pointer) to either 5.5.5 or 5.6.5
// depending on the actual surface mode, so it should all work out :)
if (Color_Scan16(skelaton.x+16, skelaton.y+16,
skelaton.x+skelaton.width-16, skelaton.y+skelaton.height-16,
RGB16Bit(WALL_COLOR_R, WALL_COLOR_G, WALL_COLOR_B),
RGB16Bit(WALL_COLOR_R, WALL_COLOR_G, WALL_COLOR_B), back_buffer,back_lpitch))
{
// back the skelaton up along its last trajectory
skelaton.x-=dx;
skelaton.y-=dy;
} // end if
// done, so unlock
DDraw_Unlock_Back_Surface();
// check if skelaton is off screen
if (skelaton.x < 0 || skelaton.x > (screen_width - skelaton.width))
skelaton.x-=dx;
if (skelaton.y < 0 || skelaton.y > (screen_height - skelaton.height))
skelaton.y-=dy;
} // end if
// draw the skelaton
Draw_BOB16(&skelaton, lpddsback);
// draw some text
Draw_Text_GDI("I STILL HAVE A BONE TO PICK!",0,screen_height - 32,RGB(32,32,32),lpddsback);
Draw_Text_GDI("(16-Bit Version) USE ARROW KEYS TO MOVE, <ESC> TO EXIT.",0,0,RGB(32,32,32),lpddsback);
// flip the surfaces
DDraw_Flip();
// sync to 30 fps
Wait_Clock(30);
// return success
return(1);
} // end Game_Main
//////////////////////////////////////////////////////////
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -