📄 demoii12_4.cpp
字号:
// create some working colors
white.rgba = _RGBA32BIT(255,255,255,0);
lightgray.rgba = _RGBA32BIT(200,200,200,0);
gray.rgba = _RGBA32BIT(100,100,100,0);
black.rgba = _RGBA32BIT(0,0,0,0);
red.rgba = _RGBA32BIT(255,0,0,0);
green.rgba = _RGBA32BIT(0,255,0,0);
blue.rgba = _RGBA32BIT(0,0,255,0);
// ambient light
Init_Light_LIGHTV2(lights2, // array of lights to work with
AMBIENT_LIGHT_INDEX,
LIGHTV2_STATE_ON, // turn the light on
LIGHTV2_ATTR_AMBIENT, // ambient light type
gray, black, black, // color for ambient term only
NULL, NULL, // no need for pos or dir
0,0,0, // no need for attenuation
0,0,0); // spotlight info NA
VECTOR4D dlight_dir = {-1,1,0,1};
// directional light
Init_Light_LIGHTV2(lights2, // array of lights to work with
INFINITE_LIGHT_INDEX,
LIGHTV2_STATE_ON, // turn the light on
LIGHTV2_ATTR_INFINITE, // infinite light type
black, lightgray, black, // color for diffuse term only
NULL, &dlight_dir, // need direction only
0,0,0, // no need for attenuation
0,0,0); // spotlight info NA
VECTOR4D plight_pos = {0,200,0,1};
// point light
Init_Light_LIGHTV2(lights2, // array of lights to work with
POINT_LIGHT_INDEX,
LIGHTV2_STATE_ON, // turn the light on
LIGHTV2_ATTR_POINT, // pointlight type
black, gray, black, // color for diffuse term only
&plight_pos, NULL, // need pos only
0,.002,0, // linear attenuation only
0,0,1); // spotlight info NA
// create lookup for lighting engine
RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565, // format we want to build table for
palette, // source palette
rgblookup); // lookup table
// load background sounds
wind_sound_id = DSound_Load_WAV("WIND.WAV");
water_light_sound_id = DSound_Load_WAV("WATERLIGHT01.WAV");
water_heavy_sound_id = DSound_Load_WAV("WATERHEAVY01.WAV");
water_splash_sound_id = DSound_Load_WAV("SPLASH01.WAV");
zbuffer_intro_sound_id = DSound_Load_WAV("ZBUFFER02.WAV");
zbuffer_instr_sound_id = DSound_Load_WAV("ZINSTRUCTIONS02.WAV");
jetski_start_sound_id = DSound_Load_WAV("jetskistart04.WAV");
jetski_idle_sound_id = DSound_Load_WAV("jetskiidle01.WAV");
jetski_fast_sound_id = DSound_Load_WAV("jetskifast01.WAV");
jetski_accel_sound_id = DSound_Load_WAV("jetskiaccel01.WAV");
jetski_splash_sound_id = DSound_Load_WAV("splash01.WAV");
// load background image
Load_Bitmap_File(&bitmap16bit, "cloud03_640.BMP");
Create_Bitmap(&background_bmp,0,0,640,480,16);
Load_Image_Bitmap16(&background_bmp, &bitmap16bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);
// load in all the text images
// intro
Load_Bitmap_File(&bitmap16bit, "zbufferwr_intro01.BMP");
Create_BOB(&intro_image, WINDOW_WIDTH/2 - 560/2,40,560,160,1, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 16);
Load_Frame_BOB16(&intro_image, &bitmap16bit,0,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);
// get ready
Load_Bitmap_File(&bitmap16bit, "zbufferwr_ready01.BMP");
Create_BOB(&ready_image, WINDOW_WIDTH/2 - 596/2,40,596,244,1, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 16);
Load_Frame_BOB16(&ready_image, &bitmap16bit,0,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);
// nice one
Load_Bitmap_File(&bitmap16bit, "zbufferwr_nice01.BMP");
Create_BOB(&nice_one_image, WINDOW_WIDTH/2 - 588/2,40,588,92,1, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 16);
Load_Frame_BOB16(&nice_one_image, &bitmap16bit,0,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap16bit);
// set single precission
//_control87( _PC_24, MCW_PC );
// allocate memory for zbuffer
Create_Zbuffer(&zbuffer,
WINDOW_WIDTH,
WINDOW_HEIGHT,
ZBUFFER_ATTR_32BIT);
RGB_Alpha_Table_Builder(NUM_ALPHA_LEVELS, rgb_alpha_table);
// return success
return(1);
} // end Game_Init
///////////////////////////////////////////////////////////
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();
Delete_Zbuffer(&zbuffer);
// 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!
static MATRIX4X4 mrot; // general rotation matrix
static float plight_ang = 0,
slight_ang = 0; // angles for light motion
// use these to rotate objects
static float x_ang = 0, y_ang = 0, z_ang = 0;
// state variables for different rendering modes and help
static int wireframe_mode = 1;
static int backface_mode = 1;
static int lighting_mode = 1;
static int help_mode = -1;
static int zsort_mode = 1;
static int x_clip_mode = 1;
static int y_clip_mode = 1;
static int z_clip_mode = 1;
static int z_buffer_mode = 1;
static int display_mode = 1;
static int seafloor_mode = 1;
char work_string[256]; // temp string
static int nice_one_on = 0; // used to display the nice one text
static int nice_count1 = 0;
static int alpha = 0;
int index; // looping var
// what state is the game in?
switch(game_state)
{
case GAME_STATE_INIT:
{
// perform any important initializations
// transition to restart
game_state = GAME_STATE_RESTART;
} break;
case GAME_STATE_RESTART:
{
// reset all variables
game_state_count1 = 0;
player_state = JETSKI_OFF;
player_state_count1 = 0;
gravity = -.30;
vel_y = 0;
cam_speed = 0;
sea_level = 30;
gclearance = 75;
neutral_pitch = 10;
turn_ang = 0;
jetski_yaw = 0;
wave_count = 0;
scroll_count = 0;
enable_model_view = 0;
// set camera high atop mount aleph one
cam.pos.x = 1550;
cam.pos.y = 800;
cam.pos.z = 1950;
cam.dir.y = -140;
// turn on water sounds
// start the sounds
DSound_Play(wind_sound_id, DSBPLAY_LOOPING);
DSound_Set_Volume(wind_sound_id, 75);
DSound_Play(water_light_sound_id, DSBPLAY_LOOPING);
DSound_Set_Volume(water_light_sound_id, 50);
DSound_Play(water_heavy_sound_id, DSBPLAY_LOOPING);
DSound_Set_Volume(water_heavy_sound_id, 30);
DSound_Play(zbuffer_intro_sound_id);
DSound_Set_Volume(zbuffer_intro_sound_id, 100);
// transition to introduction sub-state of run
game_state = GAME_STATE_INTRO;
} break;
// in any of these cases enter into the main simulation loop
case GAME_STATE_RUN:
case GAME_STATE_INTRO:
case GAME_STATE_PLAY:
{
// perform sub-state transition logic here
if (game_state == GAME_STATE_INTRO)
{
// update timer
++game_state_count1;
// test for first part of intro
if (game_state_count1 == INTRO_STATE_COUNT1)
{
// change amplitude of water
DSound_Set_Volume(water_light_sound_id, 50);
DSound_Set_Volume(water_heavy_sound_id, 100);
// reposition camera in water
cam.pos.x = 444; // 560;
cam.pos.y = 200;
cam.pos.z = -534; // -580;
cam.dir.y = 45;// (-100);
// enable model
enable_model_view = 1;
} // end if
else
if (game_state_count1 == INTRO_STATE_COUNT2)
{
// change amplitude of water
DSound_Set_Volume(water_light_sound_id, 20);
DSound_Set_Volume(water_heavy_sound_id, 50);
// play the instructions
DSound_Play(zbuffer_instr_sound_id);
DSound_Set_Volume(zbuffer_instr_sound_id, 100);
} // end if
else
if (game_state_count1 == INTRO_STATE_COUNT3)
{
// reset counter for other use
game_state_count1 = 0;
// change amplitude of water
DSound_Set_Volume(water_light_sound_id, 30);
DSound_Set_Volume(water_heavy_sound_id, 70);
// transition to play state
game_state = GAME_STATE_PLAY;
} // end if
} // end if
// start the timing clock
Start_Clock();
// clear the drawing surface
//DDraw_Fill_Surface(lpddsback, 0);
// draw the sky
//Draw_Rectangle(0,0, WINDOW_WIDTH, WINDOW_HEIGHT*.38, RGB16Bit(50,100,255), lpddsback);
// draw the ground
//Draw_Rectangle(0,WINDOW_HEIGHT*.38, WINDOW_WIDTH, WINDOW_HEIGHT, RGB16Bit(25,50,110), lpddsback);
//Draw_BOB16(&background, lpddsback);
// read keyboard and other devices here
DInput_Read_Keyboard();
// game logic here...
// reset the render list
Reset_RENDERLIST4DV2(&rend_list);
if (keyboard_state[DIK_O])
{
if (++alpha >= NUM_ALPHA_LEVELS)
alpha = 0;
Wait_Clock(100); // wait, so keyboard doesn't bounce
} // end if
// modes and lights
// wireframe mode
if (keyboard_state[DIK_W])
{
// toggle wireframe mode
if (++wireframe_mode > 1)
wireframe_mode=0;
Wait_Clock(100); // wait, so keyboard doesn't bounce
} // end if
// backface removal
if (keyboard_state[DIK_B])
{
// toggle backface removal
backface_mode = -backface_mode;
Wait_Clock(100); // wait, so keyboard doesn't bounce
} // end if
// lighting
if (keyboard_state[DIK_L])
{
// toggle lighting engine completely
lighting_mode = -lighting_mode;
Wait_Clock(100); // wait, so keyboard doesn't bounce
} // end if
// toggle ambient light
if (keyboard_state[DIK_A])
{
// toggle ambient light
if (lights2[AMBIENT_LIGHT_INDEX].state == LIGHTV2_STATE_ON)
lights2[AMBIENT_LIGHT_INDEX].state = LIGHTV2_STATE_OFF;
else
lights2[AMBIENT_LIGHT_INDEX].state = LIGHTV2_STATE_ON;
Wait_Clock(100); // wait, so keyboard doesn't bounce
} // end if
// toggle infinite light
if (keyboard_state[DIK_I])
{
// toggle ambient light
if (lights2[INFINITE_LIGHT_INDEX].state == LIGHTV2_STATE_ON)
lights2[INFINITE_LIGHT_INDEX].state = LIGHTV2_STATE_OFF;
else
lights2[INFINITE_LIGHT_INDEX].state = LIGHTV2_STATE_ON;
Wait_Clock(100); // wait, so keyboard doesn't bounce
} // end if
// toggle point light
if (keyboard_state[DIK_P])
{
// toggle point light
if (lights2[POINT_LIGHT_INDEX].state == LIGHTV2_STATE_ON)
lights2[POINT_LIGHT_INDEX].state = LIGHTV2_STATE_OFF;
else
lights2[POINT_LIGHT_INDEX].state = LIGHTV2_STATE_ON;
Wait_Clock(100); // wait, so keyboard doesn't bounce
} // end if
// help menu
if (keyboard_state[DIK_H])
{
// toggle help menu
help_mode = -help_mode;
Wait_Clock(100); // wait, so keyboard doesn't bounce
} // end if
// z-sorting
if (keyboard_state[DIK_S])
{
// toggle z sorting
zsort_mode = -zsort_mode;
Wait_Clock(100); // wait, so keyboard doesn't bounce
} // end if
// z buffer
if (keyboard_state[DIK_Z])
{
// toggle z buffer
z_buffer_mode = -z_buffer_mode;
Wait_Clock(100); // wait, so keyboard doesn't bounce
} // end if
// display mode
if (keyboard_state[DIK_D])
{
// toggle display mode
display_mode = -display_mode;
Wait_Clock(100); // wait, so keyboard doesn't bounce
} // end if
// seafloor mode
if (keyboard_state[DIK_T])
{
// toggle the seafloor mode
seafloor_mode = -seafloor_mode;
Wait_Clock(100); // wait, so keyboard doesn't bounce
} // end if
// PLAYER CONTROL AREA ////////////////////////////////////////////////////////////
// filter player control if not in PLAY state
if (game_state==GAME_STATE_PLAY)
{
// forward/backward
if (keyboard_state[DIK_UP] && player_state >= JETSKI_START)
{
// test for acceleration
if (cam_speed == 0)
{
DSound_Play(jetski_accel_sound_id);
DSound_Set_Volume(jetski_accel_sound_id, 100);
} // end if
// move forward
if ( (cam_speed+=1) > MAX_SPEED)
cam_speed = MAX_SPEED;
} // end if
/*
else
if (keyboard_state[DIK_DOWN])
{
// move backward
if ((cam_speed-=1) < -MAX_SPEED) cam_speed = -MAX_SPEED;
} // end if
*/
// rotate around y axis or yaw
if (keyboard_state[DIK_RIGHT])
{
cam.dir.y+=5;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -