-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents.cpp
More file actions
66 lines (53 loc) · 1.66 KB
/
components.cpp
File metadata and controls
66 lines (53 loc) · 1.66 KB
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
#pragma once
#include "components.h"
#include "game.h"
#include "iostream"
SpeedDebuff::SpeedDebuff(Entity* entity, float duration, const sf::Color& color) : Modifier(entity, duration) {
this->entity->body->speed -= 150;
this->entity->shape->setFillColor(color);
}
SpeedDebuff::~SpeedDebuff() {
std::cout << "Debuff modifier deleted" << "\n";
}
void SpeedDebuff::update() {
timePassed += Game::deltaTime;
if (timePassed > duration) {
entity->body->speed += 150;
entity->shape->setFillColor(sf::Color::White);
isActive = false;
}
}
IncreaseSize::IncreaseSize(Entity* entity, float duration) :
Modifier(entity, duration),
paddle(std::static_pointer_cast<sf::RectangleShape>(entity->shape)),
startSize(paddle.lock()->getSize()),
colorNotifyDelay(duration - 1) {};
void IncreaseSize::update() {
timePassed += Game::deltaTime;
float t = timePassed / duration;
if (t <= 1) {
float x = startSize.x + (targetSize - startSize.x) * t;
paddle.lock()->setOrigin(sf::Vector2f(x/2, startSize.y/2));
paddle.lock()->setSize(sf::Vector2f(x, startSize.y));
}
if (timePassed >= colorNotifyDelay) {
flashColor();
}
if (timePassed > duration) {
entity->shape->setFillColor(sf::Color::White);
paddle.lock()->setOrigin(sf::Vector2f(startSize.x/2, startSize.y/2));
paddle.lock()->setSize(startSize);
isActive = false;
}
}
void IncreaseSize::flashColor() {
colorTimePassed += Game::deltaTime;
if (colorTimePassed >= colorDuration) {
sf::Color color = entity->shape->getFillColor() == main ? secondary : main;
entity->shape->setFillColor(color);
colorTimePassed = 0;
}
}
IncreaseSize::~IncreaseSize() {
std::cout << "IncreaseSize modifier destoryed" << "\n";
}