void World::adaptPlayerVelocity() { sf::Vector2f velocity = mPlayerSpaceship->getVelocity(); // If moving diagonally, reduce velocity (to have always same velocity) if (velocity.x != 0.f && velocity.y != 0.f) mPlayerSpaceship->setVelocity(velocity / std::sqrt(2.f)); // Add scrolling velocity float xCoord = sin(degreeToRadians(mPlayerSpaceship->getRotation())); float yCoord = cos(degreeToRadians(mPlayerSpaceship->getRotation())); mPlayerSpaceship->accelerate(-mScrollSpeed * xCoord, +mScrollSpeed * yCoord); }
LRESULT CALLBACK App::WindowProc(UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: break; case WM_PAINT: break; case WM_COMMAND: if ((HWND)lParam == mButton) { int velocity = getTextAndConvertToInt(mVelEditBox); int angleInDegree = getTextAndConvertToInt(mAngleEditBox); ((ProcessRunnable*)mProcessRunnable)->start((float)velocity, degreeToRadians(angleInDegree)); } break; case WM_START_ANIMATION: break; case WM_RENDER_WND: render(); break; case WM_UPDATE_WND: InvalidateRect(mHwnd, NULL, TRUE); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(mHwnd, msg, wParam, lParam); } }
void Planet::updateMovementPattern(sf::Time dt) { const std::vector<Direction>& directions = Table[mType].directions; if (!directions.empty()) { float distanceToTravel = directions[mDirectionIndex].distance; if (mTravelledDistance > distanceToTravel) { mDirectionIndex = (mDirectionIndex + 1) % directions.size(); mTravelledDistance = 0.f; } float radians = degreeToRadians(directions[mDirectionIndex].angle + 90.f); float vx = getMaxSpeed() * std::cos(radians); float vy = getMaxSpeed() * std::sin(radians); setVelocity(vx, vy); mTravelledDistance += getMaxSpeed() * dt.asSeconds(); } }