diff --git a/js/bullets.js b/js/bullets.js index ef47558..c32e171 100644 --- a/js/bullets.js +++ b/js/bullets.js @@ -46,21 +46,6 @@ const b = { isModEnergyRecovery: null, isModHealthRecovery: null, isModEnergyLoss: null, - removeAllMods() { - for (let i = 0, len = b.mods.length; i < len; i++) { - b.mods[i].remove(); - b.mods[i].count = 0 - } - b.modCount = 0; - - }, - setModDefaults() { - for (let i = 0, len = b.mods.length; i < len; i++) { - if (b.mods[i].count) b.mods[i].remove(); - b.mods[i].count = 0 - } - b.modCount = 0; - }, modOnHealthChange() { //used with acid mod if (b.isModAcidDmg && mech.health > 0.8) { game.playerDmgColor = "rgba(0,80,80,0.9)" @@ -139,7 +124,7 @@ const b = { maxCount: 1, count: 0, allowed() { - return mech.health < 0.75 + return mech.health < 0.75 || level.isBuildRun }, effect() { b.isModLowHealthDmg = true; //used in mob.damage() @@ -215,7 +200,7 @@ const b = { maxCount: 3, count: 0, allowed() { - return b.haveGunCheck("spores") || b.haveGunCheck("drones") || b.haveGunCheck("super balls") || b.haveGunCheck("foam") + return mech.fieldUpgrades[mech.fieldMode].name === "nano-scale manufacturing" || b.haveGunCheck("spores") || b.haveGunCheck("drones") || b.haveGunCheck("super balls") || b.haveGunCheck("foam") }, effect() { b.isModBulletsLastLonger += 0.33 @@ -369,7 +354,7 @@ const b = { }, { name: "scrap recycling", - description: "regen up to 1% of max health every second
active for 5 seconds after a mob dies", + description: "heal up to 1% of max health every second
active for 5 seconds after a mob dies", maxCount: 1, count: 0, allowed() { @@ -388,7 +373,7 @@ const b = { maxCount: 1, count: 0, allowed() { - return b.isModHealthRecovery + return b.isModEnergyRecovery }, effect() { b.isModEnergyLoss = true; @@ -422,7 +407,7 @@ const b = { maxCount: 1, count: 0, allowed() { - return b.modSquirrelFx === 1.2 + return b.modSquirrelFx > 1 }, effect() { b.isModStomp = true @@ -547,7 +532,7 @@ const b = { maxCount: 9, count: 0, allowed() { - return mech.health < 0.7 + return mech.health < 0.7 || level.isBuildRun }, effect() { b.modRecursiveHealing += 1 @@ -661,7 +646,7 @@ const b = { maxCount: 1, count: 0, allowed() { - return (b.modCount > 6) + return (b.modCount > 6) && !level.isBuildRun }, effect: () => { let count = b.modCount @@ -669,7 +654,7 @@ const b = { for (let i = 0; i < count; i++) { // spawn new mods powerUps.spawn(mech.pos.x, mech.pos.y, "mod"); } - b.setModDefaults(); // remove all mods + b.setupAllMods(); // remove all mods //have state is checked in mech.death() }, remove() { @@ -723,7 +708,7 @@ const b = { }, { name: "specular reflection", - description: "your laser gains +1 reflection
+20% laser damage and energy drain", + description: "your laser gains +1 reflection
+30% laser damage and energy drain", maxCount: 9, count: 0, allowed() { @@ -731,8 +716,8 @@ const b = { }, effect() { b.modLaserReflections++; - b.modLaserDamage += 0.010; //base is 0.05 - b.modLaserFieldDrain += 0.0004 //base is 0.002 + b.modLaserDamage += 0.015; //base is 0.05 + b.modLaserFieldDrain += 0.0006 //base is 0.002 }, remove() { b.modLaserReflections = 2; @@ -772,6 +757,27 @@ const b = { // } // }, ], + removeMod(index) { + b.mods[index].remove(); + b.mods[index].count = 0; + game.updateModHUD(); + }, + setupAllMods() { + for (let i = 0, len = b.mods.length; i < len; i++) { + b.mods[i].remove(); + b.mods[i].count = 0 + } + b.modCount = 0; + game.updateModHUD(); + }, + // setupAllMods() { + // for (let i = 0, len = b.mods.length; i < len; i++) { + // if (b.mods[i].count) b.mods[i].remove(); + // b.mods[i].count = 0 + // } + // b.modCount = 0; + // game.updateModHUD(); + // }, giveMod(index = 'random') { if (index === 'random') { let options = []; diff --git a/js/game.js b/js/game.js index 9ee2aff..d4168a6 100644 --- a/js/game.js +++ b/js/game.js @@ -437,7 +437,7 @@ const game = { } b.activeGun = null; - b.removeAllMods(); //sets mods to defauls values + b.setupAllMods(); //sets mods to default values game.updateModHUD(); mech.maxHealth = 1 mech.fieldEnergyMax = 1 @@ -533,7 +533,7 @@ const game = { if (game.firstRun) { mech.spawn(); //spawns the player - b.setModDefaults(); //doesn't run on reset so that gun mods carry over to new runs + b.setupAllMods(); //doesn't run on reset so that gun mods carry over to new runs function shuffle(array) { var currentIndex = array.length, diff --git a/js/index.js b/js/index.js index 3534708..6087db7 100644 --- a/js/index.js +++ b/js/index.js @@ -14,147 +14,6 @@ const cat = { //build build grid display const build = { - choosePowerUp(who, index, type) { - - // mech.setField(build.list[i].index) - // b.giveGuns(build.list[i].index) - // b.giveMod(build.list[i].index) - - - if (type === "field" || type === "gun") { - let isDeselect = false - //if already click, toggle off - for (let i = 0; i < build.list.length; i++) { - if (build.list[i].index === index && build.list[i].type === type) { - build.list.splice(i, 1); - who.style.backgroundColor = "#fff" - isDeselect = true - break - } - } - //check if trying to get a second field - if (type === "field") { - mech.setField(index) - 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); - } - } - } - if (!isDeselect) { - 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 = `
  ${b.mods[index].name} (${count}x)
${b.mods[index].description}` - } else { - //when above the mod limit remove all of that mod - for (let i = build.list.length - 1; i > -1; i--) { - if (build.list[i].index === index && build.list[i].type === type) { - build.list.splice(i, 1); - } - } - //and reset the text - who.style.backgroundColor = "#fff" - who.innerHTML = `
  ${b.mods[index].name}
${b.mods[index].description}` - } - } - // document.title = `effective starting level: ${build.list.length * game.difficultyMode}` - // build.calculateCustomDifficulty() - }, - populateGrid() { - let text = ` -
- - - start - - - - - reset - - -
-
-
starting level:
- - -
` - for (let i = 1, len = mech.fieldUpgrades.length; i < len; i++) { - text += `
  ${mech.fieldUpgrades[i].name}
${mech.fieldUpgrades[i].description}
` - } - for (let i = 0, len = b.guns.length; i < len; i++) { - text += `
  ${b.guns[i].name}
${b.guns[i].description}
` - } - for (let i = 0, len = b.mods.length; i < len; i++) { - if ( - !b.mods[i].allowed() || - b.mods[i].name === "+1 cardinality" || b.mods[i].name === "leveraged investment" - ) { - text += `
  ${b.mods[i].name}
${b.mods[i].description}
` - } else { - text += `
  ${b.mods[i].name}
${b.mods[i].description}
` - } - } - document.getElementById("build-grid").innerHTML = text - }, - reset() { - build.populateGrid(); - - document.getElementById("difficulty-select-custom").value = localSettings.difficultyMode - document.getElementById("difficulty-select-custom").addEventListener("input", () => { - document.getElementById("difficulty-select").value = document.getElementById("difficulty-select-custom").value - game.difficultyMode = Number(document.getElementById("difficulty-select-custom").value) - localSettings.difficultyMode = game.difficultyMode - localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage - // build.calculateCustomDifficulty() - }); - - document.getElementById("build-grid").style.display = "grid" - // build.calculateCustomDifficulty() - document.getElementById("difficulty-select-custom").value = localSettings.difficultyMode - }, - - startBuildRun() { - spawn.setSpawnList(); //gives random mobs, not starter mobs - spawn.setSpawnList(); - const increase = Number(document.getElementById("starting-level").value) * game.difficultyMode - level.levelsCleared += increase; - level.difficultyIncrease(increase) //increase difficulty based on modes - document.body.style.cursor = "none"; - document.body.style.overflow = "hidden" - document.getElementById("build-grid").style.display = "none" - game.paused = false; - requestAnimationFrame(cycle); - }, pauseGrid() { // let text = `
` let text = ` @@ -202,6 +61,156 @@ const build = { document.getElementById("pause-grid-left").style.display = "none" document.getElementById("pause-grid-right").style.display = "none" }, + choosePowerUp(who, index, type) { + if (type === "gun") { + let isDeselect = false + for (let i = 0, len = b.inventory.length; i < len; i++) { //look for selection in inventory + if (b.guns[b.inventory[i]].name === b.guns[index].name) { //if already clicked, remove gun + isDeselect = true + who.classList.remove("build-grid-selected"); + //remove gun + b.inventory.splice(i, 1) + b.guns[index].count = 0; + b.guns[index].have = false; + if (b.guns[index].ammo != Infinity) b.guns[index].ammo = 0; + game.makeGunHUD(); + break + } + } + if (!isDeselect) { //add gun + who.classList.add("build-grid-selected"); + b.giveGuns(index) + } + } else if (type === "field") { + if (mech.fieldMode !== index) { + document.getElementById("field-" + mech.fieldMode).classList.remove("build-grid-selected"); + mech.setField(index) + who.classList.add("build-grid-selected"); + } + } else if (type === "mod") { //remove mod if you have too many + if (b.mods[index].count < b.mods[index].maxCount) { + if (!who.classList.contains("build-grid-selected")) who.classList.add("build-grid-selected"); + b.giveMod(index) + if (b.mods[index].count > 1) who.innerHTML = `
  ${b.mods[index].name} (${b.mods[index].count}x)
${b.mods[index].description}` + } else { + b.removeMod(index); + who.innerHTML = `
  ${b.mods[index].name}
${b.mods[index].description}` + who.classList.remove("build-grid-selected"); + } + } + //disable not allowed mods + for (let i = 0, len = b.mods.length; i < len; i++) { + const modID = document.getElementById("mod-" + i) + + if (b.mods[i].allowed()) { + if (modID.classList.contains("build-grid-disabled")) { + modID.classList.remove("build-grid-disabled"); + modID.setAttribute("onClick", `javascript: build.choosePowerUp(this,${i},'mod')`); + } + } else { + if (!modID.classList.contains("build-grid-disabled")) { + modID.classList.add("build-grid-disabled"); + modID.onclick = null + } + if (b.mods[i].count > 0) { + b.removeMod(i) + } + if (modID.classList.contains("build-grid-selected")) { + modID.classList.remove("build-grid-selected"); + } + } + } + }, + populateGrid() { + level.isBuildRun = true; + let text = ` +
+ + + start + + + + + reset + + +
+
+
starting level:
+ + +
` + for (let i = 0, len = mech.fieldUpgrades.length; i < len; i++) { + text += `
  ${mech.fieldUpgrades[i].name}
${mech.fieldUpgrades[i].description}
` + } + for (let i = 0, len = b.guns.length; i < len; i++) { + text += `
  ${b.guns[i].name}
${b.guns[i].description}
` + } + for (let i = 0, len = b.mods.length; i < len; i++) { + if (!b.mods[i].allowed()) { // || b.mods[i].name === "+1 cardinality") { //|| b.mods[i].name === "leveraged investment" + text += `
  ${b.mods[i].name}
${b.mods[i].description}
` + } else if (b.mods[i].count > 1) { + text += `
  ${b.mods[i].name} (${b.mods[i].count}x)
${b.mods[i].description}
` + } else { + text += `
  ${b.mods[i].name}
${b.mods[i].description}
` + } + } + document.getElementById("build-grid").innerHTML = text + document.getElementById("difficulty-select-custom").value = document.getElementById("difficulty-select").value + document.getElementById("difficulty-select-custom").addEventListener("input", () => { + game.difficultyMode = Number(document.getElementById("difficulty-select-custom").value) + localSettings.difficultyMode = Number(document.getElementById("difficulty-select-custom").value) + document.getElementById("difficulty-select").value = document.getElementById("difficulty-select-custom").value + localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage + }); + }, + reset() { + mech.setField(0) + + b.inventory = []; //removes guns and ammo + for (let i = 0, len = b.guns.length; i < len; ++i) { + b.guns[i].count = 0; + b.guns[i].have = false; + if (b.guns[i].ammo != Infinity) b.guns[i].ammo = 0; + } + b.activeGun = null; + game.makeGunHUD(); + + b.setupAllMods(); + + build.populateGrid(); + document.getElementById("field-0").classList.add("build-grid-selected"); + document.getElementById("build-grid").style.display = "grid" + }, + + startBuildRun() { + spawn.setSpawnList(); //gives random mobs, not starter mobs + spawn.setSpawnList(); + if (b.inventory.length > 0) { + b.activeGun = b.inventory[0] //set first gun to active gun + game.makeGunHUD(); + } + + //remove any bullets that might have spawned from mods + for (let i = 0; i < bullet.length; ++i) Matter.World.remove(engine.world, bullet[i]); + bullet = []; + + const increase = Number(document.getElementById("starting-level").value) * game.difficultyMode + level.levelsCleared += increase; + level.difficultyIncrease(increase) //increase difficulty based on modes + + document.body.style.cursor = "none"; + document.body.style.overflow = "hidden" + document.getElementById("build-grid").style.display = "none" + game.paused = false; + requestAnimationFrame(cycle); + } } document.getElementById("build-button").addEventListener("click", () => { //setup build run diff --git a/js/player.js b/js/player.js index 9712594..deb0c1c 100644 --- a/js/player.js +++ b/js/player.js @@ -105,7 +105,7 @@ const mech = { Sy: 0, //adds a smoothing effect to vertical only Vx: 0, Vy: 0, - jumpForce: 0.38, //0.38 //this is reset in b.setModDefaults() + jumpForce: 0.38, //0.38 //this is reset in b.setupAllMods() gravity: 0.0024, //0.0019 //game.g is 0.001 friction: { ground: 0.01, @@ -323,7 +323,7 @@ const mech = { } function randomizeMods() { - b.setModDefaults(); //remove all mods + b.setupAllMods(); //remove all mods //remove all bullets for (let i = 0; i < bullet.length; ++i) Matter.World.remove(engine.world, bullet[i]); bullet = []; diff --git a/js/powerups.js b/js/powerups.js index 34b0cd7..2ab3475 100644 --- a/js/powerups.js +++ b/js/powerups.js @@ -62,7 +62,6 @@ 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))]]; @@ -302,36 +301,35 @@ const powerUps = { } }, spawn(x, y, target, moving = true, mode = null) { - if (!level.isBuildRun || target === "heal" || target === "ammo") { - let index = powerUp.length; - target = powerUps[target]; - size = target.size(); - powerUp[index] = Matter.Bodies.polygon(x, y, 0, size, { - density: 0.001, - frictionAir: 0.01, - restitution: 0.8, - inertia: Infinity, //prevents rotation - collisionFilter: { - group: 0, - category: cat.powerUp, - mask: cat.map | cat.powerUp - }, - color: target.color, - effect: target.effect, - name: target.name, - size: size - }); - if (mode) { - // console.log(mode) - powerUp[index].mode = mode - } - if (moving) { - Matter.Body.setVelocity(powerUp[index], { - x: (Math.random() - 0.5) * 15, - y: Math.random() * -9 - 3 - }); - } - World.add(engine.world, powerUp[index]); //add to world + // if (!level.isBuildRun || target === "heal" || target === "ammo") { + let index = powerUp.length; + target = powerUps[target]; + size = target.size(); + powerUp[index] = Matter.Bodies.polygon(x, y, 0, size, { + density: 0.001, + frictionAir: 0.01, + restitution: 0.8, + inertia: Infinity, //prevents rotation + collisionFilter: { + group: 0, + category: cat.powerUp, + mask: cat.map | cat.powerUp + }, + color: target.color, + effect: target.effect, + name: target.name, + size: size + }); + if (mode) { + powerUp[index].mode = mode } + if (moving) { + Matter.Body.setVelocity(powerUp[index], { + x: (Math.random() - 0.5) * 15, + y: Math.random() * -9 - 3 + }); + } + World.add(engine.world, powerUp[index]); //add to world + // } }, }; \ No newline at end of file diff --git a/style.css b/style.css index 5d29d30..ee7fcda 100644 --- a/style.css +++ b/style.css @@ -214,6 +214,18 @@ summary { background-color: #efeff5; } +.build-grid-selected { + background-color: #919ba8; +} + +.build-grid-selected:hover { + background-color: #919ba8; +} + +.build-grid-disabled { + opacity: 0.15; +} + #info { position: absolute; bottom: 3px; diff --git a/todo.txt b/todo.txt index db34a28..732769e 100644 --- a/todo.txt +++ b/todo.txt @@ -1,5 +1,8 @@ ************** TODO - n-gon ************** +consider making jumping cost energy (like stamina) + should walking cost energy too? + add in requirements to custom mode grey out mods that don't meet requirements make custom undo method for mods