custom mode rework, might be done

This commit is contained in:
landgreen
2020-02-17 07:26:14 -08:00
parent 32733909ab
commit b9ecfbc997
7 changed files with 230 additions and 202 deletions

View File

@@ -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 <strong>1%</strong> of max <strong class='color-h'>health</strong> every second<br>active for <strong>5 seconds</strong> after a mob <strong>dies</strong>",
description: "<strong class='color-h'>heal</strong> up to <strong>1%</strong> of max health every second<br>active for <strong>5 seconds</strong> after a mob <strong>dies</strong>",
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 <strong>laser</strong> gains <strong>+1</strong> reflection<br><strong>+20%</strong> laser <strong class='color-d'>damage</strong> and <strong class='color-f'>energy</strong> drain",
description: "your <strong>laser</strong> gains <strong>+1</strong> reflection<br><strong>+30%</strong> laser <strong class='color-d'>damage</strong> and <strong class='color-f'>energy</strong> 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 = [];

View File

@@ -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,

View File

@@ -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 = `<div class="grid-title"><div class="circle-grid mod"></div> &nbsp; ${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> &nbsp; ${b.mods[index].name}</div> ${b.mods[index].description}`
}
}
// document.title = `effective starting level: ${build.list.length * game.difficultyMode}`
// build.calculateCustomDifficulty()
},
populateGrid() {
let text = `
<div style="display: flex; justify-content: space-around; align-items: center;">
<svg class="SVG-button" onclick="build.startBuildRun()" width="115" height="51">
<g stroke='none' fill='#333' stroke-width="2" font-size="40px" font-family="Ariel, sans-serif">
<text x="18" y="38">start</text>
</g>
</svg>
<svg class="SVG-button" onclick="build.reset()" width="70" height="35">
<g stroke='none' fill='#333' stroke-width="2" font-size="22px" font-family="Ariel, sans-serif">
<text x="10" y="24">reset</text>
</g>
</svg>
</div>
<div style="align-items: center; text-align:center; font-size: 1.00em; line-height: 220%;background-color:#c4ccd8;">
<div>starting level: <input id='starting-level' type="number" step="1" value="0" min="0" max="99"></div>
<label for="difficulty-select" title="effects: number of mobs, damage done by mobs, damage done to mobs, mob speed, heal effects">difficulty:</label>
<select name="difficulty-select" id="difficulty-select-custom">
<option value="0">easy</option>
<option value="1" selected>normal</option>
<option value="2">hard</option>
<option value="4">why...</option>
</select>
</div>`
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> &nbsp; ${mech.fieldUpgrades[i].name}</div> ${mech.fieldUpgrades[i].description}</div>`
}
for (let i = 0, len = b.guns.length; i < len; i++) {
text += `<div class="build-grid-module" onclick="build.choosePowerUp(this,${i},'gun')"><div class="grid-title"><div class="circle-grid gun"></div> &nbsp; ${b.guns[i].name}</div> ${b.guns[i].description}</div>`
}
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 += `<div class="build-grid-module" style="opacity:0.3;"><div class="grid-title"><div class="circle-grid mod"></div> &nbsp; ${b.mods[i].name}</div> ${b.mods[i].description}</div>`
} else {
text += `<div class="build-grid-module" onclick="build.choosePowerUp(this,${i},'mod')"><div class="grid-title"><div class="circle-grid mod"></div> &nbsp; ${b.mods[i].name}</div> ${b.mods[i].description}</div>`
}
}
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 = `<div class="pause-grid-module" style="border:0px;background:none;"></div>`
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 = `<div class="grid-title"><div class="circle-grid mod"></div> &nbsp; ${b.mods[index].name} (${b.mods[index].count}x)</div> ${b.mods[index].description}`
} else {
b.removeMod(index);
who.innerHTML = `<div class="grid-title"><div class="circle-grid mod"></div> &nbsp; ${b.mods[index].name}</div> ${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 = `
<div style="display: flex; justify-content: space-around; align-items: center;">
<svg class="SVG-button" onclick="build.startBuildRun()" width="115" height="51">
<g stroke='none' fill='#333' stroke-width="2" font-size="40px" font-family="Ariel, sans-serif">
<text x="18" y="38">start</text>
</g>
</svg>
<svg class="SVG-button" onclick="build.reset()" width="70" height="35">
<g stroke='none' fill='#333' stroke-width="2" font-size="22px" font-family="Ariel, sans-serif">
<text x="10" y="24">reset</text>
</g>
</svg>
</div>
<div style="align-items: center; text-align:center; font-size: 1.00em; line-height: 220%;background-color:#c4ccd8;">
<div>starting level: <input id='starting-level' type="number" step="1" value="0" min="0" max="99"></div>
<label for="difficulty-select" title="effects: number of mobs, damage done by mobs, damage done to mobs, mob speed, heal effects">difficulty:</label>
<select name="difficulty-select" id="difficulty-select-custom">
<option value="0">easy</option>
<option value="1" selected>normal</option>
<option value="2">hard</option>
<option value="4">why...</option>
</select>
</div>`
for (let i = 0, len = mech.fieldUpgrades.length; i < len; i++) {
text += `<div id ="field-${i}" class="build-grid-module" onclick="build.choosePowerUp(this,${i},'field')"><div class="grid-title"><div class="circle-grid field"></div> &nbsp; ${mech.fieldUpgrades[i].name}</div> ${mech.fieldUpgrades[i].description}</div>`
}
for (let i = 0, len = b.guns.length; i < len; i++) {
text += `<div class="build-grid-module" onclick="build.choosePowerUp(this,${i},'gun')"><div class="grid-title"><div class="circle-grid gun"></div> &nbsp; ${b.guns[i].name}</div> ${b.guns[i].description}</div>`
}
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 += `<div id="mod-${i}" class="build-grid-module build-grid-disabled"><div class="grid-title"><div class="circle-grid mod"></div> &nbsp; ${b.mods[i].name}</div> ${b.mods[i].description}</div>`
} else if (b.mods[i].count > 1) {
text += `<div id="mod-${i}" class="build-grid-module" onclick="build.choosePowerUp(this,${i},'mod')"><div class="grid-title"><div class="circle-grid mod"></div> &nbsp; ${b.mods[i].name} (${b.mods[i].count}x)</div> ${b.mods[i].description}</div>`
} else {
text += `<div id="mod-${i}" class="build-grid-module" onclick="build.choosePowerUp(this,${i},'mod')"><div class="grid-title"><div class="circle-grid mod"></div> &nbsp; ${b.mods[i].name}</div> ${b.mods[i].description}</div>`
}
}
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

View File

@@ -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 = [];

View File

@@ -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
// }
},
};