Peoplemon  0.1.0
Peoplemon 3 game source documentation
Particles.cpp
Go to the documentation of this file.
2 
3 #include <BLIB/Util/Random.hpp>
4 #include <Core/Properties.hpp>
5 #include <cmath>
6 
7 namespace game
8 {
9 namespace state
10 {
11 namespace evo
12 {
13 namespace
14 {
15 constexpr unsigned int SparkCount = 400;
16 constexpr float SparkSpawnRate = 1600.f;
17 const sf::Color SparkColor(252, 230, 30);
18 } // namespace
19 
21 : residual(0.f) {}
22 
23 void SparkEmitter::update(Emitter::Proxy& proxy, float dt, float) {
24  residual += SparkSpawnRate * dt;
25 
26  // TODO - cap spawn?
27  while (residual >= 1.f) {
28  residual -= 1.f;
29  Evolution::Spark& sp = proxy.emit();
30 
31  const float a = bl::util::Random::get<float>(0.f, 360.f);
32  const float d = bl::util::Random::get<float>(1.f, 40.f);
33  const float v = bl::util::Random::get<float>(150.f, 900.f);
34  const float c = bl::math::cos(a);
35  const float s = bl::math::sin(a);
36  sp.position = glm::vec2(core::Properties::WindowSize().x * 0.5f,
37  core::Properties::WindowSize().y * 0.5f) +
38  glm::vec2(c, s) * d;
39  sp.velocity.x = v * c;
40  sp.velocity.y = v * s;
41  sp.time = 0.f;
42  sp.lifetime = bl::util::Random::get<float>(0.75f, 1.4f);
43  sp.radius = bl::util::Random::get<float>(2.f, 7.f);
44  }
45 }
46 
47 void SparkSink::update(Proxy& proxy, std::span<Evolution::Spark> particles, float dt, float) {
48  for (auto& spark : particles) {
49  spark.lifetime += dt;
50  if (spark.time >= spark.lifetime) { proxy.destroy(spark); }
51  }
52 }
53 
54 void SparkAffector::update(Proxy& proxy, float dt, float) {
55  for (auto& spark : proxy.particles()) { spark.position += spark.velocity * dt; }
56 }
57 
58 } // namespace evo
59 } // namespace state
60 } // namespace game
Parent namespace for all functionality unique to the game.
static sf::Vector2f WindowSize()
Definition: Properties.cpp:262