From 1bb3a19102fb8787e738d276941c5ebb88518af6 Mon Sep 17 00:00:00 2001 From: landgreen Date: Fri, 9 Aug 2019 16:27:08 -0700 Subject: [PATCH] added laser --- js/level.js | 2 +- js/powerups.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/js/level.js b/js/level.js index 92cd0fe..f87fcc5 100644 --- a/js/level.js +++ b/js/level.js @@ -204,7 +204,7 @@ const level = { }, //empty map for testing mobs intro() { - b.giveGuns(0, 1000) + // b.giveGuns(0, 1000) game.zoomScale = 1000 //1400 is normal game.zoomTransition(1600, 1) diff --git a/js/powerups.js b/js/powerups.js index d9f559f..a457d82 100644 --- a/js/powerups.js +++ b/js/powerups.js @@ -62,20 +62,24 @@ const powerUps = { 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 twice to give ammo to a gun with ammo, not Infinity + if (target.ammo === Infinity) target = b.guns[Math.floor(Math.random() * b.guns.length)]; + if (target.ammo === Infinity) target = b.guns[Math.floor(Math.random() * b.guns.length)]; } else { - //if you don't have a gun just add ammo to a random gun + //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)]; } - //ammo given scales as mobs take more hits to kill - const ammo = Math.ceil((target.ammoPack * (0.60 + 0.5 * Math.random())) / b.dmgScale); - target.ammo += ammo; 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.60 + 0.5 * Math.random())) / b.dmgScale); + target.ammo += ammo; game.updateGunHUD(); game.makeTextLog("+" + ammo + " ammo: " + target.name, 180); }