summary refs log tree commit diff stats
path: root/src/effect_system.cpp
blob: 4dff13c2b12362dae227595d88e814ec58a5f6ae (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "effect_system.h"
#include "game.h"

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

  if (screenFade_ != screenFadeDest_) {
    screenFadeThus_ += dt;
    if (screenFadeThus_ >= screenFadeLength_) {
      screenFadeThus_ = screenFadeLength_;
    }

    screenFade_ = (screenFadeDest_ - screenFadeStart_) / screenFadeLength_ * screenFadeThus_ + screenFadeStart_;
  }

  if (mapFade_ != mapFadeDest_) {
    mapFadeThus_ += dt;
    if (mapFadeThus_ >= mapFadeLength_) {
      mapFadeThus_ = mapFadeLength_;
    }

    mapFade_ = (mapFadeDest_ - mapFadeStart_) / mapFadeLength_ * mapFadeThus_ + mapFadeStart_;
  }

  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;
    }
  }

  if (circleEffect_ != circleEffectDest_) {
    circleEffectThus_ += dt;
    if (circleEffectThus_ >= circleEffectLength_) {
      circleEffectThus_ = circleEffectLength_;
    }

    circleEffect_ = (circleEffectDest_ - circleEffectStart_) / circleEffectLength_ * circleEffectThus_ + circleEffectStart_;
  }
}

void EffectSystem::fadeScreen(int length, double amount) {
  screenFadeStart_ = screenFade_;
  screenFadeDest_ = amount;
  screenFadeLength_ = length;
  screenFadeThus_ = 0;
}

void EffectSystem::fadeMap(int length, double amount) {
  mapFadeStart_ = mapFade_;
  mapFadeDest_ = amount;
  mapFadeLength_ = length;
  mapFadeThus_ = 0;
}

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) {
  circleEffectStart_ = circleEffect_;
  circleEffectDest_ = amount;
  circleEffectLength_ = length;
  circleEffectThus_ = 0;
}