| 290 | } |
| 291 | |
| 292 | void emit_particles(ex::EntityManager &es, ex::Entity entity) { |
| 293 | ex::ComponentHandle<Body> body = entity.component<Body>(); |
| 294 | ex::ComponentHandle<Renderable> renderable = entity.component<Renderable>(); |
| 295 | ex::ComponentHandle<Collideable> collideable = entity.component<Collideable>(); |
| 296 | sf::Color colour = renderable->shape->getFillColor(); |
| 297 | colour.a = 200; |
| 298 | |
| 299 | float area = (M_PI * collideable->radius * collideable->radius) / 3.0; |
| 300 | for (int i = 0; i < area; i++) { |
| 301 | ex::Entity particle = es.create(); |
| 302 | |
| 303 | float rotationd = r(720, 180); |
| 304 | if (std::rand() % 2 == 0) rotationd = -rotationd; |
| 305 | |
| 306 | float offset = r(collideable->radius, 1); |
| 307 | float angle = r(360) * M_PI / 180.0; |
| 308 | particle.assign<Body>( |
| 309 | body->position + sf::Vector2f(offset * cos(angle), offset * sin(angle)), |
| 310 | body->direction + sf::Vector2f(offset * 2 * cos(angle), offset * 2 * sin(angle)), |
| 311 | rotationd); |
| 312 | |
| 313 | float radius = r(3, 1); |
| 314 | particle.assign<Particle>(colour, radius, radius / 2); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | void receive(const CollisionEvent &collision) { |
| 319 | // Events are immutable, so we can't destroy the entities here. We defer |