mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-28 08:33:36 +00:00
explosion effect is looking nice
This commit is contained in:
@@ -5,11 +5,13 @@ precision mediump float;
|
||||
// Input vertex attributes (from vertex shader)
|
||||
varying vec3 fragPosition;
|
||||
|
||||
uniform float alpha;
|
||||
|
||||
void main() {
|
||||
// Texel color fetching from texture sampler
|
||||
|
||||
// NOTE: Implement here your fragment shader code
|
||||
|
||||
gl_FragColor = vec4(fragPosition, 1.0);
|
||||
gl_FragColor = vec4(fragPosition, alpha);
|
||||
|
||||
}
|
||||
@@ -19,6 +19,11 @@ namespace BBM
|
||||
float explosionRadius = 4;
|
||||
//! @brief to have the shader move by the time
|
||||
float frameCounter = 0;
|
||||
//! @brief Transparency
|
||||
float alpha = 1;
|
||||
|
||||
//! @brief max explosion radius
|
||||
static constexpr float maxRadius = 1.2;
|
||||
|
||||
//! @brief The clock to use
|
||||
std::chrono::nanoseconds clock = 0ns;
|
||||
|
||||
@@ -58,13 +58,17 @@ namespace BBM
|
||||
if (duration_cast<std::chrono::milliseconds>(ctx.clock).count() <= 10)
|
||||
return;
|
||||
ctx.clock = 0ns;
|
||||
ctx.explosionRadius -= 0.3;
|
||||
if (ctx.explosionRadius < 1.2) {
|
||||
ctx.explosionRadius = 1.2;
|
||||
ctx.explosionRadius -= 1;
|
||||
if (ctx.explosionRadius < BombExplosionShaderComponent::maxRadius) {
|
||||
ctx.explosionRadius = BombExplosionShaderComponent::maxRadius;
|
||||
ctx.alpha -= 0.1;
|
||||
// slow the explosion movement
|
||||
ctx.frameCounter -= 0.1;
|
||||
}
|
||||
ctx.frameCounter += 0.2;
|
||||
shader.shader.setShaderUniformVar("frame", ctx.frameCounter);
|
||||
shader.shader.setShaderUniformVar("alpha", ctx.alpha);
|
||||
shader.shader.setShaderUniformVar("radius", ctx.explosionRadius);
|
||||
ctx.frameCounter += 0.1;
|
||||
})
|
||||
.addComponent<TimerComponent>(500ms, [](WAL::Entity &explosion, WAL::Wal &wal) {
|
||||
explosion.scheduleDeletion();
|
||||
|
||||
Reference in New Issue
Block a user