?? outpost.cpp
字號:
player_dy=0,
player_xv=0,
player_yv=0,
vel = 0;
// these contain the virual cos, sin lookup tables for the 16 sector circle
float cos_look16[16],
sin_look16[16];
// sound id's
int intro_music_id = -1,
main_music_id = -1,
ready_id = -1,
engines_id = -1,
scream_id = -1,
game_over_id = -1,
mine_powerup_id = -1,
deactivate_id = -1,
main_menu_id = -1,
empty_id = -1,
beep0_id = -1,
beep1_id = -1,
station_blow_id = -1,
station_throb_id = -1,
ammopu_id = -1,
shldpu_id = -1;
int expl_ids[MAX_EXPL_SOUNDS] = {-1,-1,-1,-1,-1,-1,-1,-1};
int fire_ids[MAX_FIRE_SOUNDS] = {-1,-1,-1,-1,-1,-1,-1,-1};
int game_state = GAME_STATE_INIT; // initial game state
// FUNCTIONS //////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
// this is the main message handler of the system
PAINTSTRUCT ps; // used in WM_PAINT
HDC hdc; // handle to a device context
// what is the message
switch(msg)
{
case WM_CREATE:
{
// do initialization stuff here
return(0);
} break;
case WM_PAINT:
{
// start painting
hdc = BeginPaint(hwnd,&ps);
// end painting
EndPaint(hwnd,&ps);
return(0);
} break;
case WM_DESTROY:
{
// kill the application
PostQuitMessage(0);
return(0);
} break;
default:break;
} // end switch
// process any messages that we didn't take care of
return (DefWindowProc(hwnd, msg, wparam, lparam));
} // end WinProc
// WINMAIN ////////////////////////////////////////////////
int WINAPI WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
// this is the winmain function
WNDCLASS winclass; // this will hold the class we create
HWND hwnd; // generic window handle
MSG msg; // generic message
HDC hdc; // generic dc
PAINTSTRUCT ps; // generic paintstruct
// first fill in the window class stucture
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
// register the window class
if (!RegisterClass(&winclass))
return(0);
// create the window, note the use of WS_POPUP
if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
"Vector tracking demo", // title
WS_POPUP | WS_VISIBLE,
0,0, // x,y
WINDOW_WIDTH, // width
WINDOW_HEIGHT, // height
NULL, // handle to parent
NULL, // handle to menu
hinstance,// instance
NULL))) // creation parms
return(0);
// save the window handle and instance in a global
main_window_handle = hwnd;
main_instance = hinstance;
// perform all game console specific initialization
Game_Init();
// enter main event loop
while(1)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
// test if this is a quit
if (msg.message == WM_QUIT)
break;
// translate any accelerator keys
TranslateMessage(&msg);
// send the message to the window proc
DispatchMessage(&msg);
} // end if
// main game processing goes here
Game_Main();
} // end while
// shutdown game and release all resources
Game_Shutdown();
// return to Windows like this
return(msg.wParam);
} // end WinMain
////////////////////////////////////////////////////////////////////////////
void Load_Andre(void)
{
// this function loads all the buttons for the interface
// load image
Load_Bitmap_File(&bitmap8bit, "OUTART/ENEMYAI.DAT");
// save the palette
Copy_Palette(andre_palette, bitmap8bit.palette);
Create_Bitmap(&andre,320-216/2,240-166/2,216,166);
Load_Image_Bitmap(&andre,&bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);
// unload object bitmap
Unload_Bitmap_File(&bitmap8bit);
} // end Load_Andre
/////////////////////////////////////////////////////////////////
void Init_Reset_Particles(void)
{
// this function serves as both an init and reset for the particles
// loop thru and reset all the particles to dead
for (int index=0; index<MAX_PARTICLES; index++)
{
particles[index].state = PARTICLE_STATE_DEAD;
particles[index].type = PARTICLE_TYPE_FADE;
particles[index].x = 0;
particles[index].y = 0;
particles[index].xv = 0;
particles[index].yv = 0;
particles[index].start_color = 0;
particles[index].end_color = 0;
particles[index].curr_color = 0;
particles[index].counter = 0;
particles[index].max_count = 0;
} // end if
} // end Init_Reset_Particles
/////////////////////////////////////////////////////////////////////////
void Start_Particle(int type, int color, int count, int x, int y, int xv, int yv)
{
// this function starts a single particle
int pindex = -1; // index of particle
// first find open particle
for (int index=0; index < MAX_PARTICLES; index++)
if (particles[index].state == PARTICLE_STATE_DEAD)
{
// set index
pindex = index;
break;
} // end if
// did we find one
if (pindex==-1)
return;
// set general state info
particles[pindex].state = PARTICLE_STATE_ALIVE;
particles[pindex].type = type;
particles[pindex].x = x;
particles[pindex].y = y;
particles[pindex].xv = xv;
particles[pindex].yv = yv;
particles[pindex].counter = 0;
particles[pindex].max_count = count;
// set color ranges, always the same
switch(color)
{
case PARTICLE_COLOR_RED:
{
particles[pindex].start_color = COLOR_RED_START;
particles[pindex].end_color = COLOR_RED_END;
} break;
case PARTICLE_COLOR_GREEN:
{
particles[pindex].start_color = COLOR_GREEN_START;
particles[pindex].end_color = COLOR_GREEN_END;
} break;
case PARTICLE_COLOR_BLUE:
{
particles[pindex].start_color = COLOR_BLUE_START;
particles[pindex].end_color = COLOR_BLUE_END;
} break;
case PARTICLE_COLOR_WHITE:
{
particles[pindex].start_color = COLOR_WHITE_START;
particles[pindex].end_color = COLOR_WHITE_END;
} break;
break;
} // end switch
// what type of particle is being requested
if (type == PARTICLE_TYPE_FLICKER)
{
// set current color
particles[index].curr_color = RAND_RANGE(particles[index].start_color, particles[index].end_color);
} // end if
else
{
// particle is fade type
// set current color
particles[index].curr_color = particles[index].start_color;
} // end if
} // end Start_Particle
////////////////////////////////////////////////////////////////////////////////
void Start_Particle_Explosion(int type, int color, int count,
int x, int y, int xv, int yv, int num_particles)
{
// this function starts a particle explosion at the given position and velocity
while(--num_particles >=0)
{
// compute random trajectory angle
int ang = rand()%16;
// compute random trajectory velocity
float vel = 2+rand()%4;
Start_Particle(type,color,count,
x+RAND_RANGE(-4,4),y+RAND_RANGE(-4,4),
xv+cos_look16[ang]*vel, yv+sin_look16[ang]*16);
} // end while
} // end Start_Particle_Explosion
////////////////////////////////////////////////////////////////////////////////
void Draw_Particles(void)
{
// this function draws all the particles
// lock back surface
DDraw_Lock_Back_Surface();
for (int index=0; index<MAX_PARTICLES; index++)
{
// test if particle is alive
if (particles[index].state==PARTICLE_STATE_ALIVE)
{
// render the particle, perform world to screen transform
int x = particles[index].x - player_x + (SCREEN_WIDTH/2);
int y = particles[index].y - player_y + (SCREEN_HEIGHT/2);
// test for clip
if (x >= SCREEN_WIDTH || x < 0 || y >= SCREEN_HEIGHT || y < 0)
continue;
// draw the pixel
Draw_Pixel(x,y,particles[index].curr_color, back_buffer, back_lpitch);
} // end if
} // end for index
// unlock the secondary surface
DDraw_Unlock_Back_Surface();
} // end Draw_Particles
////////////////////////////////////////////////////////////////////
void Move_Particles(void)
{
// this function moves and animates all particles
for (int index=0; index<MAX_PARTICLES; index++)
{
// test if this particle is alive
if (particles[index].state == PARTICLE_STATE_ALIVE)
{
// translate particle
particles[index].x+=particles[index].xv;
particles[index].y+=particles[index].yv;
// now based on type of particle perform proper animation
if (particles[index].type==PARTICLE_TYPE_FLICKER)
{
// simply choose a color in the color range and assign it to the current color
particles[index].curr_color = RAND_RANGE(particles[index].start_color, particles[index].end_color);
// now update counter
if (++particles[index].counter >= particles[index].max_count)
{
// kill the particle
particles[index].state = PARTICLE_STATE_DEAD;
} // end if
} // end if
else
{
// must be a fade, be careful!
// test if it's time to update color
if (++particles[index].counter >= particles[index].max_count)
{
// reset counter
particles[index].counter = 0;
// update color
if (++particles[index].curr_color>particles[index].end_color)
{
// transition is complete, terminate particle
particles[index].state = PARTICLE_STATE_DEAD;
} // end if
} // end if
} // end else
} // end if
} // end for index
} // end Move_Particles
////////////////////////////////////////////////////////////////////////////////////
void Init_Stars(void)
{
// this function initializes all the stars in the star field
int index; // looping variable
for (index=0; index < MAX_STARS; index++)
{
// select plane that star will be in
switch(rand()%3)
{
case STAR_PLANE_0:
{
stars[index].color = STAR_COLOR_0;
stars[index].plane = STAR_PLANE_0;
} break;
case STAR_PLANE_1:
{
stars[index].color = STAR_COLOR_1;
stars[index].plane = STAR_PLANE_1;
} break;
case STAR_PLANE_2:
{
stars[index].color = STAR_COLOR_2;
stars[index].plane = STAR_PLANE_2;
} break;
default:break;
} // end switch
// set fields that aren't plane specific
stars[index].x = rand()%SCREEN_WIDTH; // change this latter to reflect clipping
stars[index].y = rand()%SCREEN_HEIGHT; // region
} // end for index
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -