added local storage,

This commit is contained in:
landgreen
2019-12-30 18:53:46 -08:00
parent 2073ae2279
commit 0ffafd5c31
4 changed files with 57 additions and 17 deletions

View File

@@ -24,7 +24,7 @@ const b = {
modMoreDrops: null,
isModLowHealthDmg: null,
isModFarAwayDmg: null,
isModMonogamy: null,
isModEntanglement: null,
isModMassEnergy: null,
setModDefaults() {
b.modCount = 0;
@@ -47,7 +47,7 @@ const b = {
b.modMoreDrops = 0;
b.isModLowHealthDmg = false;
b.isModFarAwayDmg = false;
b.isModMonogamy = false;
b.isModEntanglement = false;
b.isModMassEnergy = false;
mech.Fx = 0.015;
mech.jumpForce = 0.38;
@@ -162,7 +162,7 @@ const b = {
description: "using your first gun reduces <strong>harm</strong><br>scales by <strong>7%</strong> for each gun in your inventory",
have: false, //13
effect: () => { // good with laser-bots
b.isModMonogamy = true
b.isModEntanglement = true
}
},
{
@@ -1792,8 +1792,8 @@ const b = {
});
}
} else { //normal fire mode
const FIELD_DRAIN = 0.002 //laser drains energy as well as bullets
const damage = 0.045
const FIELD_DRAIN = 0.0018 //laser drains energy as well as bullets
const damage = 0.05
if (mech.fieldMeter < FIELD_DRAIN) {
mech.fireCDcycle = mech.cycle + 100; // cool down if out of energy
} else {

View File

@@ -79,7 +79,7 @@ const game = {
buttonCD: 0,
isBodyDamage: true,
levelsCleared: 0,
difficultyMode: null,
difficultyMode: 1,
difficulty: 1,
dmgScale: null, //set in levels.setDifficulty
healScale: 1,

View File

@@ -2,6 +2,8 @@
/* TODO: *******************************************
*****************************************************
use cookies to remember settings
field: catch mobs in your field and make them into guardian bullets
negative mod effect ideas
@@ -90,6 +92,34 @@ game mechanics
*/
// local storage
let localSettings = JSON.parse(localStorage.getItem("localSettings"));
if (localSettings) {
game.isBodyDamage = localSettings.isBodyDamage
document.getElementById("body-damage").checked = localSettings.isBodyDamage
game.difficultyMode = localSettings.difficultyMode
document.getElementById("difficulty-select").value = localSettings.difficultyMode
game.fpsCapDefault = localSettings.fpsCapDefault
document.getElementById("fps-select").value = localSettings.fpsCapDefault
} else {
localSettings = {
isBodyDamage: true,
difficultyMode: '1',
fpsCapDefault: '72',
};
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 = {
@@ -286,10 +316,20 @@ document.getElementById("fps-select").addEventListener("input", () => {
} else if (value === '15') {
game.fpsCapDefault = 15
}
localSettings.fpsCapDefault = game.fpsCapDefault
localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage
});
document.getElementById("body-damage").addEventListener("input", () => {
game.isBodyDamage = document.getElementById("body-damage").checked
localSettings.isBodyDamage = game.isBodyDamage
localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage
});
document.getElementById("difficulty-select").addEventListener("input", () => {
game.difficultyMode = Number(document.getElementById("difficulty-select").value)
localSettings.difficultyMode = game.difficultyMode
localStorage.setItem("localSettings", JSON.stringify(localSettings)); //update local storage
});
// function playSound(id) {

View File

@@ -439,7 +439,7 @@ const mech = {
},
defaultFPSCycle: 0, //tracks when to return to normal fps
damage(dmg) {
if (b.isModMonogamy && b.inventory[0] === b.activeGun) {
if (b.isModEntanglement && b.inventory[0] === b.activeGun) {
for (let i = 0, len = b.inventory.length; i < len; i++) {
dmg *= 0.93
}
@@ -735,16 +735,16 @@ const mech = {
}
},
holding() {
// if (mech.holdingTarget) {
mech.fieldMeter -= mech.fieldRegen;
if (mech.fieldMeter < 0) mech.fieldMeter = 0;
Matter.Body.setPosition(mech.holdingTarget, {
x: mech.pos.x + 70 * Math.cos(mech.angle),
y: mech.pos.y + 70 * Math.sin(mech.angle)
});
Matter.Body.setVelocity(mech.holdingTarget, player.velocity);
Matter.Body.rotate(mech.holdingTarget, 0.01 / mech.holdingTarget.mass); //gently spin the block
// }
if (mech.holdingTarget) {
mech.fieldMeter -= mech.fieldRegen;
if (mech.fieldMeter < 0) mech.fieldMeter = 0;
Matter.Body.setPosition(mech.holdingTarget, {
x: mech.pos.x + 70 * Math.cos(mech.angle),
y: mech.pos.y + 70 * Math.sin(mech.angle)
});
Matter.Body.setVelocity(mech.holdingTarget, player.velocity);
Matter.Body.rotate(mech.holdingTarget, 0.01 / mech.holdingTarget.mass); //gently spin the block
}
},
throw () {
if ((keys[32] || game.mouseDownRight)) {