isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
54 lines (53 loc) • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.newChargeBarSprites = newChargeBarSprites;
exports.renderChargeBar = renderChargeBar;
const CHARGE_BAR_ANM2 = "gfx/ui/ui_chargebar.anm2";
/**
* Constructor for a `ChargeBarSprites` object. For more information, see the `renderChargeBar`
* helper function.
*
* Note that this is for the vertical charge bar that represents the number of charges that an
* active item has, not the circular charge bar that shows e.g. the charge rate of Brimstone.
*/
function newChargeBarSprites(maxCharges) {
const back = Sprite();
back.Load(CHARGE_BAR_ANM2, true);
back.Play("BarEmpty", true);
const meter = Sprite();
meter.Load(CHARGE_BAR_ANM2, true);
meter.Play("BarFull", true);
const meterBattery = Sprite();
meterBattery.Load(CHARGE_BAR_ANM2, true);
meterBattery.Play("BarFull", true);
const lines = Sprite();
lines.Load(CHARGE_BAR_ANM2, true);
lines.Play(`BarOverlay${maxCharges}`, true);
return {
back,
meter,
meterBattery,
lines,
maxCharges,
};
}
/**
* Helper function to render a charge bar on the screen. First, call the `newChargeBarSprites`
* function to initialize the sprites, and then call this function on every render frame.
*
* Note that this is for the vertical charge bar that represents the number of charges that an
* active item has, not the circular charge bar that shows e.g. the charge rate of Brimstone.
*/
function renderChargeBar(sprites, position, normalCharges, batteryCharges) {
sprites.back.Render(position);
const normalChargesClamp = getChargeBarClamp(normalCharges, sprites.maxCharges);
sprites.meter.Render(position, normalChargesClamp);
const batteryChargesClamp = getChargeBarClamp(batteryCharges, sprites.maxCharges);
sprites.meterBattery.Render(position, batteryChargesClamp);
sprites.lines.Render(position);
}
function getChargeBarClamp(charges, maxCharges) {
const meterMultiplier = 24 / maxCharges;
const meterClip = 26 - charges * meterMultiplier;
return Vector(0, meterClip);
}