vectozavr-shooter/engine/animation/AFunction.h

37 lines
890 B
C
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 06.04.2021.
//
#include <utility>
#include "Animation.h"
#ifndef ENGINE_AFUNCTION_H
#define ENGINE_AFUNCTION_H
class AFunction : public Animation {
private:
int _calls = 0;
int _allCalls = 1;
std::function<void()> _callBack;
public:
2021-10-02 20:36:07 +03:00
explicit AFunction(std::function<void()> function, int calls = 1, double duration = 1, LoopOut looped = LoopOut::None, InterpolationType interpolationType = InterpolationType::linear) {
2021-09-13 15:53:43 +03:00
_callBack = std::move(function);
_allCalls = calls;
_duration = duration;
_looped = looped;
_intType = interpolationType;
}
2021-10-02 20:36:07 +03:00
bool update() override {
2021-10-09 13:41:12 +03:00
if(_allCalls != 0 && _p >= (double)(_calls + 1) / (_allCalls + 1)) {
2021-09-13 15:53:43 +03:00
_calls++;
_callBack();
}
return updateState();
}
};
#endif //MINECRAFT_3DZAVR_AFUNCTION_H