📄 gamerun.cpp
字号:
if (the_player->cur_sec->flags & VOXEL_SECTOR) {
abs_z=the_player->z+Get_Voxel_Alt((PUCHAR)the_player->cur_sec->extra_data,
the_player->x, the_player->y)+the_player->type->eye_height;
} else {
abs_z=the_player->z+the_player->cur_sec->floor_height+the_player->type->eye_height;
}
Render_Screen(the_player->x, the_player->y, abs_z, the_player->angle);
end_scrn.transparent_show(buff, Get_Phys_Screen_Width(), 0,0);
#ifdef OS_WINDOWS
Win_Copy_Buff();
#endif
#ifdef OS_DOS
Dos_Copy_Buff();
#endif
raw_key=0;
long start_update_num;
start_update_num=Get_Update_Num();
while ( ((start_update_num+200)>Get_Update_Num()) && (!raw_key) );
}
if (game_result==DIED_GAME) {
setgmode(0x3);
cout << "Just because you're paranoid, doesn't mean they're not out to get you.\n";
delay(5000);
}
done=TRUE;
}
void Do_Shot(PCHAR graphic_filename, PCHAR sound_filename, long time, BOOL back) {
Suspend_Time();
RCastGobject scrn;
scrn.assigninfile(graphic_filename);
scrn.load();
if (back) {
cur_vert_angle=Get_Player_Vert_Angle(the_player);
if (cur_vert_angle!=last_vert_angle) {
Set_View_Angle(cur_vert_angle);
last_vert_angle=cur_vert_angle;
}
Render_Screen(the_player->x, the_player->y, the_player->z+the_player->type->eye_height+
Ground_Height(the_player), the_player->angle);
} else clearBuff();
scrn.transparent_show(buff, Get_Phys_Screen_Width(), 0, 0);
#ifdef OS_WINDOWS
Win_Copy_Buff();
#endif
#ifdef OS_DOS
Dos_Copy_Buff();
#endif
Play_Sound(Load_Sound(sound_filename));
Reset_Timer();
while (Get_Update_Num()<time);
Resume_Time();
}
void Init_Main_Cycle() {
Reset_Timer();
Do_Intro();
Reset_Timer();
#ifdef OS_DOS
if (hasmouse)
GetMouseInput();
#endif
Clear_Input();
beg_update_num=0;
cur_vert_angle=last_vert_angle=0;
dim_control=VERT_CONTROL;
raw_key=0;
#ifdef OS_DOS
done=FALSE;
#endif
}
BOOL Main_Cycle_Done() {
return done;
}
void Do_Main_Cycle()
{
long abs_z;
long cur_update, end_update_num;
cur_vert_angle=Get_Player_Vert_Angle(the_player);
if (cur_vert_angle!=last_vert_angle) {
Set_View_Angle(cur_vert_angle);
last_vert_angle=cur_vert_angle;
}
if (the_player->cur_sec->flags & VOXEL_SECTOR) {
abs_z=the_player->z+Get_Voxel_Alt((PUCHAR)the_player->cur_sec->extra_data,
the_player->x, the_player->y)+the_player->type->eye_height;
} else {
abs_z=the_player->z+the_player->cur_sec->floor_height+the_player->type->eye_height;
}
Render_Screen(the_player->x, the_player->y, abs_z, the_player->angle);
#ifdef OS_WINDOWS
Win_Copy_Buff();
#endif
#ifdef OS_DOS
Dos_Copy_Buff();
#endif
frame_num++;
end_update_num=Get_Update_Num();
for (cur_update=beg_update_num; cur_update<end_update_num; cur_update++) {
World_Update(cur_update);
}
beg_update_num=end_update_num;
// Check other keys that are unrelated to world updates
switch (raw_key) {
case ESC_KEY:
#ifdef OS_DOS
done=TRUE;
#endif
#ifdef OS_WINDOWS
PostQuitMessage(0);
#endif
// end if user is exiting
break;
#ifdef _PROGRAMMER_VERSION_
case PLUS_KEY:
// user pressed "+" key, so increase window size
if (GetRenderMode()!=MODE_2D) {
#ifdef OS_DOS
if (dim_control==VERT_CONTROL)
setWindowDimensions(WINDOW_HEIGHT+10);
else if (dim_control==HORIZ_CONTROL)
Set_Window_Width(WINDOW_WIDTH+10);
#endif
} else Map_Scale_Increase();
break;
case MINUS_KEY:
// user pressed "-" key, so decrease window size
if (GetRenderMode()!=MODE_2D) {
#ifdef OS_DOS
if (dim_control==VERT_CONTROL)
setWindowDimensions(WINDOW_HEIGHT-10);
else if (dim_control==HORIZ_CONTROL)
Set_Window_Width(WINDOW_WIDTH-10);
#endif
} else Map_Scale_Decrease();
break;
case RIGHT_BRACKET:
// user pressed "]" key, so increase window FOV
if (dim_control==VERT_CONTROL)
setWindowFOV(VERTICAL_VIEW_RANGE+ANGLE_5);
else if (dim_control==HORIZ_CONTROL)
Set_Horiz_FOV(HORIZ_VIEW_RANGE+ANGLE_5);
break;
case LEFT_BRACKET:
// user pressed "[" key, so decrease window FOV
if (dim_control==VERT_CONTROL)
setWindowFOV(VERTICAL_VIEW_RANGE-ANGLE_5);
else if (dim_control==HORIZ_CONTROL)
Set_Horiz_FOV(HORIZ_VIEW_RANGE-ANGLE_5);
break;
case PGUP_KEY:
// user wants to make vox terrain seem farther away
V_Dist_Scale_Inc();
break;
case PGDN_KEY:
// user wants to make vox terrain seem closer
V_Dist_Scale_Dec();
break;
#endif
#ifdef OS_DOS
case F1_KEY:
// user is changing screen resolution
if (is_super_vga)
Change_Screen(VGA_WIDTH, VGA_HEIGHT);
else Change_Screen(SVGA_WIDTH, SVGA_HEIGHT);
is_super_vga=(!is_super_vga);
Update_Palette();
break;
#endif
#ifdef _PROGRAMMER_VERSION_
case F2_KEY:
// user wants to adjust the other dimension of screen
if (dim_control==VERT_CONTROL)
dim_control=HORIZ_CONTROL;
else if (dim_control==HORIZ_CONTROL)
dim_control=VERT_CONTROL;
raw_key=0;
break;
#endif
case S_KEY:
// user wants to capture screen
Screen_Capture((PCHAR)DEF_CAPTURE_F_NAME);
break;
case TAB_KEY:
SwitchRenderMode();
raw_key=0;
break;
default:
break;
} /* endswitch */
}
long time_at_hurt;
BOOL is_hurt;
void Init_Visuals() {
time_at_hurt=0;
is_hurt=FALSE;
}
void Visuals_Message(ULONG message, pdata extra_data) {
switch (message) {
case HURT_MESSAGE:
Show_Palette(HURT_PAL);
time_at_hurt=Get_Update_Num();
is_hurt=TRUE;
break;
case VIS_DIE_MSG:
Do_Shot("dscreen.pcx", "aaah.wav", 90, TRUE);
the_player->x=PLAYER_START_X;
the_player->y=PLAYER_START_Y;
the_player->z=PLAYER_START_Z;
the_player->stats.current_health=the_player->type->stats.total_health;
the_player->angle=PLAYER_START_ANGLE;
default:
break;
}
}
void Visuals_Update(long cur_update_num) {
if (is_hurt) {
if (cur_update_num>time_at_hurt+HURT_TIME) {
is_hurt=FALSE;
time_at_hurt=0;
Show_Palette(STANDARD_PAL);
}
}
}
void World_Update(long cur_update_num) {
#ifdef OS_DOS
if (hasmouse)
GetMouseInput();
#endif
if (do_waves) {
Do_Waves();
} /* endif */
Animate_Textures(cur_update_num);
Setup_Combined_Input();
Update_Objects(cur_update_num);
Visuals_Update(cur_update_num);
}
void GetMouseInput()
{
#ifdef OS_DOS
short x,y; // x,y positions of the mouse relative to last check
mbrel(x,y); // Get them's positions;
if (x<0) { // mouse to left
mouse_table[INDEX_LEFT]=-x;
} else {
if (x>0) { // mouse to right
mouse_table[INDEX_RIGHT]=x;
} else { // no mouse movement on x
mouse_table[INDEX_LEFT]=0; mouse_table[INDEX_RIGHT]=0;
} /* endif */
} /* endif */
// Note: on the y axis, direction is reversed i.e. a mouse movement up generates a y<0
// mouse has different function in fly mode
if (!Is_Flying(the_player)) {
if (y<0) { // mouse is higher than last position
if (y<-the_player->type->stats.base_speed)
y=-the_player->type->stats.base_speed;
mouse_table[INDEX_UP]=-y;
} else {
if (y>0) { // mouse is lower than last position
if (y>the_player->type->stats.base_speed)
y=the_player->type->stats.base_speed;
mouse_table[INDEX_DOWN]=y;
} else { // no mouse movement on y
mouse_table[INDEX_DOWN]=0; mouse_table[INDEX_UP]=0;
} /* endif */
} /* endif */
if (mbpos(x,y)) { // Check for button press
mouse_table[INDEX_GUN]=1;
} else {
mouse_table[INDEX_GUN]=0;
}
} else {
if (y<0) {
mouse_table[LOOK_UP]=-y;
} else {
if (y>0) {
mouse_table[LOOK_DOWN]=y;
} else {
mouse_table[LOOK_UP]=0; mouse_table[LOOK_DOWN]=0;
} /* endif */
} /* endif */
long mb_press=mbpos(x,y);
if (mb_press & ML_BUTTON) {
mouse_table[INDEX_UP]=the_player->type->stats.base_speed;
} else {
if (mb_press & MR_BUTTON) {
mouse_table[INDEX_DOWN]=the_player->type->stats.base_speed;
} else {
mouse_table[INDEX_UP]=0; mouse_table[INDEX_DOWN]=0;
} /* endif */
} /* endif */
} /* endif */
#endif
}
void Setup_Combined_Input()
{
for (short i=0; i<(MAX_TRACKED_INPUTS-1); i++) {
if (key_table[i]>mouse_table[i]) {
combined_table[i]=(short)key_table[i];
} else {
combined_table[i]=(short)mouse_table[i];
} /* endif */
} /* endfor */
combined_table[MAX_TRACKED_INPUTS-1]=raw_key;
}
void Clear_Input() {
for (short i=0; i<(MAX_TRACKED_INPUTS-1); i++) {
key_table[i]=0;
mouse_table[i]=0;
combined_table[i]=0;
}
raw_key=0;
combined_table[MAX_TRACKED_INPUTS-1]=0;
}
void Screen_Message(PCHAR message) {
printf(message);
printf("\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -