70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
"use strict";
|
|
|
|
const ExplosionsManager = (function(){
|
|
|
|
const ExplosionsManager = function(xgravity){
|
|
|
|
const self = this;
|
|
|
|
const shield_fx = new ShieldExplosionsFx(xgravity);
|
|
const hull_fx = new HullHitExplosionsFx(xgravity);
|
|
const sparks_fx = new DeflectionSparksFx(xgravity);
|
|
const cockpit_fx = new CockpitImpactFx(xgravity);
|
|
|
|
const get_cell_size = (width, height) => {
|
|
const cells = xgravity.settings.get("cells", null, 40);
|
|
return (width < height ? width : height) / cells;
|
|
};
|
|
|
|
this.add = (cell_x, cell_y, type = "shield") => {
|
|
if(type === "shield"){
|
|
shield_fx.add(cell_x, cell_y);
|
|
} else {
|
|
hull_fx.add(cell_x, cell_y);
|
|
}
|
|
};
|
|
|
|
this.add_sparks = (cell_x, cell_y, normal_x, normal_y, intensity) => {
|
|
sparks_fx.add(cell_x, cell_y, normal_x, normal_y, intensity);
|
|
};
|
|
|
|
this.add_mothership_impact = () => {
|
|
cockpit_fx.trigger();
|
|
};
|
|
|
|
this.update = (delta_time) => {
|
|
shield_fx.update(delta_time);
|
|
hull_fx.update(delta_time);
|
|
sparks_fx.update(delta_time);
|
|
cockpit_fx.update(delta_time);
|
|
};
|
|
|
|
// Renderizado del plano de batalla (ondas y chispas espaciales)
|
|
this.render = (ctx, width, height) => {
|
|
const cell_px = get_cell_size(width, height);
|
|
const cx = width / 2;
|
|
const cy = height / 2;
|
|
|
|
ctx.save();
|
|
ctx.globalCompositeOperation = "lighter";
|
|
shield_fx.render(ctx, cell_px, cx, cy);
|
|
hull_fx.render(ctx, cell_px, cx, cy);
|
|
sparks_fx.render(ctx, cell_px, cx, cy);
|
|
ctx.restore();
|
|
};
|
|
|
|
// Renderizado exclusivo de la cabina (pantalla completa y rocas sólidas)
|
|
this.render_cockpit = (ctx, width, height) => {
|
|
cockpit_fx.render(ctx, width, height);
|
|
};
|
|
|
|
this.reset = () => {
|
|
shield_fx.reset();
|
|
hull_fx.reset();
|
|
sparks_fx.reset();
|
|
cockpit_fx.reset();
|
|
};
|
|
};
|
|
|
|
return ExplosionsManager;
|
|
})(); |