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