-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatformUnit.cpp
More file actions
46 lines (38 loc) · 1.24 KB
/
Copy pathPlatformUnit.cpp
File metadata and controls
46 lines (38 loc) · 1.24 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
#include <algorithm>
#include <cmath>
#include "PlatformUnit.h"
#include "constants.h"
PlatformUnit::PlatformUnit(std::vector<Sprite*> sprites, double x, double y, double width, double height, double minX, double maxX) : DynamicUnit(sprites[0], x, y, width, height) {
this->sprites = sprites;
this->currentSpriteIndex = 0;
this->animationCounter = 0;
this->minX(minX);
this->maxX(maxX);
this->maxVelocity(PLATFORM_VELOCITY * PLATFORM_VELOCITY_COEF);
this->minVelocity(PLATFORM_VELOCITY / PLATFORM_VELOCITY_COEF);
this->maxWidth(width * PLATFOTM_WIDTH_COEF);
this->velocity(PLATFORM_VELOCITY);
}
void PlatformUnit::update() {
if (animationCounter == 0) {
sprite(sprites[currentSpriteIndex]);
currentSpriteIndex = (currentSpriteIndex + 1) % sprites.size();
}
animationCounter = (animationCounter + 1) % PLATFORM_ANIMATION_LATENCY;
DynamicUnit::update();
}
double PlatformUnit::x() {
return std::clamp(DynamicUnit::x(), this->minX(), this->maxX());
}
double PlatformUnit::maxX() {
return this->_maxX >= 0 ? this->_maxX : HUGE_VAL;
}
void PlatformUnit::maxX(double maxX) {
this->_maxX = maxX;
}
double PlatformUnit::minX() {
return this->_minX >= 0 ? this->_minX : -HUGE_VAL;
}
void PlatformUnit::minX(double minX) {
this->_minX = minX;
}