📄 game_hero.cpp
字号:
#include "..\Include\Game_Hero.h"
Game_Hero::Game_Hero(WCHAR * name,Game_Terrain* Game_Terrain,float scale){
m_pGame_SkinMesh=Game_Resource::Instance()->GetSkinMesh(name);
m_pMouseMesh=Game_Resource::Instance()->GetSkinMesh(L"Arrow.X");
//m_pMouseMesh->m_fScale=5;
m_bMousShow=false;
m_pGame_Terrain=Game_Terrain;
m_pGame_SkinMesh->m_fScale=scale;
m_pGame_SkinMesh->m_vPos=D3DXVECTOR3(300,0,0);
}
void Game_Hero::Render(float timeStep){
if (m_pGame_SkinMesh->m_MouseMove){
m_pGame_SkinMesh->SetAnimationName("run");
if(!m_pGame_SkinMesh->m_KeyMove){
m_pGame_SkinMesh->WalkFoward(timeStep*m_pGame_SkinMesh->m_speed1,m_pGame_Terrain);
}
if (m_pGame_SkinMesh->DistanceOfTwoVec3(m_pGame_SkinMesh->m_vPos,m_pGame_SkinMesh->m_destpoint)<=10){
m_pGame_SkinMesh->SetAltitude(m_pGame_SkinMesh->m_destpoint.y);
m_pGame_SkinMesh->SetAnimationName("wait");
m_pGame_SkinMesh->m_MouseMove=false;
m_bMousShow=false;
}
}
if (m_pGame_SkinMesh->m_bnextAnim){
float couTime = (float)m_pGame_SkinMesh->m_pCurAnimSet->GetPeriod();
if (m_pGame_SkinMesh->IsAnimEnd(timeStep)){
m_pGame_SkinMesh->SetAnimationName(m_pGame_SkinMesh->m_strAnim);
m_pGame_SkinMesh->m_CurTime = 0.0f;
timeStep=0.0f;
}
}
m_pGame_SkinMesh->Render(timeStep,m_pGame_SkinMesh->m_vPos,m_pGame_SkinMesh->m_fAngle,m_pGame_SkinMesh->m_fScale);
if(m_bMousShow){
m_pMouseMesh->Render(timeStep,D3DXVECTOR3(m_mouseCross.x,m_mouseCross.y,m_mouseCross.z),m_pMouseMesh->m_fAngle,m_pMouseMesh->m_fScale,false);
//m_bMousShow=false;
}
}
HRESULT Game_Hero::SetInput2D(POINT pt){
return S_OK;
}
HRESULT Game_Hero::SetInput3D(FLOAT timeDelta){
//static Game_QuietMesh* & BookSeller=g_sGlobal.g_pGameApp->m_Game_QuietMesh.at(1);
//不可控制UI
static Game_UIBar* & SkillBar1 =g_sGlobal.g_pGameApp->m_Game_UIBar.at(0);
static Game_UIBar* & Head =g_sGlobal.g_pGameApp->m_Game_UIBar.at(1);
static Game_UIBar* & BagMenu =g_sGlobal.g_pGameApp->m_Game_UIBar.at(2);
//可控制菜单UI
static Game_UIBar* & People =g_sGlobal.g_pGameApp->m_Game_UIBar.at(3);
static Game_UIBar* & WOW_ESC =g_sGlobal.g_pGameApp->m_Game_UIBar.at(4);
static Game_UIBar* Bag[6];
for(int i=0;i<6;i++){
Bag[i]=g_sGlobal.g_pGameApp->m_Game_UIBar.at(i+5);
}
static Game_UIBar* Shop[5];
for(int i=0;i<5;i++){
Shop[i]=g_sGlobal.g_pGameApp->m_Game_UIBar.at(i+11);
}
FLOAT dForward=0,dSide=0;
FLOAT fYaw=0,fPitch=0;
g_sGlobal.g_pGameApp->m_pGame_Camera->MoveRelative(dSide,(g_sGlobal.g_pGame_Input->m_MouseState).lZ/12.0f);
if(g_sGlobal.g_pGameApp->m_pGame_Camera->m_Distance<=40)
g_sGlobal.g_pGameApp->m_pGame_Camera->m_Distance=40;
if(g_sGlobal.g_pGameApp->m_pGame_Camera->m_Distance>=400)
g_sGlobal.g_pGameApp->m_pGame_Camera->m_Distance=400;
//m_pGame_SkinMesh->SetAnimationName("wait");//idle,walk,get,skill1,skill2
m_pGame_SkinMesh->m_KeyMove=false;
if(WOW_ESC->m_pInterface->m_bShow){
for(vector<Game_UIBar*>::iterator i=g_sGlobal.g_pGameApp->m_Game_UIBar.begin();
i!=g_sGlobal.g_pGameApp->m_Game_UIBar.end();
i++){
if((*i)!=WOW_ESC){
(*i)->m_pInterface->m_bEnable=false;
}
}
}
if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_ESCAPE)){//ESC设置菜单
for(vector<Game_UIBar*>::iterator i=g_sGlobal.g_pGameApp->m_Game_UIBar.begin();
i!=g_sGlobal.g_pGameApp->m_Game_UIBar.end();
i++){//UI列表
if((*i)!=WOW_ESC&&(*i)!=SkillBar1&&
(*i)!=Head&&(*i)!=BagMenu&&
(*i)->m_pInterface->m_bShow){//关闭所有除ESC和技能以外UI,ESC的UI不显示
(*i)->m_pInterface->m_bShow=false;
WOW_ESC->m_pInterface->m_bEnable=false;
}
if(!People->m_pInterface->m_bShow&&
WOW_ESC->m_pInterface->m_bEnable){//如果商店是关的并且ESC可用,才显示ESC的UI
WOW_ESC->m_pInterface->m_bShow=!WOW_ESC->m_pInterface->m_bShow;
WOW_ESC->m_pInterface->m_bEnable=false;
}
}
}
else
WOW_ESC->m_pInterface->m_bEnable=true;
//开包
if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_B)){
if(Bag[0]->m_pInterface->m_bEnable){
for(int i=0;i<6;i++){
Bag[i]->m_pInterface->m_bShow=!Bag[i]->m_pInterface->m_bShow;
}
Bag[0]->m_pInterface->m_bEnable=false;
}
}
else
Bag[0]->m_pInterface->m_bEnable=true;
//开属性栏
if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_C)){
if(People->m_pInterface->m_bEnable){//如果商店是关的并且ESC可用,才显示ESC的UI
People->m_pInterface->m_bShow=!People->m_pInterface->m_bShow;
People->m_pInterface->m_bEnable=false;
}
}
else
People->m_pInterface->m_bEnable=true;
if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_W)||
g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_S)||
m_pGame_SkinMesh->m_MouseMove){//如果前后走动,关闭所有除ESC和技能以外UI
if(Shop[0]->m_pInterface->m_bShow&&Bag[0]->m_pInterface->m_bShow){
for(int i=0;i<5;i++){
Shop[i]->m_pInterface->m_bShow=false;
}
for(int i=0;i<6;i++){
Bag[i]->m_pInterface->m_bShow=false;
}
}
}
static bool run=false;
if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_W)){
m_pGame_SkinMesh->m_KeyMove=true;
dForward+=m_pGame_SkinMesh->m_speed1*timeDelta;
m_pGame_SkinMesh->SetAnimationName("run");
m_pGame_SkinMesh->m_MouseMove=false;
run=true;
}
else if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_S)){
m_pGame_SkinMesh->m_KeyMove=true;
dForward-=m_pGame_SkinMesh->m_speed1*timeDelta;
m_pGame_SkinMesh->SetAnimationName("run");
m_pGame_SkinMesh->m_MouseMove=false;
run=true;
}
else if(run){
m_pGame_SkinMesh->SetAnimationName("wait");
run=false;
}
if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_A)){
m_pGame_SkinMesh->m_KeyMove=true;
dSide-=m_pGame_SkinMesh->m_speed2*timeDelta;
m_pGame_SkinMesh->m_MouseMove=false;
}
if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_D)){
m_pGame_SkinMesh->m_KeyMove=true;
dSide+=m_pGame_SkinMesh->m_speed2*timeDelta;
m_pGame_SkinMesh->m_MouseMove=false;
}
if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_1)){
m_pGame_SkinMesh->m_pAnimController->GetTrackAnimationSet(0,&m_pGame_SkinMesh->m_pCurAnimSet);
if(!m_pGame_SkinMesh->m_bnextAnim){
float s=m_pGame_SkinMesh->m_pAnimController->GetTime();
m_pGame_SkinMesh->SetAnimationName("attack2");
float t=m_pGame_SkinMesh->m_pAnimController->GetTime();
m_pGame_SkinMesh->m_bnextAnim=true;
}
}
else if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_2)){
m_pGame_SkinMesh->m_pAnimController->GetTrackAnimationSet(0,&m_pGame_SkinMesh->m_pCurAnimSet);
if(!m_pGame_SkinMesh->m_bnextAnim){
float s=m_pGame_SkinMesh->m_pAnimController->GetTime();
m_pGame_SkinMesh->SetAnimationName("attack3");
float t=m_pGame_SkinMesh->m_pAnimController->GetTime();
m_pGame_SkinMesh->m_bnextAnim=true;
}
}
else if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_3)){
m_pGame_SkinMesh->m_pAnimController->GetTrackAnimationSet(0,&m_pGame_SkinMesh->m_pCurAnimSet);
if(!m_pGame_SkinMesh->m_bnextAnim){
float s=m_pGame_SkinMesh->m_pAnimController->GetTime();
m_pGame_SkinMesh->SetAnimationName("attack4");
float t=m_pGame_SkinMesh->m_pAnimController->GetTime();
m_pGame_SkinMesh->m_bnextAnim=true;
}
}
else if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_4)){
m_pGame_SkinMesh->m_pAnimController->GetTrackAnimationSet(0,&m_pGame_SkinMesh->m_pCurAnimSet);
if(!m_pGame_SkinMesh->m_bnextAnim){
float s=m_pGame_SkinMesh->m_pAnimController->GetTime();
m_pGame_SkinMesh->SetAnimationName("attack5");
float t=m_pGame_SkinMesh->m_pAnimController->GetTime();
m_pGame_SkinMesh->m_bnextAnim=true;
}
}
else if(g_sGlobal.g_pGame_Input->GetIsKeyDown(DIK_5)){
m_pGame_SkinMesh->m_pAnimController->GetTrackAnimationSet(0,&m_pGame_SkinMesh->m_pCurAnimSet);
if(!m_pGame_SkinMesh->m_bnextAnim){
float s=m_pGame_SkinMesh->m_pAnimController->GetTime();
m_pGame_SkinMesh->SetAnimationName("attack6");
float t=m_pGame_SkinMesh->m_pAnimController->GetTime();
m_pGame_SkinMesh->m_bnextAnim=true;
}
}
else{
m_pGame_SkinMesh->m_bnextAnim=false;
}
if(g_sGlobal.g_pGame_Input->GetIsKeyDown(MK_RIGHT)){
float fYaw=g_sGlobal.g_pGame_Input->GetLX()*0.2f*D3DX_PI/180;
float fPitch=g_sGlobal.g_pGame_Input->GetLY()*0.2f*D3DX_PI/180;
g_sGlobal.g_pGameApp->m_pGame_Camera->YawPitchAt(fYaw,fPitch);
//m_pGame_SkinMesh->Turn(fYaw);
}
if(g_sGlobal.g_pGame_Input->GetIsKeyDown(MK_LEFT)){
POINT pt;
GetCursorPos(&pt);
ScreenToClient(g_sGlobal.g_hwnd,&pt);
if(FAILED(SetInput2D(pt)))
return E_FAIL;
else{
if(Pick_Game_Terrain(pt)){
m_pGame_Terrain->GetTerrainVertex(&m_mouseCross,m_indexFace,m_u,m_v);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -