void Player::Update(float elapsedTime) { SGD::InputManager *ptInput = SGD::InputManager::GetInstance(); if (ptInput->IsKeyPressed(SGD::Key::Space) || ptInput->IsKeyPressed(SGD::Key::W)) { m_bPendingJump = true; } Puff* ptPuff = dynamic_cast<Puff*>(GameplayState::GetInstance()->GetPuff()); if (ptInput->IsKeyPressed(SGD::Key::MouseLeft)) { // Allocate a CreateLaserMessage CreateBulletMessage* pMsg = new CreateBulletMessage( ptPuff->GetPosition().x + ptPuff->GetSize().width / 4, ptPuff->GetPosition().y + ptPuff->GetSize().height / 4, //m_ptPosition.x + m_szSize.width / 2, //m_ptPosition.y + m_szSize.height / 2, m_fRotation, BULLET_A); // Queue the message into the Message System pMsg->QueueMessage(); pMsg = nullptr; } //============================================================= // independent phycis timer/buffer ////////////////////////////////////////////////////////////// m_fAccumulatedTime += elapsedTime; if (m_fAccumulatedTime < FRAME) return; elapsedTime = FRAME; while (m_fAccumulatedTime >= FRAME) { m_fAccumulatedTime -= FRAME; } //============================================================= // independent phycis timer/buffer ////////////////////////////////////////////////////////////// if (ptInput->IsKeyDown(SGD::Key::A)) { m_bIsFlipped = true; if (m_fSpeed < m_fMaxSpeed) { m_fSpeed += m_fAccelerationRate * elapsedTime; } } if (ptInput->IsKeyDown(SGD::Key::D)) { m_bIsFlipped = false; if (m_fSpeed > -m_fMaxSpeed) { m_fSpeed -= m_fAccelerationRate * elapsedTime; } } // left and right control if (!(ptInput->IsKeyDown(SGD::Key::D) || ptInput->IsKeyDown(SGD::Key::A))) { if (m_ptPosition.y + m_szSize.height / 2 == GameplayState::GetInstance()->GetWorldSize().height - m_fGroundOffset) { if (m_fSpeed > 0) { if (m_fSpeed - (m_fAccelerationRate * 2.0f) * elapsedTime < 0) { m_fSpeed = 0; } else { m_fSpeed -= (m_fAccelerationRate * 2.0f) * elapsedTime; } } else if (m_fSpeed < 0) { m_fSpeed += (m_fAccelerationRate * 2.0f) * elapsedTime; } } } if (m_bPendingJump) { //pre-Jump trigger "space and w" if (m_ptPosition.y + m_szSize.height / 2 == GameplayState::GetInstance()->GetWorldSize().height - m_fGroundOffset) { m_vtVelocity.y = -1500.0f; } m_bPendingJump = false; } SGD::Vector vtNewVelocity{ -m_fSpeed, 0 }; m_vtVelocity.x = vtNewVelocity.x; m_vtVelocity += m_vtGravity; if (m_fSpeed > 0) { m_pCharaterAnim->Pause(false); } else if (m_fSpeed < 0) { m_pCharaterAnim->Pause(false); } else { m_pCharaterAnim->Pause(true); m_pCharaterAnim->Restart(true, 1.0f); } if (m_pCharaterAnim != nullptr) { m_pCharaterAnim->Update(elapsedTime, m_bIsFlipped); Entity::Update(elapsedTime); } StayInWorld(); }