summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-15 12:05:18 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-15 12:05:18 -0500
commitd1235174157bd498d0c148325d7c8066e3ab6ac7 (patch)
tree1f086f5c07ebbf7721d0eb14bed6c86714164dbd
parentce0628c5ad96e094db12a67d4e98b445fa873ad3 (diff)
downloadtanetane-d1235174157bd498d0c148325d7c8066e3ab6ac7.tar.gz
tanetane-d1235174157bd498d0c148325d7c8066e3ab6ac7.tar.bz2
tanetane-d1235174157bd498d0c148325d7c8066e3ab6ac7.zip
Added camera shake to lightning event
-rw-r--r--res/scripts/common.lua8
-rw-r--r--res/scripts/map2.lua11
-rw-r--r--src/effect_system.cpp28
-rw-r--r--src/effect_system.h17
-rw-r--r--src/renderer.cpp6
-rw-r--r--src/script_system.cpp4
6 files changed, 71 insertions, 3 deletions
diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 2197417..422d157 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua
@@ -131,6 +131,14 @@ function WaitForMapFade()
131 end 131 end
132end 132end
133 133
134function ShakeCamera(period)
135 effect():shakeCamera(period)
136end
137
138function StopShakingCamera()
139 effect():stopShakingCamera()
140end
141
134function SetPartyDirection(spriteId, direction) 142function SetPartyDirection(spriteId, direction)
135 animation():setSpriteDirection(spriteId, direction) 143 animation():setSpriteDirection(spriteId, direction)
136 144
diff --git a/res/scripts/map2.lua b/res/scripts/map2.lua index 12a5df0..cdab0f5 100644 --- a/res/scripts/map2.lua +++ b/res/scripts/map2.lua
@@ -26,6 +26,15 @@ end
26 26
27function map2.mailbox_lightning() 27function map2.mailbox_lightning()
28 StartCutscene() 28 StartCutscene()
29 DisplayMessage("* The mailbox lid is open...\n* Peek inside?", "", SpeakerType.NONE)
30 ShowChoice("Yes", "No")
31 WaitForEndOfMessage()
32
33 if GetChoiceSelection() == 1 then
34 HideCutsceneBars()
35 return
36 end
37
29 FadeMap(500, 0.5) 38 FadeMap(500, 0.5)
30 WaitForMapFade() 39 WaitForMapFade()
31 40
@@ -38,11 +47,13 @@ function map2.mailbox_lightning()
38 local lucasPos = GetPosition("lucas") 47 local lucasPos = GetPosition("lucas")
39 CreateAnimatedSpriteAtPosition("lightning_from_mailbox", "lightning", lucasPos:x() + 56, lucasPos:y() - 72, "strike", Direction.DOWN_LEFT, SpriteLayer.ABOVE) 48 CreateAnimatedSpriteAtPosition("lightning_from_mailbox", "lightning", lucasPos:x() + 56, lucasPos:y() - 72, "strike", Direction.DOWN_LEFT, SpriteLayer.ABOVE)
40 49
50 ShakeCamera(66)
41 PlaySound("lightning_explosion.wav") 51 PlaySound("lightning_explosion.wav")
42 SetDirection("lucas", Direction.DOWN) 52 SetDirection("lucas", Direction.DOWN)
43 SetAnimation("lucas", "lightning_electrocute!") 53 SetAnimation("lucas", "lightning_electrocute!")
44 WaitForAnimation("lucas") 54 WaitForAnimation("lucas")
45 55
56 StopShakingCamera()
46 DestroyNamedSprite("lightning_from_mailbox") 57 DestroyNamedSprite("lightning_from_mailbox")
47 SetAnimation("lucas", "lightning_collapse!") 58 SetAnimation("lucas", "lightning_collapse!")
48 WaitForAnimation("lucas") 59 WaitForAnimation("lucas")
diff --git a/src/effect_system.cpp b/src/effect_system.cpp index 3a0afe4..74fc8f3 100644 --- a/src/effect_system.cpp +++ b/src/effect_system.cpp
@@ -18,6 +18,22 @@ void EffectSystem::tick(double dt) {
18 18
19 mapFade_ = (mapFadeDest_ - mapFadeStart_) / mapFadeLength_ * mapFadeThus_ + mapFadeStart_; 19 mapFade_ = (mapFadeDest_ - mapFadeStart_) / mapFadeLength_ * mapFadeThus_ + mapFadeStart_;
20 } 20 }
21
22 if (cameraShaking_) {
23 cameraShakeTimer_.accumulate(dt);
24
25 while (cameraShakeTimer_.step()) {
26 cameraShakeOn_ = !cameraShakeOn_;
27 }
28
29 if (cameraShakeOn_) {
30 cameraShakeOffset_.x() = 8;
31 cameraShakeOffset_.y() = 8;
32 } else {
33 cameraShakeOffset_.x() = 0;
34 cameraShakeOffset_.y() = 0;
35 }
36 }
21} 37}
22 38
23void EffectSystem::fadeScreen(int length, double amount) { 39void EffectSystem::fadeScreen(int length, double amount) {
@@ -33,3 +49,15 @@ void EffectSystem::fadeMap(int length, double amount) {
33 mapFadeLength_ = length; 49 mapFadeLength_ = length;
34 mapFadeThus_ = 0; 50 mapFadeThus_ = 0;
35} 51}
52
53void EffectSystem::shakeCamera(int period) {
54 cameraShaking_ = true;
55 cameraShakeOffset_ = { 0, 0 };
56 cameraShakeOn_ = false;
57 cameraShakeTimer_ = Timer(period);
58}
59
60void EffectSystem::stopShakingCamera() {
61 cameraShaking_ = false;
62 cameraShakeOffset_ = { 0, 0 };
63}
diff --git a/src/effect_system.h b/src/effect_system.h index 2cdcb10..12ec7ca 100644 --- a/src/effect_system.h +++ b/src/effect_system.h
@@ -2,6 +2,8 @@
2#define EFFECT_SYSTEM_H_0B497B39 2#define EFFECT_SYSTEM_H_0B497B39
3 3
4#include "system.h" 4#include "system.h"
5#include "timer.h"
6#include "vector.h"
5 7
6class Game; 8class Game;
7 9
@@ -26,6 +28,12 @@ public:
26 // - amount is [0,1] 28 // - amount is [0,1]
27 void fadeMap(int length, double amount); 29 void fadeMap(int length, double amount);
28 30
31 // Shakes the viewport by 1 tile in both directions.
32 // - period is in milliseconds, it's actually a half period
33 void shakeCamera(int period);
34
35 void stopShakingCamera();
36
29 /* Information */ 37 /* Information */
30 38
31 bool isScreenFaded() const { return screenFade_ > 0.0; } 39 bool isScreenFaded() const { return screenFade_ > 0.0; }
@@ -40,6 +48,10 @@ public:
40 48
41 bool isMapFadeComplete() const { return mapFade_ == mapFadeDest_; } 49 bool isMapFadeComplete() const { return mapFade_ == mapFadeDest_; }
42 50
51 const vec2i& getCameraShakeOffset() const { return cameraShakeOffset_; }
52
53 bool isCameraShaking() const { return cameraShaking_; }
54
43private: 55private:
44 56
45 Game& game_; 57 Game& game_;
@@ -55,6 +67,11 @@ private:
55 double mapFadeStart_ = 0.0; 67 double mapFadeStart_ = 0.0;
56 double mapFadeLength_ = 0.0; 68 double mapFadeLength_ = 0.0;
57 double mapFadeThus_ = 0.0; 69 double mapFadeThus_ = 0.0;
70
71 bool cameraShaking_ = false;
72 vec2i cameraShakeOffset_ { 0, 0 };
73 bool cameraShakeOn_ = false;
74 Timer cameraShakeTimer_ { 0 };
58}; 75};
59 76
60#endif /* end of include guard: EFFECT_SYSTEM_H_0B497B39 */ 77#endif /* end of include guard: EFFECT_SYSTEM_H_0B497B39 */
diff --git a/src/renderer.cpp b/src/renderer.cpp index c80b0d3..5aeb232 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -194,9 +194,11 @@ void Renderer::render(Game& game) {
194 renderSprite(sprite); 194 renderSprite(sprite);
195 } 195 }
196 196
197 vec2i viewport = game.getSystem<CameraSystem>().getCameraPosition() + effects.getCameraShakeOffset();
198
197 SDL_Rect cameraField { 199 SDL_Rect cameraField {
198 game.getSystem<CameraSystem>().getCameraPosition().x(), 200 viewport.x(),
199 game.getSystem<CameraSystem>().getCameraPosition().y(), 201 viewport.y(),
200 game.getSystem<CameraSystem>().getFieldOfView().w(), 202 game.getSystem<CameraSystem>().getFieldOfView().w(),
201 game.getSystem<CameraSystem>().getFieldOfView().h() 203 game.getSystem<CameraSystem>().getFieldOfView().h()
202 }; 204 };
diff --git a/src/script_system.cpp b/src/script_system.cpp index 7109d98..cbbd473 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp
@@ -59,7 +59,9 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
59 "fadeScreen", &EffectSystem::fadeScreen, 59 "fadeScreen", &EffectSystem::fadeScreen,
60 "isScreenFadeComplete", &EffectSystem::isScreenFadeComplete, 60 "isScreenFadeComplete", &EffectSystem::isScreenFadeComplete,
61 "fadeMap", &EffectSystem::fadeMap, 61 "fadeMap", &EffectSystem::fadeMap,
62 "isMapFadeComplete", &EffectSystem::isMapFadeComplete); 62 "isMapFadeComplete", &EffectSystem::isMapFadeComplete,
63 "shakeCamera", &EffectSystem::shakeCamera,
64 "stopShakingCamera", &EffectSystem::stopShakingCamera);
63 65
64 engine_.new_usertype<Mixer>( 66 engine_.new_usertype<Mixer>(
65 "mixer", 67 "mixer",