Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
screen_effects.hpp
Go to the documentation of this file.
1
3#pragma once
4
9#include <aegis2d/render/export.hpp>
11
12#include <array>
13#include <cstddef>
14#include <cstdint>
15#include <optional>
16#include <string_view>
17
18namespace aegis2d::render {
19
24struct AEGIS2D_RENDER_EXPORT EffectSettings {
26 bool flashes = true;
28 bool shake = true;
29
35 void save(core::Config& settings, std::string_view section) const;
36
42 void load(const core::Config& settings, std::string_view section);
43};
44
65class AEGIS2D_RENDER_EXPORT ScreenEffects {
66public:
68 static constexpr std::size_t max_flashes_per_second = 3;
69
73 explicit ScreenEffects(EffectSettings settings = {}, std::uint64_t seed = 0) noexcept;
74
77 void set_settings(EffectSettings settings) noexcept;
78
81 [[nodiscard]] EffectSettings settings() const noexcept;
82
89 bool flash(Color color, float seconds) noexcept;
90
96 bool shake(float strength, float seconds) noexcept;
97
100 void update(float seconds) noexcept;
101
104 [[nodiscard]] Color flash_color() const noexcept;
105
110 [[nodiscard]] Color tint(Color background) const noexcept;
111
116 [[nodiscard]] std::optional<Sprite> overlay(Vec2 screen) const noexcept;
117
121 [[nodiscard]] Vec2 offset() const noexcept;
122
123private:
124 EffectSettings settings_;
125 core::Random random_;
126 double time_ = 0.0;
127 std::array<double, max_flashes_per_second> flash_starts_{};
128 std::size_t flash_count_ = 0;
129 Color flash_color_;
130 float flash_left_ = 0.0F;
131 float flash_length_ = 0.0F;
132 float shake_strength_ = 0.0F;
133 float shake_left_ = 0.0F;
134 float shake_length_ = 0.0F;
135 Vec2 offset_;
136};
137
138} // namespace aegis2d::render
JSON configuration file (server port, window size...) read through typed getters.
Definition config.hpp:58
Full-screen flashes and camera shake triggered by gameplay (explosions, hits).
Definition screen_effects.hpp:65
ScreenEffects(EffectSettings settings={}, std::uint64_t seed=0) noexcept
Creates the effects, with nothing showing.
EffectSettings settings() const noexcept
The player's choice.
void set_settings(EffectSettings settings) noexcept
Changes the player's choice; turning an effect off stops it at once.
RGBA color used by the renderer.
JSON configuration with dotted-path lookups, which can be changed and saved.
Vector and matrix types of the engine (GLM behind engine names).
OpenGL renderer: sprites, text and camera (client only).
Definition bitmap_font.hpp:16
aegis2d::Vec2 Vec2
2D vector of floats, in logical pixels: the engine-wide aegis2d::Vec2.
Definition renderer.hpp:17
Definition endpoint.hpp:85
Seeded random numbers that are the same on every platform.
Backend-independent renderer interface and the sprite it draws.
RGBA color with components in [0, 1].
Definition color.hpp:10
The player's choice about screen flashes and shake.
Definition screen_effects.hpp:24
void save(core::Config &settings, std::string_view section) const
Writes the choice into the player's settings.
void load(const core::Config &settings, std::string_view section)
Reads the choice written by save().
One textured quad to draw.
Definition renderer.hpp:46