MCPcopy Create free account
hub / github.com/ddnet/ddnet / Explosion

Method Explosion

src/game/client/components/effects.cpp:326–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

324}
325
326void CEffects::Explosion(vec2 Pos, float Alpha)
327{
328 // add to flow
329 for(int y = -8; y <= 8; y++)
330 for(int x = -8; x <= 8; x++)
331 {
332 if(x == 0 && y == 0)
333 continue;
334
335 float a = 1 - (length(vec2(x, y)) / length(vec2(8.0f, 8.0f)));
336 GameClient()->m_Flow.Add(Pos + vec2(x, y) * 16.0f, normalize(vec2(x, y)) * 5000.0f * a, 10.0f);
337 }
338
339 // add the explosion
340 CParticle p;
341 p.SetDefault();
342 p.m_Spr = SPRITE_PART_EXPL01;
343 p.m_Pos = Pos;
344 p.m_LifeSpan = 0.4f;
345 p.m_StartSize = 150.0f;
346 p.m_EndSize = 0.0f;
347 p.m_Rot = random_angle();
348 p.m_Color.a = Alpha;
349 p.m_StartAlpha = Alpha;
350 GameClient()->m_Particles.Add(CParticles::GROUP_EXPLOSIONS, &p);
351
352 // Nudge position slightly to edge of closest tile so the
353 // smoke doesn't get stuck inside the tile.
354 if(Collision()->CheckPoint(Pos))
355 {
356 const vec2 DistanceToTopLeft = Pos - vec2(round_truncate(Pos.x / 32), round_truncate(Pos.y / 32)) * 32;
357
358 vec2 CheckOffset;
359 CheckOffset.x = (DistanceToTopLeft.x > 16.0f ? 32.0f : -1.0f);
360 CheckOffset.y = (DistanceToTopLeft.y > 16.0f ? 32.0f : -1.0f);
361 CheckOffset -= DistanceToTopLeft;
362
363 for(vec2 Mask : {vec2(1.0f, 0.0f), vec2(0.0f, 1.0f), vec2(1.0f, 1.0f)})
364 {
365 const vec2 NewPos = Pos + CheckOffset * Mask;
366 if(!Collision()->CheckPoint(NewPos))
367 {
368 Pos = NewPos;
369 break;
370 }
371 }
372 }
373
374 // add the smoke
375 for(int i = 0; i < 24; i++)
376 {
377 p.SetDefault();
378 p.m_Spr = SPRITE_PART_SMOKE;
379 p.m_Pos = Pos;
380 p.m_Vel = random_direction() * (random_float(1.0f, 1.2f) * 1000.0f);
381 p.m_LifeSpan = random_float(0.5f, 0.9f);
382 p.m_StartSize = random_float(32.0f, 40.0f);
383 p.m_EndSize = 0.0f;

Callers 2

ProcessEventsMethod · 0.80
HandlePredictedEventsMethod · 0.80

Calls 12

lengthFunction · 0.85
normalizeFunction · 0.85
random_angleFunction · 0.85
round_truncateFunction · 0.85
random_directionFunction · 0.85
random_floatFunction · 0.85
SetDefaultMethod · 0.80
CheckPointMethod · 0.80
WithAlphaMethod · 0.80
MultiplyMethod · 0.80
ColorRGBAClass · 0.70
AddMethod · 0.45

Tested by

no test coverage detected