void Player::ChangePlayerState(PlayerState state) { currentState = state; SetAnimationName(animationNames[state].c_str(), &selectedAnimationLength); animController->SetTrackPosition(0, 0.0f); currentAnimationTime = 0; }
void Minion::ChangeCharacterState(CharacterState state) { currentState = state; SetAnimationName(animationNames[state].c_str(), &selectedAnimationLength); animController->SetTrackPosition(0, 0.0f); animController->SetTrackSpeed(0, 1.0f); currentAnimationTime = 0.0f; }
bool CControl::OnPropertyChange( void* pVariableAddr, CSerializer* pSerializer ) { bool bRet = super::OnPropertyChange( pVariableAddr, pSerializer ); if ( !bRet ) { if ( &m_vec2AbsolutePosition == pVariableAddr ) { CVec2 absolutePosition; DeserializeVariable( absolutePosition, pSerializer ); SetAbsolutePosition( absolutePosition ); bRet = true; } else if ( &m_vec2PercentPosition == pVariableAddr ) { CVec2 percentPosition; DeserializeVariable( percentPosition, pSerializer ); SetPercentPosition( percentPosition ); bRet = true; } else if ( &m_vec2PercentSize == pVariableAddr ) { CVec2 percentSize; DeserializeVariable( percentSize, pSerializer ); SetPercentSize( percentSize ); bRet = true; } else if( &m_vec2Size == pVariableAddr ) { CVec2 size; DeserializeVariable( size, pSerializer ); SetSize( size ); bRet = true; } else if( &m_vec2Anchor == pVariableAddr ) { CVec2 anchor; DeserializeVariable( anchor, pSerializer ); SetAnchor( anchor ); bRet = true; } else if( &m_color == pVariableAddr ) { CColor color; DeserializeVariable( color, pSerializer ); SetColor( color ); bRet = true; } else if( &m_strPressAnimationName == pVariableAddr ) { TString animationName; DeserializeVariable( animationName, pSerializer ); SetAnimationName( animationName ); bRet = true; } } return bRet; }
void Player::UpdateAndRender() { D3DXVECTOR3 pos = position; D3DXVECTOR3 direction = GameManager::GetCamera()->GetCameraDirectionXZ(); D3DXVECTOR3 up = D3DXVECTOR3(0, 1, 0); D3DXVECTOR3 right; D3DXVECTOR3 forward = D3DXVECTOR3(0, 0, 1); D3DXVec3Cross(&right, &direction, &up); rotationAngle = 135.0f; D3DXMATRIXA16 rotation; rotationAngle += acosf(D3DXVec3Dot(&direction, &forward)); D3DXMatrixRotationY(&rotation, rotationAngle); switch (currentState) { //Idle, Move만 특별한 State. changeState로 바꾸지 않는다. case PlayerState::PLAYER_IDLE: case PlayerState::PLAYER_MOVE: { if (hm->GetHeight(pos, pos.x, pos.z) != false) { float tick = (float)GameManager::GetTick(); bool move = false; if ((GetAsyncKeyState('W') & 0x8000) != 0) { pos -= (-direction * moveSpeed * tick); SetAnimationName("Run"); move = true; } else if ((GetAsyncKeyState('S') & 0x8000) != 0) { pos += (-direction * moveSpeed * tick); move = true; } if ((GetAsyncKeyState('A') & 0x8000) != 0) { pos -= (-right * moveSpeed * tick); move = true; } else if ((GetAsyncKeyState('D') & 0x8000) != 0) { pos += (-right * moveSpeed * tick); move = true; } if (!move) SetAnimationName("Idle"); else SetAnimationName("Run"); //state transition if ((GetAsyncKeyState(VK_SPACE) & 0x8000) != 0) { ChangePlayerState(PlayerState::PLAYER_ATTACK); } } } break; case PlayerState::PLAYER_ATTACK: { double tick = GameManager::GetTick(); currentAnimationTime += tick; if (currentAnimationTime >= selectedAnimationLength) { ChangePlayerState(PlayerState::PLAYER_IDLE); } break; } default: break; } SetPosition(pos); //여기부턴 skinnedmesh와 같음 if (animController) { animController->AdvanceTime(GameManager::GetTick(), nullptr); } if (rootFrame) { D3DXMATRIXA16 local; D3DXMatrixTranslation(&local, position.x, position.y, position.z); D3DXMATRIXA16 scale; D3DXMatrixScaling(&scale, scaleFactor.x, scaleFactor.y, scaleFactor.z); local = scale*rotation*local; Update(rootFrame, &local); Render(rootFrame); } }