custom build rework (recursive, no limit)
This commit is contained in:
108
js/index.js
108
js/index.js
@@ -139,12 +139,6 @@ if (localSettings) {
|
|||||||
localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage
|
localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//collision groups
|
//collision groups
|
||||||
// cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet | cat.mobShield
|
// cat.player | cat.map | cat.body | cat.bullet | cat.powerUp | cat.mob | cat.mobBullet | cat.mobShield
|
||||||
const cat = {
|
const cat = {
|
||||||
@@ -158,66 +152,66 @@ const cat = {
|
|||||||
mobShield: 0x10000000,
|
mobShield: 0x10000000,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//build build grid display
|
//build build grid display
|
||||||
const build = {
|
const build = {
|
||||||
isShowingBuilds: false,
|
isShowingBuilds: false,
|
||||||
list: [],
|
list: [],
|
||||||
choosePowerUp(who, index, type) {
|
choosePowerUp(who, index, type) {
|
||||||
//check if matching a current power up
|
if (type === "field" || type === "gun") {
|
||||||
// if (type === "field" || type === "gun") {
|
//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) { //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") {
|
|
||||||
for (let i = 0; i < build.list.length; i++) {
|
for (let i = 0; i < build.list.length; i++) {
|
||||||
if (build.list[i].type === "field") { //if already click, toggle off
|
if (build.list[i].index === index && build.list[i].type === type) {
|
||||||
build.list[i].who.style.backgroundColor = "#fff"
|
|
||||||
build.list.splice(i, 1);
|
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"
|
who.style.backgroundColor = "#919ba8" //"#868f9a"
|
||||||
build.list[build.list.length] = {
|
build.list[build.list.length] = {
|
||||||
who: who,
|
who: who,
|
||||||
index: index,
|
index: index,
|
||||||
type: type,
|
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 = `<div class="grid-title"><div class="circle-grid mod"></div> ${b.mods[index].name} (${count}x)</div> ${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 = `<div class="grid-title"><div class="circle-grid mod"></div> ${b.mods[index].name}</div> ${b.mods[index].description}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
console.log(build.list)
|
|
||||||
},
|
},
|
||||||
removeMod(index) {
|
removeMod(index) {
|
||||||
for (let i = build.list.length - 1; i > -1; i--) {
|
for (let i = build.list.length - 1; i > -1; i--) {
|
||||||
@@ -228,7 +222,8 @@ const build = {
|
|||||||
spawn.setSpawnList();
|
spawn.setSpawnList();
|
||||||
spawn.setSpawnList(); //gives random mobs, not starter
|
spawn.setSpawnList(); //gives random mobs, not starter
|
||||||
game.startGame();
|
game.startGame();
|
||||||
game.difficulty = 6;
|
level.difficultyIncrease(build.list.length * game.difficultyMode)
|
||||||
|
|
||||||
level.isBuildRun = true;
|
level.isBuildRun = true;
|
||||||
for (let i = 0; i < build.list.length; i++) {
|
for (let i = 0; i < build.list.length; i++) {
|
||||||
if (build.list[i].type === "field") {
|
if (build.list[i].type === "field") {
|
||||||
@@ -252,17 +247,17 @@ document.getElementById("build-button").addEventListener("click", () => {
|
|||||||
document.getElementById("info").style.display = 'inline'
|
document.getElementById("info").style.display = 'inline'
|
||||||
} else {
|
} else {
|
||||||
build.list = []
|
build.list = []
|
||||||
// let text = '<p>choose up to 5 powers<br> <button type="button" id="build-begin-button" onclick="build.startBuildRun()">Begin Run</button></p>'
|
// let text = '<p>The difficulty increases by one level for each power up you choose.<br> <button type="button" id="build-begin-button" onclick="build.startBuildRun()">Begin Run</button></p>'
|
||||||
let text =
|
let text =
|
||||||
`<div style="display: flex; justify-content: center; align-items: center;">
|
`<div style="display: flex; justify-content: center; align-items: center;">
|
||||||
<svg class="SVG-button" onclick="build.startBuildRun()" width="90" height="40">
|
<svg class="SVG-button" onclick="build.startBuildRun()" width="90" height="45">
|
||||||
<g stroke='none' fill='#333' stroke-width="2" font-size="30px" font-family="Ariel, sans-serif">
|
<g stroke='none' fill='#333' stroke-width="2" font-size="30px" font-family="Ariel, sans-serif">
|
||||||
<text x="15" y="31">start</text>
|
<text x="15" y="32">start</text>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<div class="build-grid-module" style="font-size: 1.05em; line-height: 170%;">
|
<div class="build-grid-module" style="font-size: 1.00em; line-height: 175%;">
|
||||||
Choose five power ups.<br>Click start to begin.
|
each power up you select will increase the starting level by one
|
||||||
</div>`
|
</div>`
|
||||||
for (let i = 1, len = mech.fieldUpgrades.length; i < len; i++) {
|
for (let i = 1, len = mech.fieldUpgrades.length; i < len; i++) {
|
||||||
text += `<div class="build-grid-module" onclick="build.choosePowerUp(this,${i},'field')"><div class="grid-title"><div class="circle-grid field"></div> ${mech.fieldUpgrades[i].name}</div> ${mech.fieldUpgrades[i].description}</div>`
|
text += `<div class="build-grid-module" onclick="build.choosePowerUp(this,${i},'field')"><div class="grid-title"><div class="circle-grid field"></div> ${mech.fieldUpgrades[i].name}</div> ${mech.fieldUpgrades[i].description}</div>`
|
||||||
@@ -282,6 +277,7 @@ document.getElementById("build-button").addEventListener("click", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//set up canvas
|
//set up canvas
|
||||||
var canvas = document.getElementById("canvas");
|
var canvas = document.getElementById("canvas");
|
||||||
//using "const" causes problems in safari when an ID shares the same name.
|
//using "const" causes problems in safari when an ID shares the same name.
|
||||||
|
|||||||
Reference in New Issue
Block a user