📄 main.cpp
字号:
bActive = false;
else if(HIWORD(wParam))
{
bActive = false;
return 0;
}
else
bActive = true;
//重新获取输入设备
Mouse.SetAcquire(hWnd);
Key.SetAcquire(hWnd);
g_Joystick.SetAcquire(hWnd);
Mouse.GetMouseData();
Mouse.ReleaseMouseBuffer();
//保护页面
if( g_eDisplayState==DS_NIGHT && WindowMode !=0 && !bActive )
{
GetPrimarySurface(lpDDSBack);
}
//背景音乐处理
{
if( !bActive )
{
if( Music.IsPlay() )
{
bMusicPlaying=true;
Music.Pause();
}
else
bMusicPlaying=false;
if(g_ePlayState==PS_FIGHT)
{
if(Fight.IsPlayingMusic())
{
bFMusicPlaying = true;
Fight.PauseMusic();
}
else
bFMusicPlaying = false;
}
}
else
{
if(bMusicPlaying )
Music.Resume();
if(g_ePlayState == PS_FIGHT&&bFMusicPlaying)
{
Fight.ResumeMusic();
}
}
}
return 0;
case WM_SYSKEYDOWN:
switch( wParam )
{
case VK_RETURN: //切换全屏或窗口
if ( bSwitch && bActive )
{
if( WindowMode == 0 )
lpDD->RestoreDisplayMode();
GetWindowRect(hWnd, &RectWindow);
WindowMode = 1-WindowMode;
ChangeCoopLevel(hWnd);
}
break;
case 'Q':
case 'q':
case VK_F4:
if( MessageBox(hWnd, "真的要退出吗?", "圣剑英雄传 II", MB_YESNO) == IDYES )
RunGame=false;
return 0;
case VK_F12:
g_bDebug = !g_bDebug;
break;
case 18: // 屏蔽alt
return 0;
}
break;
case WM_KEYDOWN://击键消息
switch( wParam )
{
case VK_SUBTRACT:
DelayTick+=33;
if( DelayTick>1000 )
DelayTick=1000;
break;
case VK_ADD:
DelayTick-=33;
if( DelayTick<0 )
DelayTick=0;
break;
case VK_F2:
Script.Run("script\\test.gps");
break;
case VK_F5: //切换模式
if( g_ePlayState==PS_EDIT )
{
_DELETE(UndoMap);
g_ePlayState=PS_MAIN;
bShowHardCursor=false;
ShowCursor(FALSE);
}
else if( g_ePlayState==PS_MAIN )
{
UndoMap=new Cell_Struct[map.Width*map.Height];
memcpy(UndoMap, map.Cell, sizeof(Cell_Struct)*map.Width*map.Height);
g_ePlayState=PS_EDIT;
bShowHardCursor=true;
ShowCursor(TRUE);
}
break;
case VK_F6: //查看变量
{
char *Var=GetStringDlg("请输入要查看的变量名称:");
if( Var )
ShowMessage("%s = %d", Var, Script.GetValue(Var));
}
break;
case VK_F7: //切换模式
if( g_eDisplayState==DS_NORMAL )
{
g_eDisplayState=DS_NIGHT;
map.CountDisplayGrid();
Clrscr(lpDDSPrimary, RGB(0,0,0));
}
else if( g_eDisplayState==DS_NIGHT )
{
g_eDisplayState=DS_NORMAL;
map.CountDisplayGrid();
}
break;
case VK_F8: //执行脚本
{
char *Var=GetStringDlg("请输入要执行的脚本语句:");
if( Var == NULL ) break;
Script.RunCommand(Var);
}
break;
case VK_F4: //切换全屏或窗口
if ( bSwitch && bActive )
{
if( WindowMode == 0 )
lpDD->RestoreDisplayMode();
GetWindowRect(hWnd, &RectWindow);
WindowMode = 1-WindowMode;
ChangeCoopLevel(hWnd);
}
break;
case VK_F12: //显示FPS
bShowFps=!bShowFps;
break;
case 'h': //隐藏模式的加mp,hp方法
case 'H':
{
if(g_ePlayState!=PS_MAIN||!g_bDebug||!GetAsyncKeyState(VK_CONTROL))
break;
for(int i =0 ;i<RoleNum;i++)
{
role[i].Propertiy.Hp = role[i].Propertiy.MaxHp;
role[i].Propertiy.Mp = role[i].Propertiy.MaxMp;
}
}
break;
case 'l': //直接升级
case 'L':
{
if(g_ePlayState!=PS_MAIN||!g_bDebug||!GetAsyncKeyState(VK_CONTROL))
break;
for(int i =0 ;i<RoleNum;i++)
{
role[i].Propertiy.Level++;
//算下升一级所需要的经验值
role[i].Propertiy.MaxExp += 10*(role[i].Propertiy.Level+1)*
(role[i].Propertiy.Level)+30;
role[i].Propertiy.Exp = role[i].Propertiy.MaxExp;
role[i].Propertiy.MaxHp+=200; //HP加20
role[i].Propertiy.Hp=role[i].Propertiy.MaxHp; //把HP加满
role[i].Propertiy.MaxMp+=60;
role[i].Propertiy.Mp=role[i].Propertiy.MaxMp;
role[i].oldAttack+=80;
role[i].oldDefend+=40;
role[i].Propertiy.Magic+=3;
role[i].Propertiy.Stamina+=3;
role[i].Propertiy.Luck+=3;
role[i].Propertiy.Speed+=3;
role[i].Propertiy.Bp=100;
role[i].Propertiy.Ip=100;
role[i].ReCalcPro();
}
}
break;
}
break;
case WM_TIMER: //定时器消息
if(!bActive)
return 0;
switch( wParam )
{
case 1: //Music
if( g_ePlayState!=PS_FIGHT && CMusic::bPlay &&
!Music.IsPlay() &&!bMusicPlaying)
{
Music.Play();
}
break;
case 2: //Fight
if( g_ePlayState==PS_FIGHT )
{
Fight.OnTimer();
}
break;
}
return 0;
// 处理地图编辑器的右键命令
case WM_COMMAND:
Mouse.ReleaseMouseBuffer();
MapEditProc(LOWORD(wParam));
Mouse.ReleaseMouseBuffer();
break;
case WM_PAINT: //在后台窗口模式时
if( !bActive &&WindowMode!=0 )
{
while (TRUE)
{
int hRet = lpDDSPrimary->Blt(&RectWindow, lpDDSBack,
&RectScreen, DDBLT_WAIT, NULL);
if (hRet == DD_OK)
break;
if (hRet == DDERR_SURFACELOST)
{
hRet = lpDDSPrimary->Restore();
if (hRet != DD_OK )
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
}
break;
case WM_SIZE:
if(wParam==SIZE_RESTORED)
{
GetWindowRect(hWnd,&RectWindow);
RectWindow.top += g_pointClient.y;
RectWindow.left += g_pointClient.x;
RectWindow.right = RectWindow.left + ScreenWidth;
RectWindow.bottom = RectWindow.top + ScreenHeight;
}
return 0;
case WM_ENTERMENULOOP:
if(Music.IsPlay())
{
bMusicPlaying=true;
Music.Pause();
}
else
bMusicPlaying=false;
if(Fight.IsPlayingMusic())
{
bFMusicPlaying = true;
Fight.PauseMusic();
}
else
bFMusicPlaying = false;
return 0;
case WM_EXITMENULOOP:
if(g_ePlayState == PS_FIGHT&&bFMusicPlaying)
Fight.ResumeMusic();
if(bMusicPlaying)
Music.Resume();
return 0;
case WM_MOVE: //窗口移动
if ( bActive && WindowMode!=0 )
{
GetWindowRect(hWnd, &RectWindow);
RectWindow.top += g_pointClient.y;
RectWindow.left += g_pointClient.x;
RectWindow.right = RectWindow.left + ScreenWidth;
RectWindow.bottom = RectWindow.top + ScreenHeight;
}
break;
case WM_SETCURSOR: //设置光标
if( bActive && !bShowHardCursor )
{
SetCursor(NULL);
return true;
}
break;
case WM_DESTROY: //退出消息
PostQuitMessage( 0 );
RunGame=false;
break;
case WM_GETMINMAXINFO:
{
// 窗口模式下不让改变大小
// 窗口固定到 640x480 (客户区)
MINMAXINFO* pMinMax = (MINMAXINFO*) lParam;
DWORD dwFrameWidth = GetSystemMetrics( SM_CXSIZEFRAME );
DWORD dwFrameHeight = GetSystemMetrics( SM_CYSIZEFRAME );
//DWORD dwMenuHeight = GetSystemMetrics( SM_CYMENU );
DWORD dwCaptionHeight = GetSystemMetrics( SM_CYCAPTION );
pMinMax->ptMinTrackSize.x = MainWidth + dwFrameWidth * 2;
pMinMax->ptMinTrackSize.y = MainHeight + dwFrameHeight * 2 +
dwCaptionHeight;
pMinMax->ptMaxTrackSize.x = pMinMax->ptMinTrackSize.x;
pMinMax->ptMaxTrackSize.y = pMinMax->ptMinTrackSize.y;
}
return 0L;
}
//调用缺省消息处理过程
return DefWindowProc(hWnd, message, wParam, lParam);
}
//-----------------------------------------------
//更新到屏幕或表面lpSurf
void UpdateScreen(LPDIRECTDRAWSURFACE lpSurf, RECT DestRect)
{
if( g_eDisplayState==DS_NORMAL ) //正常显示
{
if( bShowFps )
font.PrintText(lpDDSBack, 20, 460,"FPS:%d", CountSpeed());
//debug模式的显示
if( g_bDebug&&g_ePlayState == PS_MAIN)
{
DebugFont.PrintText(lpDDSBack,500,400,"Cheating Enable");
DebugFont.PrintText(lpDDSBack,500,440,
"Process = %d",Script.GetValue("$process"));
DebugFont.PrintText(lpDDSBack,500,410,"Hp = %d...Mp = %d",role[0].Propertiy.Hp,role[0].Propertiy.Mp);
DebugFont.PrintText(lpDDSBack,500,420,"Ap = %d...Dp = %d",role[0].Propertiy.Attack,role[0].Propertiy.Defend);
DebugFont.PrintText(lpDDSBack,500,430,"Level = %d",role[0].Propertiy.Level);
DebugFont.PrintText(lpDDSBack,100,100,"(%d,%d)",point.x,point.y);
}
if( WindowMode==0 ) //全屏
{
Blt(lpSurf, 0, 0, lpDDSBack, RectScreen, false);
}
else //窗口
{
lpSurf->Blt( &DestRect, lpDDSBack, &RectScreen, DDBLTFAST_NOCOLORKEY, 0);
}
}
else if( g_eDisplayState==DS_NIGHT ) //夜晚
{
if( bShowFps )
font.PrintText(lpDDSBack, 220, 260, "FPS:%d", CountSpeed());
int sx= role[0].State.x - map.sx - _point_x(6);
int sy= role[0].State.y - map.sy - _point_y(5);
Alpha_Blt(lpDDSBack, sx, sy, lpDDSMask, GetRect(0,0,384,288));
if( WindowMode==0 ) //全屏
{
RECT s_rect={sx, sy, sx+384, sy+288};
Blt(lpSurf, sx, sy, lpDDSBack, s_rect, false);
}
else //窗口
{
RECT d_rect={DestRect.left+sx, DestRect.top+sy,
DestRect.left+sx+384, DestRect.top+sy+288};
RECT s_rect={sx, sy, sx+384, sy+288};
if( d_rect.left<DestRect.left )
{
s_rect.left=s_rect.left+DestRect.left-d_rect.left;
d_rect.left=DestRect.left;
}
if( d_rect.top<DestRect.top )
{
s_rect.top=s_rect.top+DestRect.top-d_rect.top;
d_rect.top=DestRect.top;
}
if( d_rect.right>DestRect.right )
{
s_rect.right-=d_rect.right-DestRect.right;
d_rect.right=DestRect.right;
}
if( d_rect.bottom>DestRect.bottom )
{
s_rect.bottom-=d_rect.bottom-DestRect.bottom;
d_rect.bottom=DestRect.bottom;
}
_SBlt(lpSurf, d_rect, lpDDSBack, s_rect, false);
}
}
nFrames++; //桢数
}
//更新到屏幕-对话
void UpdateScreen_Dialog(LPDIRECTDRAWSURFACE lpDDSurf)
{
if( WindowMode==0 ) //全屏
Blt(lpDDSPrimary, 0, 0, lpDDSurf, RectScreen, false);
else
lpDDSPrimary->Blt( &RectWindow, lpDDSurf, &RectScreen, DDBLTFAST_NOCOLORKEY, 0);
nFrames++; //桢数
}
//画鼠标光标
void ShowMouseCursor(LPDIRECTDRAWSURFACE lpSurf, bool bNormal)
{
//目的地光标
CCursor::Show(CCursor::CS_CHANGEMAP, lpSurf,
CCursor::GetCursor(1).pPic.Getx()-map.sx,
CCursor::GetCursor(1).pPic.Gety()-map.sy ); //显示目的地光标
//画鼠标光标
if( g_ePlayState == PS_MAIN )
{
int n = map.Width*cy+cx;
if( bNormal && cx<map.Width && cy<map.Height )
{
CCursor::Show(map.Cell[n].MouseType, lpSurf, point.x, point.y);
}
else
{
CCursor::Show(CCursor::CS_NORMAL, lpSurf, point.x, point.y);
}
}
else
{
CCursor::Show(CCursor::CS_NORMAL, lpSurf, point.x, point.y);
}
}
//把当前屏幕复制到后台表面
void GetPrimarySurface(LPDIRECTDRAWSURFACE surf)
{
if( WindowMode==0 ) //全屏
Blt(surf, 0, 0, lpDDSPrimary, RectScreen, false);
else
Blt(surf, 0, 0, lpDDSPrimary, RectWindow, false);
}
//把游戏画面复制到一个表面上(不画鼠标和FPS等)
void GetGameSurface(LPDIRECTDRAWSURFACE surf)
{
if( g_ePlayState == PS_MAIN ||g_ePlayState == PS_Null)
{
if( g_eDisplayState == DS_NIGHT ) //夜晚模式
{
FillSurface(surf,RGB16(0)); //清除
map.ShowMap(false,surf); //显示地图
//计算alpha显示的位置
//下面是把光圈alpha显示到表面上
int sx= role[0].State.x - map.sx - _point_x(6);
int sy= role[0].State.y - map.sy - _point_y(5);
RECT rect;
rect = GetRect(0,0,384,288);
int xTemp=sx,yTemp=sy;
if(sx<0)
{
rect.left = 0-sx;
sx =0;
}
if(sy<0)
{
rect.top = 0-sy;
sy =0;
}
if(xTemp>ScreenWidth-384)
rect.right = xTemp+384-ScreenWidth+sx;
if(yTemp>ScreenHeight-288)
rect.bottom = yTemp+288-ScreenHeight+sy;
Alpha_Blt(surf, sx, sy, lpDDSMask,rect);
}
else
{
map.ShowMap(false); //直接显示
Blt(surf, 0, 0, lpDDSBack, RectScreen, false);
}
}
else if(g_ePlayState == PS_FIGHT)
Fight.GetFightGameSurface(surf); //战斗的时候
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -