summary refs log tree commit diff stats
path: root/src/effect_system.cpp
blob: 9b24d3e846d07c66d3028f45c6d2ecde16f6c7c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "effect_system.h"
#include "game.h"

void EffectSystem::tick(double dt) {
  if (game_.isGameplayPaused()) return;

  screenFade_.tick(dt);
  mapFade_.tick(dt);
  circleEffect_.tick(dt);

  if (cameraShaking_) {
    cameraShakeTimer_.accumulate(dt);

    while (cameraShakeTimer_.step()) {
      cameraShakeOn_ = !cameraShakeOn_;
    }

    if (cameraShakeOn_) {
      cameraShakeOffset_.x() = 8;
      cameraShakeOffset_.y() = 8;
    } else {
      cameraShakeOffset_.x() = 0;
      cameraShakeOffset_.y() = 0;
    }
  }
}

void EffectSystem::fadeScreen(int length, double amount) {
  screenFade_.start(length, amount);
}

void EffectSystem::fadeMap(int length, double amount) {
  mapFade_.start(length, amount);
}

void EffectSystem::shakeCamera(int period) {
  cameraShaking_ = true;
  cameraShakeOffset_ = { 0, 0 };
  cameraShakeOn_ = false;
  cameraShakeTimer_ = Timer(period);
}

void EffectSystem::stopShakingCamera() {
  cameraShaking_ = false;
  cameraShakeOffset_ = { 0, 0 };
}

void EffectSystem::circleTransition(int length, double amount) {
  circleEffect_.start(length, amount);
}