summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-03-05 09:39:31 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-03-05 09:39:31 -0500
commit7e3b59b09399bf8da243fb4122caa2c9c10d2624 (patch)
tree34a586249f6cd8ee7acb357642dc87117794348f /src
parent379f1f8bd8da856a142deb5781c8e9ab15393452 (diff)
downloadtanetane-7e3b59b09399bf8da243fb4122caa2c9c10d2624.tar.gz
tanetane-7e3b59b09399bf8da243fb4122caa2c9c10d2624.tar.bz2
tanetane-7e3b59b09399bf8da243fb4122caa2c9c10d2624.zip
Implemented circle transition effect (for exit area)
Diffstat (limited to 'src')
-rw-r--r--src/effect_system.cpp16
-rw-r--r--src/effect_system.h17
-rw-r--r--src/renderer.cpp54
-rw-r--r--src/script_system.cpp4
4 files changed, 90 insertions, 1 deletions
diff --git a/src/effect_system.cpp b/src/effect_system.cpp index aeccebb..4dff13c 100644 --- a/src/effect_system.cpp +++ b/src/effect_system.cpp
@@ -37,6 +37,15 @@ void EffectSystem::tick(double dt) {
37 cameraShakeOffset_.y() = 0; 37 cameraShakeOffset_.y() = 0;
38 } 38 }
39 } 39 }
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 }
40} 49}
41 50
42void EffectSystem::fadeScreen(int length, double amount) { 51void EffectSystem::fadeScreen(int length, double amount) {
@@ -64,3 +73,10 @@ void EffectSystem::stopShakingCamera() {
64 cameraShaking_ = false; 73 cameraShaking_ = false;
65 cameraShakeOffset_ = { 0, 0 }; 74 cameraShakeOffset_ = { 0, 0 };
66} 75}
76
77void EffectSystem::circleTransition(int length, double amount) {
78 circleEffectStart_ = circleEffect_;
79 circleEffectDest_ = amount;
80 circleEffectLength_ = length;
81 circleEffectThus_ = 0;
82}
diff --git a/src/effect_system.h b/src/effect_system.h index 12ec7ca..904e6cb 100644 --- a/src/effect_system.h +++ b/src/effect_system.h
@@ -34,6 +34,11 @@ public:
34 34
35 void stopShakingCamera(); 35 void stopShakingCamera();
36 36
37 // Hides or reveals the screen using a circle transition.
38 // - length is the time in milliseconds
39 // - amount is [0,1], where 0 is fully revealed and 1 is fully hidden
40 void circleTransition(int length, double amount);
41
37 /* Information */ 42 /* Information */
38 43
39 bool isScreenFaded() const { return screenFade_ > 0.0; } 44 bool isScreenFaded() const { return screenFade_ > 0.0; }
@@ -52,6 +57,12 @@ public:
52 57
53 bool isCameraShaking() const { return cameraShaking_; } 58 bool isCameraShaking() const { return cameraShaking_; }
54 59
60 bool isCircleTransitionActive() const { return circleEffect_ > 0.0; }
61
62 double getCircleTransitionProgress() const { return circleEffect_; }
63
64 bool isCircleTransitionComplete() const { return circleEffect_ == circleEffectDest_; }
65
55private: 66private:
56 67
57 Game& game_; 68 Game& game_;
@@ -72,6 +83,12 @@ private:
72 vec2i cameraShakeOffset_ { 0, 0 }; 83 vec2i cameraShakeOffset_ { 0, 0 };
73 bool cameraShakeOn_ = false; 84 bool cameraShakeOn_ = false;
74 Timer cameraShakeTimer_ { 0 }; 85 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;
75}; 92};
76 93
77#endif /* end of include guard: EFFECT_SYSTEM_H_0B497B39 */ 94#endif /* end of include guard: EFFECT_SYSTEM_H_0B497B39 */
diff --git a/src/renderer.cpp b/src/renderer.cpp index 3007378..5ab623a 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -353,6 +353,60 @@ void Renderer::render(Game& game) {
353 SDL_RenderFillRect(ren_.get(), nullptr); 353 SDL_RenderFillRect(ren_.get(), nullptr);
354 } 354 }
355 355
356 if (effects.isCircleTransitionActive()) {
357 if (effects.getCircleTransitionProgress() == 1.0) {
358 SDL_SetRenderTarget(ren_.get(), cameraTex.get());
359 SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_NONE);
360 SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, 255);
361 SDL_RenderClear(ren_.get());
362 } else {
363 texture_ptr circleEffectTex(
364 SDL_CreateTexture(
365 ren_.get(),
366 SDL_PIXELFORMAT_RGBA8888,
367 SDL_TEXTUREACCESS_TARGET,
368 CANVAS_WIDTH,
369 CANVAS_HEIGHT));
370
371 if (!circleEffectTex) {
372 throw sdl_error();
373 }
374
375 SDL_SetRenderTarget(ren_.get(), circleEffectTex.get());
376 SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_NONE);
377 SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, 255);
378 SDL_RenderClear(ren_.get());
379
380 int circleDiameter = 290 * (1.0 - effects.getCircleTransitionProgress());
381 SDL_Rect circleSize {
382 CANVAS_WIDTH / 2 - circleDiameter / 2,
383 CANVAS_HEIGHT / 2 - circleDiameter / 2,
384 circleDiameter,
385 circleDiameter
386 };
387
388 SDL_Rect copyFromCamera = circleSize;
389 if (circleDiameter > CANVAS_WIDTH) {
390 copyFromCamera.x = 0;
391 copyFromCamera.w = CANVAS_WIDTH;
392 }
393 if (circleDiameter > CANVAS_HEIGHT) {
394 copyFromCamera.y = 0;
395 copyFromCamera.h = CANVAS_HEIGHT;
396 }
397
398 SDL_RenderCopy(ren_.get(), cameraTex.get(), &copyFromCamera, &copyFromCamera);
399
400 int pinholeTexId = loadImageFromFile("../res/pinhole.png");
401 SDL_SetTextureBlendMode(textures_[pinholeTexId].get(), SDL_BLENDMODE_MOD);
402 SDL_RenderCopy(ren_.get(), textures_[pinholeTexId].get(), nullptr, &circleSize);
403
404 SDL_SetRenderTarget(ren_.get(), cameraTex.get());
405 SDL_SetTextureBlendMode(circleEffectTex.get(), SDL_BLENDMODE_NONE);
406 SDL_RenderCopy(ren_.get(), circleEffectTex.get(), nullptr, nullptr);
407 }
408 }
409
356 if (game.getSystem<InputSystem>().isDebugConsoleOpen()) { 410 if (game.getSystem<InputSystem>().isDebugConsoleOpen()) {
357 // Not sure why I'm supposed to copy the cached texture to the screen 411 // Not sure why I'm supposed to copy the cached texture to the screen
358 // BEFORE rendering it, but we get flickering if we don't, so. 412 // BEFORE rendering it, but we get flickering if we don't, so.
diff --git a/src/script_system.cpp b/src/script_system.cpp index a3686b4..3325b79 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp
@@ -89,7 +89,9 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
89 "fadeMap", &EffectSystem::fadeMap, 89 "fadeMap", &EffectSystem::fadeMap,
90 "isMapFadeComplete", &EffectSystem::isMapFadeComplete, 90 "isMapFadeComplete", &EffectSystem::isMapFadeComplete,
91 "shakeCamera", &EffectSystem::shakeCamera, 91 "shakeCamera", &EffectSystem::shakeCamera,
92 "stopShakingCamera", &EffectSystem::stopShakingCamera); 92 "stopShakingCamera", &EffectSystem::stopShakingCamera,
93 "circleTransition", &EffectSystem::circleTransition,
94 "isCircleTransitionComplete", &EffectSystem::isCircleTransitionComplete);
93 95
94 engine_.new_usertype<CameraSystem>( 96 engine_.new_usertype<CameraSystem>(
95 "camera", 97 "camera",