comicz
小水手

UID 21754
精华
0
积分 1
帖子 1
阅读权限 10
注册 2006-5-25
状态 离线
|
一个段代码,大家帮我看看
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_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
//////////////////////////////////////////////////////////
void Start_Explosion(int tie)
{
// this starts an explosion based on the sent tie fighter
// first hunt and see if an explosion is free
for (int index=0; index < NUM_EXPLOSIONS; index++)
{
if (explosions[index].state==0)
{
// start this explosion up using the properties
// if the tie figther index sent
explosions[index].state = 1; // enable state of explosion
explosions[index].counter = 0; // reset counter for explosion
// set color of explosion
explosions[index].color = rgb_green;
// make copy of of edge list, so we can blow it up
for (int edge=0; edge < NUM_TIE_EDGES; edge++)
{
// start point of edge
explosions[index].p1[edge].x = ties[tie].x+tie_vlist[tie_shape[edge].v1].x;
explosions[index].p1[edge].y = ties[tie].y+tie_vlist[tie_shape[edge].v1].y;
explosions[index].p1[edge].z = ties[tie].z+tie_vlist[tie_shape[edge].v1].z;
// end point of edge
explosions[index].p2[edge].x = ties[tie].x+tie_vlist[tie_shape[edge].v2].x;
explosions[index].p2[edge].y = ties[tie].y+tie_vlist[tie_shape[edge].v2].y;
explosions[index].p2[edge].z = ties[tie].z+tie_vlist[tie_shape[edge].v2].z;
// compute trajectory vector for edges
explosions[index].vel[edge].x = ties[tie].xv - 8+rand()%16;
explosions[index].vel[edge].y = ties[tie].yv - 8+rand()%16;
explosions[index].vel[edge].z = -3+rand()%4;
} // end for edge
// done, so return
return;
} // end if found
} // end for index
} // end Start_Explosion
///////////////////////////////////////////////////////////
void Process_Explosions(void)
{
// this processes all the explosions
// loop thro all the explosions and render them
for (int index=0; index<NUM_EXPLOSIONS; index++)
{
// test if this explosion is active?
if (explosions[index].state==0)
continue;
for (int edge=0; edge<NUM_TIE_EDGES; edge++)
{
// must be exploding, update edges (shrapel)
explosions[index].p1[edge].x+=explosions[index].vel[edge].x;
explosions[index].p1[edge].y+=explosions[index].vel[edge].y;
explosions[index].p1[edge].z+=explosions[index].vel[edge].z;
explosions[index].p2[edge].x+=explosions[index].vel[edge].x;
explosions[index].p2[edge].y+=explosions[index].vel[edge].y;
explosions[index].p2[edge].z+=explosions[index].vel[edge].z;
} // end for edge
// test for terminatation of explosion?
if (++explosions[index].counter > 100)
explosions[index].state = explosions[index].counter = 0;
} // end for index
} // end Process_Explosions
///////////////////////////////////////////////////////////
void Draw_Explosions(void)
{
// this draws all the explosions
// loop thro all the explosions and render them
for (int index=0; index<NUM_EXPLOSIONS; index++)
{
// test if this explosion is active?
if (explosions[index].state==0)
continue;
// render this explosion
// each explosion is made of a number of edges
for (int edge=0; edge < NUM_TIE_EDGES; edge++)
{
POINT3D p1_per, p2_per; // used to hold perspective endpoints
// test if edge if beyond near clipping plane
if (explosions[index].p1[edge].z < NEAR_Z &&
explosions[index].p2[edge].z < NEAR_Z)
continue;
// step 1: perspective transform each end point
p1_per.x = VIEW_DISTANCE*explosions[index].p1[edge].x/explosions[index].p1[edge].z;
p1_per.y = VIEW_DISTANCE*explosions[index].p1[edge].y/explosions[index].p1[edge].z;
p2_per.x = VIEW_DISTANCE*explosions[index].p2[edge].x/explosions[index].p2[edge].z;
p2_per.y = VIEW_DISTANCE*explosions[index].p2[edge].y/explosions[index].p2[edge].z;
// step 2: compute screen coords
int p1_screen_x = WINDOW_WIDTH/2 + p1_per.x;
int p1_screen_y = WINDOW_HEIGHT/2 - p1_per.y;
int p2_screen_x = WINDOW_WIDTH/2 + p2_per.x;
int p2_screen_y = WINDOW_HEIGHT/2 - p2_per.y;
// step 3: draw the edge
Draw_Clip_Line16(p1_screen_x, p1_screen_y, p2_screen_x, p2_screen_y,
explosions[index].color,back_buffer, back_lpitch);
} // end for edge
} // end for index
} // end Draw_Explosions
//////////////////////////////////////////////////////////
int Game_Main(void *parms)
{
int index; // looping var
Start_Clock();
// clear the drawing surface
DDraw_Fill_Surface(lpddsback, 0);
// read keyboard and other devices here
DInput_Read_Keyboard();
// game logic here...
if (game_state==GAME_RUNNING)
{
// move players crosshair
if (keyboard_state[DIK_RIGHT])
{
// move cross hair to right
cross_x+=CROSS_VEL;
// test for wraparound
if (cross_x > WINDOW_WIDTH/2)
cross_x = -WINDOW_WIDTH/2;
} // end if
if (keyboard_state[DIK_LEFT])
{
// move cross hair to left
cross_x-=CROSS_VEL;
// test for wraparound
if (cross_x < -WINDOW_WIDTH/2)
cross_x = WINDOW_WIDTH/2;
} // end if
if (keyboard_state[DIK_DOWN])
{
// move cross hair up
cross_y-=CROSS_VEL;
// test for wraparound
if (cross_y < -WINDOW_HEIGHT/2)
cross_y = WINDOW_HEIGHT/2;
} // end if
if (keyboard_state[DIK_UP])
{
// move cross hair up
cross_y+=CROSS_VEL;
// test for wraparound
if (cross_y > WINDOW_HEIGHT/2)
cross_y = -WINDOW_HEIGHT/2;
} // end if
// speed of ship controls
if (keyboard_state[DIK_A])
player_z_vel++;
else
if (keyboard_state[DIK_S])
player_z_vel--;
// test if player is firing laser cannon
if (keyboard_state[DIK_SPACE] && cannon_state==0)
{
// fire the cannon
cannon_state = 1;
cannon_count = 0;
// save last position of targeter
target_x_screen = cross_x_screen;
target_y_screen = cross_y_screen;
// make sound
DSound_Play(laser_id);
} // end if
} // end if game running
// process cannon, simple FSM ready->firing->cool
// firing phase
if (cannon_state == 1)
if (++cannon_count > 15)
cannon_state = 2;
// cool down phase
if (cannon_state == 2)
if (++cannon_count > 20)
cannon_state = 0;
// move the starfield
Move_Starfield();
// move and perform ai for ties
Process_Ties();
// Process the explosions
Process_Explosions();
// lock the back buffer and obtain pointer and width
DDraw_Lock_Back_Surface();
// draw the starfield
Draw_Starfield();
// draw the tie fighters
Draw_Ties();
// draw the explosions
Draw_Explosions();
// draw the crosshairs
// first compute screen coords of crosshair
// note inversion of y-axis
cross_x_screen = WINDOW_WIDTH/2 + cross_x;
cross_y_screen = WINDOW_HEIGHT/2 - cross_y;
// draw the crosshair in screen coords
Draw_Clip_Line16(cross_x_screen-16,cross_y_screen,
cross_x_screen+16,cross_y_screen,
rgb_red,back_buffer,back_lpitch);
Draw_Clip_Line16(cross_x_screen,cross_y_screen-16,
cross_x_screen,cross_y_screen+16,
rgb_red,back_buffer,back_lpitch);
Draw_Clip_Line16(cross_x_screen-16,cross_y_screen-4,
cross_x_screen-16,cross_y_screen+4,
rgb_red,back_buffer,back_lpitch);
Draw_Clip_Line16(cross_x_screen+16,cross_y_screen-4,
cross_x_screen+16,cross_y_screen+4,
rgb_red,back_buffer,back_lpitch);
// draw the laser beams
if (cannon_state == 1)
{
if ((rand()%2 == 1))
{
// right beam
Draw_Clip_Line16(WINDOW_WIDTH-1, WINDOW_HEIGHT-1,
-4+rand()%8+target_x_screen,-4+rand()%8+target_y_screen,
RGB16Bit(0,0,rand()),back_buffer,back_lpitch);
} // end if
else
{
// left beam
Draw_Clip_Line16(0, WINDOW_HEIGHT-1,
-4+rand()%8+target_x_screen,-4+rand()%8+target_y_screen,
RGB16Bit(0,0,rand()),back_buffer,back_lpitch);
} // end if
} // end if
// done rendering, unlock back buffer surface
DDraw_Unlock_Back_Surface();
// draw the informtion
sprintf(buffer, "Score %d Kills %d Escaped %d", score, hits, misses);
Draw_Text_GDI(buffer, 0,0,RGB(0,255,0), lpddsback);
if (game_state==GAME_OVER)
Draw_Text_GDI("G A M E O V E R", WINDOW_WIDTH/2-8*10,WINDOW_HEIGHT/2,RGB(255,255,255), lpddsback);
// check if the music has finished, if so restart
if (DMusic_Status_MIDI(main_track_id)==MIDI_STOPPED)
DMusic_Play(main_track_id);
// flip the surfaces
DDraw_Flip();
// sync to 30ish fps
Wait_Clock(30);
// check for game state switch
if (misses > 4*NUM_TIES)
game_state = GAME_OVER;
// check of user is trying to exit
if (KEY_DOWN(VK_ESCAPE) || keyboard_state[DIK_ESCAPE])
{
PostMessage(main_window_handle, WM_DESTROY,0,0);
} // end if
// return success
return(1);
} // end Game_Main
这是一个游戏的代码
基本上这个我已经弄好了,但是一直少不到这段代码中的子弹绘制控制在什么地方.....我快郁闷死了,谁能帮我找找,顺便教教这里的攻击判定是怎么射定的??
|
|