added slow-mo
This commit is contained in:
parent
2ee288cbe0
commit
635960007c
@ -105,9 +105,38 @@ AnimationState Character::resolveActiveState() const {
|
||||
return AnimationState::STAND;
|
||||
}
|
||||
|
||||
float Character::getSpeedMultiplier(float transitionProgress) const {
|
||||
|
||||
if (isPlayer) {
|
||||
return 1.0f + (1.5f - 1.0f) * transitionProgress;
|
||||
}
|
||||
else {
|
||||
return 1.0f - (1.0f - 0.5f) * transitionProgress;
|
||||
}
|
||||
}
|
||||
|
||||
void Character::update(int64_t deltaMs) {
|
||||
if (initialHp <= 0.f) initialHp = hp;
|
||||
|
||||
if (slowMoTimeRemaining > 0.0f) {
|
||||
slowMoTimeRemaining -= static_cast<float>(deltaMs) / 1000.0f;
|
||||
|
||||
float transitionProgress;
|
||||
if (slowMoTimeRemaining > slowMoActiveTime - slowMoTransitionTime) {
|
||||
float timeInTransition = slowMoActiveTime - slowMoTimeRemaining;
|
||||
transitionProgress = (std::min)(1.0f, timeInTransition / slowMoTransitionTime);
|
||||
}
|
||||
else if (slowMoTimeRemaining < slowMoTransitionTime) {
|
||||
transitionProgress = (std::max)(0.0f, slowMoTimeRemaining / slowMoTransitionTime);
|
||||
}
|
||||
else {
|
||||
transitionProgress = 1.0f;
|
||||
}
|
||||
|
||||
float speedMultiplier = getSpeedMultiplier(transitionProgress);
|
||||
deltaMs = static_cast<int64_t>(static_cast<float>(deltaMs) * speedMultiplier);
|
||||
}
|
||||
|
||||
|
||||
//weaponInitialRotation = Eigen::AngleAxisf(x/180.0, Eigen::Vector3f::UnitZ()).toRotationMatrix();
|
||||
//weaponInitialRotation = Eigen::AngleAxisf(-M_PI*0.5, Eigen::Vector3f::UnitZ()).toRotationMatrix();
|
||||
|
||||
@ -132,6 +132,10 @@ public:
|
||||
|
||||
SparkEmitter hitSparkEmitter;
|
||||
|
||||
float slowMoTimeRemaining = 0.0f;
|
||||
float slowMoTransitionTime = 0.5f;
|
||||
float slowMoActiveTime = 6.0f;
|
||||
float getSpeedMultiplier(float transitionProgress) const;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
20
src/Game.cpp
20
src/Game.cpp
@ -546,6 +546,12 @@ namespace ZL
|
||||
case SDLK_l:
|
||||
x = x - 0.002;
|
||||
break;
|
||||
|
||||
case SDLK_c:
|
||||
std::cout << "SLOW-MO activated!" << std::endl;
|
||||
activateSlowMoEffect();
|
||||
break;
|
||||
|
||||
case SDLK_RETURN:
|
||||
|
||||
default:
|
||||
@ -592,6 +598,20 @@ namespace ZL
|
||||
return n;
|
||||
}
|
||||
|
||||
void Game::activateSlowMoEffect() {
|
||||
if (!currentLocation) return;
|
||||
|
||||
if (currentLocation->player) {
|
||||
currentLocation->player->slowMoTimeRemaining = currentLocation->player->slowMoActiveTime;
|
||||
}
|
||||
|
||||
for (auto& npc : currentLocation->npcs) {
|
||||
if (npc) {
|
||||
npc->slowMoTimeRemaining = npc->slowMoActiveTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Game::enterCameraDragMode(int eventX, int eventY)
|
||||
{
|
||||
cameraDragging = true;
|
||||
|
||||
@ -55,6 +55,8 @@ namespace ZL {
|
||||
|
||||
MenuManager menuManager;
|
||||
|
||||
void activateSlowMoEffect();
|
||||
|
||||
private:
|
||||
// Unified pointer handling: mouse-left and a single touch share one path.
|
||||
// A press becomes a tap (interact / walk-to) on release if it never crossed
|
||||
|
||||
Loading…
Reference in New Issue
Block a user