3 #include <BLIB/Math.hpp>
4 #include <BLIB/Util/Random.hpp>
18 static constexpr
bool ContainsTransparency =
false;
20 static constexpr
bool CreateRenderPipeline =
true;
21 static constexpr std::initializer_list<std::uint32_t> RenderPassIds =
22 RenderConfigDefaults<Evolution::Spark>::RenderPassIds;
26 RenderConfigDescriptorList<bl::rc::ds::Scene2DFactory,
27 DescriptorSetFactory<Evolution::Spark, evo::GpuSpark>>;
29 static constexpr
bool EnableDepthTesting =
false;
30 static constexpr VkPrimitiveTopology Topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
32 static constexpr
const char* VertexShader =
33 "Resources/Shaders/Particles/evolution_spark.vert.spv";
34 static constexpr
const char* FragmentShader =
35 "Resources/Shaders/Particles/evolution_spark.frag.spv";
47 constexpr
float FadeTime = 1.5f;
48 constexpr
float FadeRate = 255.f / FadeTime;
49 constexpr
float FadeAlpha = 95.f;
50 constexpr
float FadeDiff = 255.f - FadeAlpha;
51 constexpr
float MaxColorRecip = 1.f / 255.f;
53 constexpr
float ScalingTime = 7.f;
54 constexpr
float InitialRpm = 0.9f;
55 constexpr
float SinMult = 90.f / InitialRpm;
57 constexpr
float SparkPercent = 1.f / 2.3f;
58 constexpr
float SparkStopColor = 255.f * SparkPercent;
60 sf::Color makeFade(
float c) {
61 const float af = 255.f - (1.f - c * MaxColorRecip) * FadeDiff;
62 const std::uint8_t a =
static_cast<std::uint8_t
>(af);
63 const std::uint8_t ci =
static_cast<std::uint8_t
>(c);
64 return sf::Color(ci, ci, ci, a);
74 :
State(systems,
bl::engine::StateMask::Menu)
76 , state(AnimState::IntroMsg)
81 bgndTxtr = txtrs.getOrLoadTexture(
87 oldThumb.getTransform().setOrigin(oldTxtr->size() * 0.5f);
90 oldThumb.setParent(background);
94 newThumb.getTransform().setOrigin(newTxtr->size() * 0.5f);
97 newThumb.setParent(background);
99 sparks = &
systems.
engine().particleSystem().getUniqueSystem<Spark>();
107 auto overlay = engine.renderer().getObserver().pushScene<bl::rc::Overlay>();
108 background.addToScene(overlay, bl::rc::UpdateSpeed::Static);
109 oldThumb.addToScene(overlay, bl::rc::UpdateSpeed::Dynamic);
110 newThumb.addToScene(overlay, bl::rc::UpdateSpeed::Dynamic);
111 sparks->addToScene(overlay);
112 engine.ecs().setEntityParent(sparks->getRenderer().getEntity(), background.entity());
113 newThumb.setHidden(
true);
114 oldThumb.setHidden(
false);
116 engine.inputSystem().getActor().addListener(*
this);
119 BL_LOG_CRITICAL <<
"Tried to evolve " << ppl.
id()
120 <<
" which does not have a valid evolution";
126 ppl.
name() +
" is evolving!",
true, std::bind(&Evolution::messageDone,
this));
127 state = AnimState::IntroMsg;
133 engine.renderer().getObserver().popScene();
134 engine.inputSystem().getActor().removeListener(*
this);
139 const auto updateSpark = [dt](
Spark& spark) {
141 spark.position += spark.velocity * dt;
142 return spark.time < spark.lifetime;
146 case AnimState::OldFadeOut:
150 state = AnimState::SizeOscillating;
151 newThumb.setHidden(
false);
153 newThumb.component().setColor(oldThumb.component().getColor());
154 newThumb.getTransform().setScale(0.f, 0.f);
158 case AnimState::SizeOscillating: {
161 const float os = 1.f - s;
162 oldThumb.getTransform().setScale(os, os);
163 newThumb.getTransform().setScale(s, s);
165 state = AnimState::NewFadeIn;
166 oldThumb.setHidden(
true);
167 newThumb.getTransform().setScale(1.f, 1.f);
173 case AnimState::NewFadeIn:
176 if (
fadeColor >= SparkStopColor) { sparks->removeAllEmitters(); }
178 state = AnimState::EvolvedMsg;
183 std::bind(&Evolution::messageDone,
this));
186 case AnimState::EvolvedMsg:
187 case AnimState::IntroMsg:
188 case AnimState::CancelMsg:
189 case AnimState::CancelConfirm:
195 void Evolution::messageDone() {
197 case AnimState::IntroMsg:
198 state = AnimState::OldFadeOut;
201 case AnimState::CancelMsg:
202 case AnimState::EvolvedMsg:
206 BL_LOG_WARN <<
"Received message done event while in invalid state";
211 void Evolution::onCancelConfirm(
const std::string& choice) {
212 if (choice ==
"Yes") {
214 std::bind(&Evolution::messageDone,
this));
215 state = AnimState::CancelMsg;
218 state = cancelPriorState;
220 ppl.
name() +
" is evolving!",
false, std::bind(&Evolution::messageDone,
this));
224 bool Evolution::observe(
const bl::input::Actor&,
unsigned int ctrl, bl::input::DispatchType,
228 case AnimState::OldFadeOut:
229 case AnimState::SizeOscillating:
230 case AnimState::NewFadeIn:
232 cancelPriorState = state;
233 state = AnimState::CancelConfirm;
236 "Are you sure you want to stop " + ppl.
name() +
" from evolving?",
238 std::bind(&Evolution::onCancelConfirm,
this, std::placeholders::_1));
Parent namespace for all functionality unique to the game.
Parent namespace for all engine states implemented by the game.
Represents an instance of a peoplemon. Can be a wild peoplemon, trainer, or player peoplemon....
void evolve()
Changes this Peoplemon into it's evolved form if it has one.
Id id() const
Returns the id of this peoplemon.
Id evolvesInto() const
Returns the people that this evolves into. Returns Unknown if no evolution.
const std::string & name() const
Returns the name of this peoplemon, custom or defualt.
static std::string opponentImage(Id id)
Returns the full path to the image to use in battle for the opponent peoplemon.
static const std::string & name(Id id)
Returns the name of the given Peoplemon.
static constexpr std::uint32_t EvolutionSparkPipelineId
static sf::Vector2f WindowSize()
static const std::string & ImagePath()
void displayMessage(const std::string &message, const Callback &cb=[](const std::string &) {})
Displays a message in the HUD textbox. Messages are queued in order that they arrive.
void promptUser(const std::string &prompt, const std::vector< std::string > &choices, const Callback &cb)
Asks the player a question through the HUD.
void displayStickyMessage(const std::string &message, bool ghostWrite, const Callback &cb=[](const std::string &) {})
Displays a message in the HUD textbox. Sticky messages stay displayed until programmatically dismisse...
bool dismissStickyMessage(bool ignoreGhostWrite=true)
Dismisses the currently active sticky message.
Owns all primary systems and a reference to the engine.
const bl::engine::Engine & engine() const
Const accessor for the Engine.
HUD & hud()
Returns the HUD.
Spark emitter for the evolution sparks particle system.
Spark sink for the evolution sparks particle system.
Spark affector for the evolution sparks particle system.
Game state for when a Peoplemon evolves into another one.
virtual void activate(bl::engine::Engine &engine) override
Subscribes to player input.
const char * name() const override
Returns "Evolution".
virtual void update(bl::engine::Engine &engine, float dt, float) override
Updates the evolution process.
virtual void deactivate(bl::engine::Engine &engine) override
Unsubscribes from player input.
Parent to all game states. Provides some commonly required data like core game systems.
core::system::Systems & systems
RenderConfigDescriptorList< bl::rc::ds::Scene2DFactory, DescriptorSetFactory< Evolution::Spark, evo::GpuSpark > > DescriptorSets
RenderConfigDefaults< Evolution::Spark >::GlobalShaderPayload GlobalShaderPayload