diff --git a/js/index.js b/js/index.js index e73d928..76d7220 100644 --- a/js/index.js +++ b/js/index.js @@ -139,12 +139,6 @@ if (localSettings) { localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage } - - - - - - //collision groups // cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet | cat.mobShield const cat = { @@ -158,66 +152,66 @@ const cat = { mobShield: 0x10000000, } - //build build grid display const build = { isShowingBuilds: false, list: [], choosePowerUp(who, index, type) { - //check if matching a current power up - // if (type === "field" || type === "gun") { - for (let i = 0; i < build.list.length; i++) { - if (build.list[i].index === index && build.list[i].type === type) { //if already click, toggle off - build.list.splice(i, 1); - who.style.backgroundColor = "#fff" - return - } - } - //check if trying to get a second field - if (type === "field") { + if (type === "field" || type === "gun") { + //if already click, toggle off for (let i = 0; i < build.list.length; i++) { - if (build.list[i].type === "field") { //if already click, toggle off - build.list[i].who.style.backgroundColor = "#fff" + if (build.list[i].index === index && build.list[i].type === type) { build.list.splice(i, 1); + who.style.backgroundColor = "#fff" + return + } + } + //check if trying to get a second field + if (type === "field") { + for (let i = 0; i < build.list.length; i++) { + if (build.list[i].type === "field") { //if already click, toggle off + build.list[i].who.style.backgroundColor = "#fff" + build.list.splice(i, 1); + } } } - } - // } else { //type is mod - - // //count each mod type to check for recursion caps - // let counts = [] - // for (let i = 0; i < build.list.length; i++) { - // if (build.list[i].type === "mod") { - // if (!counts[build.list[i].index]) { - // counts[build.list[i].index] = 1 - // } else { - // counts[build.list[i].index] = counts[build.list[i].index] + 1 - // } - // } - // } - - // for (let i = 0; i < build.list.length; i++) { - // //if above max count, toggle off - // if (build.list[i].index === index && build.list[i].type === type && - // counts[index] >= b.mods[index].maxCount) { - // //remove all versions of mod - - - // who.style.backgroundColor = "#fff" - // return - // } - // } - // } - - if (build.list.length < 5) { //add to build array who.style.backgroundColor = "#919ba8" //"#868f9a" build.list[build.list.length] = { who: who, index: index, type: type, } + } else if (type === "mod") { + if (who.style.backgroundColor !== "#919ba8") who.style.backgroundColor = "#919ba8" //"#868f9a" + //if already clicked graphically indicate recursive clicks + let count = 0 + for (let i = 0; i < build.list.length; i++) { + if (build.list[i].type === "mod" && build.list[i].index === index) { + count++ + } + } + if (count < b.mods[index].maxCount) { + //add mod to build list + build.list[build.list.length] = { + who: who, + index: index, + type: type, + } + count++ + //display mod count in grid box text + if (count > 1) who.innerHTML = `
choose up to 5 powers
The difficulty increases by one level for each power up you choose.