Concept
My concept is inspired by the red explosive barrels from the Half-Life video game series. I wanted to recreate that same mechanic of an exploding barrel using matter.js where objects can collide with a barrel, build up damage, and trigger an explosion. The idea of explosive barrels spread into other video games with objects that explode either on impact or as it builds up damage and growing up I always enjoyed playing games with destructible elements.
Code Highlight
explode(allBoxes) {
if (this.isExploded) {
return;
}
const center = this.body.position;
for (let i = 0; i < allBoxes.length; i++) {
const currentBox = allBoxes[i];
if (!currentBox || currentBox.body.isStatic) {
continue;
}
const boxPos = currentBox.body.position;
const delta = Vector.sub(boxPos, center);
const distance = Vector.magnitude(delta);
if (distance <= 0 || distance > EXPLOSION_RADIUS) {
continue;
}
const direction = Vector.normalise(delta);
const falloff = 1 - distance / EXPLOSION_RADIUS;
const totalForce = max(EXPLOSION_MIN_FORCE, EXPLOSION_FORCE * falloff);
const force = Vector.mult(direction, totalForce);
Body.applyForce(currentBox.body, boxPos, force);
// Add a direct velocity impulse so the explosion is always visible.
Body.setVelocity(currentBox.body, {
x: currentBox.body.velocity.x + direction.x * EXPLOSION_VELOCITY_BOOST,
y: currentBox.body.velocity.y + direction.y * EXPLOSION_VELOCITY_BOOST
});
}
Composite.remove(world, this.body);
this.isExploded = true;
}
The part of the code I am most proud of is the explosion function. I track the number of collisions for the barrel, change the barrel color from gray toward red as damage increases, and once it reaches the hit limit which I defined as a global variable I remove the barrel body and apply outward force and increase the initial velocity to nearby boxes.
Embedded Sketch
Milestones and Challenges
Stage 1:

Focused on getting the core interaction working by spawning rectangles with the mouse, and getting used to coding with matter.js.
Stage 2:

Added a grounded barrel in the center area to establish the main object of the simulation and changed the background color to something I liked. At this point I began thinking about aesthetics.
Stage 3:


Introduced the damage mechanic where the barrel changes from gray toward red with each hit. A key challenge was collision handling, especially making sure hits were counted reliably and visual feedback was clear.
Stage 4:

Finally I combined everything and added the final explosion behavior after the hit threshold. I had to tune radius, force, and velocity boost values so the explosion effect was strong and readable without becoming too chaotic. I found that the force value was not as important as the initial velocity boost because of air resistance. Then I added text to show the controls and allowed the user to drag their mouse to spawn squares rather than only clicking and made the boundary cover the sides and not only the ground.
Reflection and Future Improvements
If I continue this project, I want to replace simple shapes with sprite-based visuals so the barrel and debris feel more game-like. I also want to explore whether Matter.js can be combined with a 3D workflow or whether a different engine would be better for a full 3D version. Future improvements could include sound effects, particle debris, and different barrel types with unique blast strengths.
This is a really strong and clear project, especially in how you translate a familiar game mechanic into a physics-based system. The idea of building damage over time rather than triggering an immediate explosion works well, as it introduces anticipation and makes the interaction feel more intentional.
The explosion function is particularly effective. The use of distance-based falloff combined with an added velocity boost creates a result that feels both physically grounded and visually satisfying. It is also good that you noticed the role of air resistance and adjusted for it, as this shows a deeper understanding of how the system behaves beyond just coding the effect.
The progression of your milestones is clear, moving from basic interaction to a more complete system with feedback and control. The color shift from gray to red is a simple but strong decision, as it communicates damage in a way that is immediately readable.
Your concept is strong because it takes a simple game mechanic and turns it into an interactive system. I like that you focused on the idea of damage building up first, instead of making the barrel explode right away, because that makes the interaction more interesting and gives the user a sense of tension before the explosion happens. The color change from gray to red is also a smart choice since it gives clear visual feedback and helps the user understand what is happening. It also connects well to the game inspiration, because explosive barrels are familiar but still fun to recreate in your own way. What makes the concept nice is that it is simple, recognizable, and has a clear action and reaction.
Hi Saeed! Your project has a strong and engaging concept, Good Job! The idea is simple but effective. One way to improve the concept even more would be to expand it beyond a single barrel by adding chain reactions, different barrel types. But overall it is very appealing!