JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
effects.hpp
Go to the documentation of this file.
1// Copyright 2020-2022 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include "Vec2.hpp"
8#include <functional>
9
10namespace jngl {
11
13class Effect {
14public:
15 enum class Action {
16 NONE,
17 REMOVE_EFFECT,
18 REMOVE_WIDGET,
19 };
20
21 virtual ~Effect();
22 [[nodiscard]] virtual Action step() = 0;
23 virtual void beginDraw() const = 0;
24 virtual void endDraw() const = 0;
25};
26
28class Zoom : public Effect {
29public:
31 explicit Zoom(std::function<float(float)>);
32 Action step() override;
33 void beginDraw() const override;
34 void endDraw() const override;
35
36private:
37 std::function<float(float)> function;
38 float time = 0;
39};
40
42class Executor : public Effect {
43public:
44 explicit Executor(std::function<Action(float)>);
45 Action step() override;
46
48 void beginDraw() const override;
49 void endDraw() const override;
50
51private:
52 std::function<Action(float)> function;
53 float time = 0;
54};
55
56class Move : public Effect {
57public:
58 explicit Move(Vec2 offset, std::function<float(float)>);
59 Action step() override;
60 void beginDraw() const override;
61 void endDraw() const override;
62
63private:
64 Vec2 offset;
65 float progress;
66 std::function<float(float)> function;
67 float time = 0;
68};
69
70namespace easing {
71
72float linear(float);
73float elastic(float);
74float cubic(float);
75float expo(float);
76
77} // namespace easing
78
79} // namespace jngl
Contains jngl::Vec2 class.
Base class for effects that can be applied to jngl::Widget.
Definition: effects.hpp:13
Executes a specific action, e.g. removes the Widget.
Definition: effects.hpp:42
void beginDraw() const override
Does nothing.
Two-dimensional vector.
Definition: Vec2.hpp:32
Scales the ModelView matrix.
Definition: effects.hpp:28
Zoom(std::function< float(float)>)
f(t)
JNGL's main namespace.
Definition: Achievement.hpp:10