diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/effect_system.cpp | 44 | ||||
-rw-r--r-- | src/effect_system.h | 39 | ||||
-rw-r--r-- | src/interpolation.cpp | 19 | ||||
-rw-r--r-- | src/interpolation.h | 26 |
4 files changed, 64 insertions, 64 deletions
diff --git a/src/effect_system.cpp b/src/effect_system.cpp index 4dff13c..9b24d3e 100644 --- a/src/effect_system.cpp +++ b/src/effect_system.cpp | |||
@@ -4,23 +4,9 @@ | |||
4 | void EffectSystem::tick(double dt) { | 4 | void EffectSystem::tick(double dt) { |
5 | if (game_.isGameplayPaused()) return; | 5 | if (game_.isGameplayPaused()) return; |
6 | 6 | ||
7 | if (screenFade_ != screenFadeDest_) { | 7 | screenFade_.tick(dt); |
8 | screenFadeThus_ += dt; | 8 | mapFade_.tick(dt); |
9 | if (screenFadeThus_ >= screenFadeLength_) { | 9 | circleEffect_.tick(dt); |
10 | screenFadeThus_ = screenFadeLength_; | ||
11 | } | ||
12 | |||
13 | screenFade_ = (screenFadeDest_ - screenFadeStart_) / screenFadeLength_ * screenFadeThus_ + screenFadeStart_; | ||
14 | } | ||
15 | |||
16 | if (mapFade_ != mapFadeDest_) { | ||
17 | mapFadeThus_ += dt; | ||
18 | if (mapFadeThus_ >= mapFadeLength_) { | ||
19 | mapFadeThus_ = mapFadeLength_; | ||
20 | } | ||
21 | |||
22 | mapFade_ = (mapFadeDest_ - mapFadeStart_) / mapFadeLength_ * mapFadeThus_ + mapFadeStart_; | ||
23 | } | ||
24 | 10 | ||
25 | if (cameraShaking_) { | 11 | if (cameraShaking_) { |
26 | cameraShakeTimer_.accumulate(dt); | 12 | cameraShakeTimer_.accumulate(dt); |
@@ -37,29 +23,14 @@ void EffectSystem::tick(double dt) { | |||
37 | cameraShakeOffset_.y() = 0; | 23 | cameraShakeOffset_.y() = 0; |
38 | } | 24 | } |
39 | } | 25 | } |
40 | |||
41 | if (circleEffect_ != circleEffectDest_) { | ||
42 | circleEffectThus_ += dt; | ||
43 | if (circleEffectThus_ >= circleEffectLength_) { | ||
44 | circleEffectThus_ = circleEffectLength_; | ||
45 | } | ||
46 | |||
47 | circleEffect_ = (circleEffectDest_ - circleEffectStart_) / circleEffectLength_ * circleEffectThus_ + circleEffectStart_; | ||
48 | } | ||
49 | } | 26 | } |
50 | 27 | ||
51 | void EffectSystem::fadeScreen(int length, double amount) { | 28 | void EffectSystem::fadeScreen(int length, double amount) { |
52 | screenFadeStart_ = screenFade_; | 29 | screenFade_.start(length, amount); |
53 | screenFadeDest_ = amount; | ||
54 | screenFadeLength_ = length; | ||
55 | screenFadeThus_ = 0; | ||
56 | } | 30 | } |
57 | 31 | ||
58 | void EffectSystem::fadeMap(int length, double amount) { | 32 | void EffectSystem::fadeMap(int length, double amount) { |
59 | mapFadeStart_ = mapFade_; | 33 | mapFade_.start(length, amount); |
60 | mapFadeDest_ = amount; | ||
61 | mapFadeLength_ = length; | ||
62 | mapFadeThus_ = 0; | ||
63 | } | 34 | } |
64 | 35 | ||
65 | void EffectSystem::shakeCamera(int period) { | 36 | void EffectSystem::shakeCamera(int period) { |
@@ -75,8 +46,5 @@ void EffectSystem::stopShakingCamera() { | |||
75 | } | 46 | } |
76 | 47 | ||
77 | void EffectSystem::circleTransition(int length, double amount) { | 48 | void EffectSystem::circleTransition(int length, double amount) { |
78 | circleEffectStart_ = circleEffect_; | 49 | circleEffect_.start(length, amount); |
79 | circleEffectDest_ = amount; | ||
80 | circleEffectLength_ = length; | ||
81 | circleEffectThus_ = 0; | ||
82 | } | 50 | } |
diff --git a/src/effect_system.h b/src/effect_system.h index 904e6cb..b2b4669 100644 --- a/src/effect_system.h +++ b/src/effect_system.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef EFFECT_SYSTEM_H_0B497B39 | 1 | #ifndef EFFECT_SYSTEM_H_0B497B39 |
2 | #define EFFECT_SYSTEM_H_0B497B39 | 2 | #define EFFECT_SYSTEM_H_0B497B39 |
3 | 3 | ||
4 | #include "interpolation.h" | ||
4 | #include "system.h" | 5 | #include "system.h" |
5 | #include "timer.h" | 6 | #include "timer.h" |
6 | #include "vector.h" | 7 | #include "vector.h" |
@@ -41,54 +42,40 @@ public: | |||
41 | 42 | ||
42 | /* Information */ | 43 | /* Information */ |
43 | 44 | ||
44 | bool isScreenFaded() const { return screenFade_ > 0.0; } | 45 | bool isScreenFaded() const { return screenFade_.getProgress() > 0.0; } |
45 | 46 | ||
46 | double getScreenFadeProgress() const { return screenFade_; } | 47 | double getScreenFadeProgress() const { return screenFade_.getProgress(); } |
47 | 48 | ||
48 | bool isScreenFadeComplete() const { return screenFade_ == screenFadeDest_; } | 49 | bool isScreenFadeComplete() const { return screenFade_.isComplete(); } |
49 | 50 | ||
50 | bool isMapFaded() const { return mapFade_ > 0.0; } | 51 | bool isMapFaded() const { return mapFade_.getProgress() > 0.0; } |
51 | 52 | ||
52 | double getMapFadeProgress() const { return mapFade_; } | 53 | double getMapFadeProgress() const { return mapFade_.getProgress(); } |
53 | 54 | ||
54 | bool isMapFadeComplete() const { return mapFade_ == mapFadeDest_; } | 55 | bool isMapFadeComplete() const { return mapFade_.isComplete(); } |
55 | 56 | ||
56 | const vec2i& getCameraShakeOffset() const { return cameraShakeOffset_; } | 57 | const vec2i& getCameraShakeOffset() const { return cameraShakeOffset_; } |
57 | 58 | ||
58 | bool isCameraShaking() const { return cameraShaking_; } | 59 | bool isCameraShaking() const { return cameraShaking_; } |
59 | 60 | ||
60 | bool isCircleTransitionActive() const { return circleEffect_ > 0.0; } | 61 | bool isCircleTransitionActive() const { return circleEffect_.getProgress() > 0.0; } |
61 | 62 | ||
62 | double getCircleTransitionProgress() const { return circleEffect_; } | 63 | double getCircleTransitionProgress() const { return circleEffect_.getProgress(); } |
63 | 64 | ||
64 | bool isCircleTransitionComplete() const { return circleEffect_ == circleEffectDest_; } | 65 | bool isCircleTransitionComplete() const { return circleEffect_.isComplete(); } |
65 | 66 | ||
66 | private: | 67 | private: |
67 | 68 | ||
68 | Game& game_; | 69 | Game& game_; |
69 | 70 | ||
70 | double screenFade_ = 0.0; | 71 | Interpolation screenFade_; |
71 | double screenFadeDest_ = 0.0; | 72 | Interpolation mapFade_; |
72 | double screenFadeStart_ = 0.0; | 73 | Interpolation circleEffect_; |
73 | double screenFadeLength_ = 0; | ||
74 | double screenFadeThus_ = 0; | ||
75 | |||
76 | double mapFade_ = 0.0; | ||
77 | double mapFadeDest_ = 0.0; | ||
78 | double mapFadeStart_ = 0.0; | ||
79 | double mapFadeLength_ = 0.0; | ||
80 | double mapFadeThus_ = 0.0; | ||
81 | 74 | ||
82 | bool cameraShaking_ = false; | 75 | bool cameraShaking_ = false; |
83 | vec2i cameraShakeOffset_ { 0, 0 }; | 76 | vec2i cameraShakeOffset_ { 0, 0 }; |
84 | bool cameraShakeOn_ = false; | 77 | bool cameraShakeOn_ = false; |
85 | Timer cameraShakeTimer_ { 0 }; | 78 | Timer cameraShakeTimer_ { 0 }; |
86 | |||
87 | double circleEffect_ = 0.0; | ||
88 | double circleEffectDest_ = 0.0; | ||
89 | double circleEffectStart_ = 0.0; | ||
90 | double circleEffectLength_ = 0.0; | ||
91 | double circleEffectThus_ = 0.0; | ||
92 | }; | 79 | }; |
93 | 80 | ||
94 | #endif /* end of include guard: EFFECT_SYSTEM_H_0B497B39 */ | 81 | #endif /* end of include guard: EFFECT_SYSTEM_H_0B497B39 */ |
diff --git a/src/interpolation.cpp b/src/interpolation.cpp new file mode 100644 index 0000000..3c9bcf8 --- /dev/null +++ b/src/interpolation.cpp | |||
@@ -0,0 +1,19 @@ | |||
1 | #include "interpolation.h" | ||
2 | |||
3 | void Interpolation::start(int length, double amount) { | ||
4 | start_ = progress_; | ||
5 | dest_ = amount; | ||
6 | length_ = length; | ||
7 | thus_ = 0; | ||
8 | } | ||
9 | |||
10 | void Interpolation::tick(double dt) { | ||
11 | if (progress_ != dest_) { | ||
12 | thus_ += dt; | ||
13 | if (thus_ >= length_) { | ||
14 | thus_ = length_; | ||
15 | } | ||
16 | |||
17 | progress_ = (dest_ - start_) / length_ * thus_ + start_; | ||
18 | } | ||
19 | } | ||
diff --git a/src/interpolation.h b/src/interpolation.h new file mode 100644 index 0000000..d89602d --- /dev/null +++ b/src/interpolation.h | |||
@@ -0,0 +1,26 @@ | |||
1 | #ifndef INTERPOLATION_H_861230A8 | ||
2 | #define INTERPOLATION_H_861230A8 | ||
3 | |||
4 | class Interpolation { | ||
5 | public: | ||
6 | |||
7 | void start(int length, double amount); | ||
8 | |||
9 | void tick(double dt); | ||
10 | |||
11 | // Info | ||
12 | |||
13 | double getProgress() const { return progress_; } | ||
14 | |||
15 | bool isComplete() const { return progress_ == dest_; } | ||
16 | |||
17 | private: | ||
18 | |||
19 | double progress_ = 0.0; | ||
20 | double dest_ = 0.0; | ||
21 | double start_ = 0.0; | ||
22 | double length_ = 0.0; | ||
23 | double thus_ = 0.0; | ||
24 | }; | ||
25 | |||
26 | #endif /* end of include guard: INTERPOLATION_H_861230A8 */ | ||