summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-30 00:51:30 +0200
committerAki <please@ignore.pl>2022-04-30 00:51:30 +0200
commit162da719ee2382562fd7053cbe93dfa589d85246 (patch)
tree80fde7ad396a0f0dea7cbf1993fe9b8a2e60b004
parent77d3eda4f061c39ed9e922f9f46177c8728dc0f7 (diff)
downloadbullethell2022-factor-damp.zip
bullethell2022-factor-damp.tar.gz
bullethell2022-factor-damp.tar.bz2
Changed to use factor-based velocity dampingfactor-damp
-rw-r--r--Player.cpp28
1 files changed, 8 insertions, 20 deletions
diff --git a/Player.cpp b/Player.cpp
index 94371c1..facfaf4 100644
--- a/Player.cpp
+++ b/Player.cpp
@@ -1,6 +1,7 @@
#include "Player.h"
#include <algorithm>
+#include <cmath>
#include <memory>
#include <raylib.h>
@@ -10,7 +11,7 @@
static constexpr float ACCELERATION {1800};
static constexpr float MAX_SPEED {180};
-static constexpr float DAMP {2200};
+static constexpr float DAMP {3e-10f};
static constexpr float MARGIN {0.3f};
static constexpr float HIT_INVUL {1.2f};
static constexpr float RADIUS {4};
@@ -74,25 +75,12 @@ damped_velocity(const float dt, const float direction, const float velocity)
{
if (direction > 0 || direction < 0)
return velocity + direction * ACCELERATION * dt;
- if (velocity > 0) {
- if (velocity > MARGIN) {
- const float next = velocity - dt * DAMP;
- if (next < MARGIN)
- return 0;
- else
- return next;
- }
- return 0;
- }
- if (velocity < 0) {
- if (velocity < MARGIN) {
- const float next = velocity + dt * DAMP;
- if (next > MARGIN)
- return 0;
- else
- return next;
- }
- return 0;
+ if (velocity > MARGIN || velocity < -MARGIN) {
+ const float next = velocity * std::pow(DAMP, dt);
+ if (next < MARGIN && next > -MARGIN)
+ return 0;
+ else
+ return next;
}
return 0;
}