bool InputManager::IsMouseKeyDownOnce(int key) { return (IsMouseKeyDown(key) && !((prevMouseState.rgbButtons[key] & 0x80) > 0)); }
void Player::HandleInput(float deltatime) { auto i = System::GetInput(); int x, y; XMVECTOR moveVec = XMVectorZero(); XMVECTOR forward = _builder->GetEntityController()->Transform()->GetDirection(_camera); XMVECTOR right = _builder->GetEntityController()->Transform()->GetRight(_camera); XMVECTOR up = _builder->GetEntityController()->Transform()->GetUp(_camera); bool change = false; i->GetMouseDiff(x, y); if (x != 0) _builder->GetEntityController()->Transform()->RotateYaw(_camera, x * 0.1f); if (y != 0) _builder->GetEntityController()->Transform()->RotatePitch(_camera, y * 0.1f); if (i->IsKeyDown(VK_W)) { moveVec += forward; change = true; } if (i->IsKeyDown(VK_S)) { moveVec -= forward; change = true; } if (i->IsKeyDown(VK_A)) { moveVec -= right; change = true; } if (i->IsKeyDown(VK_D)) { moveVec += right; change = true; } //if (i->IsKeyDown(VK_SHIFT)) //{ // moveVec += up; // change = true; //} //if (i->IsKeyDown(VK_CONTROL)) //{ // moveVec -= up; // change = true; //} if (change) { if (i->IsKeyDown(VK_SHIFT) && _currentLight-_dashCost >= 0.0f && !_activeDash) { _activeDash = true; _lightDownBy += _dashCost; XMStoreFloat3(&_dashDir, XMVector3Normalize(moveVec)); _builder->Animation()->PlayAnimation(_camera, "dash", 2.0f); } else _builder->GetEntityController()->Transform()->MoveAlongVector(_camera, XMVector3Normalize(moveVec), _speedFactor*deltatime); } if (i->IsKeyPushed(VK_T)) { float offset = (_reservedLight * _maxLight / 20.0f)*BAR_MAXSIZE*_screenPercentWidth; _reservedLight = 0.5f; float delta = (_reservedLight * _maxLight / 20.0f)*BAR_MAXSIZE*_screenPercentWidth - offset; _lightDownBy += _maxLight*0.5f; _builder->Animation()->PlayAnimation(_lightReservedBar, "update", delta, offset); } if (i->IsKeyPushed(VK_Q)) { _ChangePower(); } if (i->IsMouseKeyDown(VK_LBUTTON)) { if (_weapons[_currentWep]->Shoot(_camera)) { _shotsFired++; } } if (!_weapons[_currentWep]->HasAmmo()) { _weapons[_currentWep]->setActive(false); _currentWep = Weapons::Basic; _weapons[_currentWep]->setActive(true); } int sde = 0; if (i->IsScrollUp(sde)) { Weapons c = _currentWep << 1; if (c._flags == 0) c._flags = 1; auto& find = _weapons.find(c); while (find == _weapons.end() || !find->second->HasAmmo()) { c._flags = c._flags << 1; if (c._flags == 0) c._flags = 1; find = _weapons.find(c); } if (!(c == _currentWep)) { _weapons[_currentWep]->setActive(false); _currentWep = c; _weapons[_currentWep]->setActive(true); } } if(i->IsScrollDown(sde)) { Weapons c = _currentWep >> 1; if (c._flags == 0) c._flags = 1 << (sizeof(unsigned int)*8-1); auto& find = _weapons.find(c); while (find == _weapons.end() || !find->second->HasAmmo()) { c._flags = c._flags >> 1; if (c._flags == 0) c._flags = 1 << (sizeof(unsigned int) * 8 - 1); find = _weapons.find(c); } if (!(c == _currentWep)) { _weapons[_currentWep]->setActive(false); _currentWep = c; _weapons[_currentWep]->setActive(true); } }