let powerUp = [];
const powerUps = {
heal: {
name: "heal",
color: "#0f9",
size() {
return 40 * Math.sqrt(0.1 + Math.random() * 0.5);
},
effect() {
let heal = this.size / 40;
mech.addHealth(heal * heal);
//game.makeTextLog('heal for '+(heal*100).toFixed(0)+'%',80)
}
},
field: {
name: "field",
color: "#f9f",
size() {
return 40;
},
effect() {
const previousMode = mech.fieldMode
if (!this.mode) { //this.mode is set if the power up has been ejected from player
mode = mech.fieldMode
while (mode === mech.fieldMode) {
mode = Math.ceil(Math.random() * (mech.fieldUpgrades.length - 1))
}
mech.fieldUpgrades[mode](); //choose random field upgrade that you don't already have
} else {
mech.fieldUpgrades[this.mode](); //set a predetermined power up
}
if (previousMode !== 0) { //pop the old field out in case player wants to swap back
// mech.fieldMeter = 0 //drop field meter to zero to prevent automatic pickup
mech.fieldCDcycle = game.cycle + 60; //trigger fieldCD to stop power up grab automatic pick up of spawn
powerUps.spawn(mech.pos.x, mech.pos.y, "field", false, previousMode);
}
// mech.fieldUpgrades[3]();
//pause game so player can read above the new field
// game.fpsCap = 0 //40 - Math.min(25, 100 * dmg)
// game.fpsInterval = 1000 / game.fpsCap;
// function unpause() {
// game.fpsCap = 72
// game.fpsInterval = 1000 / game.fpsCap;
// document.body.removeEventListener("keydown", unpause);
// }
// document.body.addEventListener("keydown", unpause);
}
},
ammo: {
name: "ammo",
color: "#467",
size() {
return 17;
},
effect() {
//only get ammo for guns player has
let target;
// console.log(b.inventory.length)
if (b.inventory.length > 0) {
//add ammo to a gun in inventory
target = b.guns[b.inventory[Math.floor(Math.random() * (b.inventory.length))]];
//try 3 more times to give ammo to a gun with ammo, not Infinity
if (target.ammo === Infinity) {
target = b.guns[b.inventory[Math.floor(Math.random() * (b.inventory.length))]]
if (target.ammo === Infinity) {
target = b.guns[b.inventory[Math.floor(Math.random() * (b.inventory.length))]]
if (target.ammo === Infinity) target = b.guns[b.inventory[Math.floor(Math.random() * (b.inventory.length))]]
}
}
} else {
//if you don't have any guns just add ammo to a random gun you don't have yet
target = b.guns[Math.floor(Math.random() * b.guns.length)];
}
if (target.ammo === Infinity) {
mech.fieldMeter = 1;
game.makeTextLog("+energy", 180);
} else {
//ammo given scales as mobs take more hits to kill
const ammo = Math.ceil((target.ammoPack * (0.70 + 0.2 * Math.random())) / b.dmgScale);
target.ammo += ammo;
game.updateGunHUD();
game.makeTextLog("+" + ammo + " ammo: " + target.name, 180);
}
}
},
gun: {
name: "gun",
color: "#0cf",
size() {
return 30;
},
effect() {
//find what guns I don't have
let options = [];
for (let i = 0; i < b.guns.length; ++i) {
if (!b.guns[i].have) options.push(i);
}
//give player a gun they don't already have if possible
if (options.length > 0) {
let newGun = options[Math.floor(Math.random() * options.length)];
// newGun = 4; //makes every gun you pick up this type //enable for testing one gun
if (b.activeGun === null) {
b.activeGun = newGun //if no active gun switch to new gun
game.makeTextLog(
// "