From 23f953f699f1c43558c291d27b3b8a8e768a71e0 Mon Sep 17 00:00:00 2001 From: landgreen Date: Thu, 5 Dec 2019 05:31:06 -0800 Subject: [PATCH] custom run fixes. mod balance --- index.html | 4 +- js/bullets.js | 244 ++++++++++++++++++++++++++------------------------ js/engine.js | 5 +- js/index.js | 25 +++--- js/level.js | 2 +- js/mobs.js | 45 +++++----- 6 files changed, 170 insertions(+), 155 deletions(-) diff --git a/index.html b/index.html index bd41ecc..8f8db42 100644 --- a/index.html +++ b/index.html @@ -88,9 +88,9 @@ -->
- + - builds + custom diff --git a/js/bullets.js b/js/bullets.js index e6f643c..a504b5b 100644 --- a/js/bullets.js +++ b/js/bullets.js @@ -67,7 +67,7 @@ const b = { }, { name: "auto-loading heuristics", - description: "delay between your shots is 15% shorter", + description: "your delay after firing is 15% shorter", have: false, //1 effect: () => { //good for guns with extra ammo: needles, M80, rapid fire, flak, super balls b.modFireRate = 0.85 @@ -123,11 +123,11 @@ const b = { } }, { - name: "field siphon", + name: "energy transfer", description: "gain energy proportional to damage done", have: false, //8 effect: () => { //good with laser, and all fields - b.modEnergySiphon = 0.15; + b.modEnergySiphon = 0.2; } }, { @@ -135,7 +135,7 @@ const b = { description: "heal proportional to damage done", have: false, //9 effect: () => { //good with guns that overkill: one shot, grenade - b.modHealthDrain = 0.01; + b.modHealthDrain = 0.015; } }, { @@ -192,7 +192,7 @@ const b = { }, { name: "fracture analysis", - description: "6x physical damage to unaware enemies
enemies aware of you have a health bar", + description: "5x physical damage to unaware enemies
unaware enemies don't have a health bar", have: false, //16 effect: () => { // good with high damage guns that strike from a distance: rail gun, drones, flechettes, spores, grenade, vacuum bomb b.modIsCrit = true; @@ -223,7 +223,7 @@ const b = { } }, { - name: "monogamy", + name: "entanglement", description: "using your first gun reduces damage taken
scales by 7% for each gun in your inventory", have: false, //20 effect: () => { // good with long term planning @@ -251,7 +251,7 @@ const b = { } } else { if (!b.guns[gun].have) b.inventory.push(gun); - b.activeGun = gun; + if (b.activeGun === null) b.activeGun = gun //if no active gun switch to new gun b.guns[gun].have = true; b.guns[gun].ammo = b.guns[gun].ammoPack * ammoPacks; } @@ -705,20 +705,20 @@ const b = { }, { name: "rail gun", //1 - description: "magnetically launch a dense rod
hold left mouse to charge and repel enemies", + description: "electro-magnetically launch a dense rod
hold left mouse to charge release to fire", //and repel enemies ammo: 0, - ammoPack: 11, + ammoPack: 7, have: false, isStarterGun: false, fire() { const me = bullet.length; - bullet[me] = Bodies.rectangle(0, 0, 0.012 * b.modBulletSize, 0.0022 * b.modBulletSize, { - density: 0.002, //0.001 is normal + bullet[me] = Bodies.rectangle(0, 0, 0.012 * b.modBulletSize, 0.0025 * b.modBulletSize, { + density: 0.01, //0.001 is normal //frictionAir: 0.01, //restitution: 0, // angle: 0, // friction: 0.5, frictionAir: 0, - dmg: 3 + b.modExtraDmg, //damage done in addition to the damage from momentum + dmg: b.modExtraDmg, //damage done in addition to the damage from momentum classType: "bullet", collisionFilter: { category: 0x000000, @@ -735,7 +735,7 @@ const b = { bullet[me].charge = 0; bullet[me].do = function () { if (this.isCharging) { - if ((!game.mouseDown && this.charge > 0.5)) { //fire on mouse release + if ((!game.mouseDown && this.charge > 0.4)) { //fire on mouse release this.isCharging = false mech.fireCDcycle = mech.cycle + 2; // set fire cool down Matter.Body.scale(this, 8000, 8000) // show the bullet by scaling it up (don't judge me... I know this is a bad way to do it) @@ -746,7 +746,7 @@ const b = { y: mech.pos.y }) Matter.Body.setAngle(this, mech.angle) - const speed = 85 + const speed = 90 Matter.Body.setVelocity(this, { x: mech.Vx / 2 + speed * this.charge * Math.cos(mech.angle), y: mech.Vy / 2 + speed * this.charge * Math.sin(mech.angle) @@ -758,24 +758,36 @@ const b = { player.force.y -= KNOCK * Math.sin(mech.angle) * 0.35 //reduce knock back in vertical direction to stop super jumps //push away blocks when firing - const RANGE = 450 * this.charge + let range = 450 * this.charge for (let i = 0, len = body.length; i < len; ++i) { const SUB = Matter.Vector.sub(body[i].position, mech.pos) const DISTANCE = Matter.Vector.magnitude(SUB) - if (DISTANCE < RANGE) { - const DEPTH = Math.max(RANGE - DISTANCE, 100) + if (DISTANCE < range) { + const DEPTH = Math.max(range - DISTANCE, 100) const FORCE = Matter.Vector.mult(Matter.Vector.normalise(SUB), 0.005 * Math.sqrt(DEPTH) * Math.sqrt(body[i].mass)) - body[i].force.x += FORCE.x + body[i].force.x += FORCE.x; body[i].force.y += FORCE.y - body[i].mass * (game.g * 1.5); //kick up a bit to give them some arc } } + for (let i = 0, len = mob.length; i < len; ++i) { + const SUB = Matter.Vector.sub(mob[i].position, mech.pos) + const DISTANCE = Matter.Vector.magnitude(SUB) + + if (DISTANCE < range) { + const DEPTH = Math.max(range - DISTANCE, 100) + const FORCE = Matter.Vector.mult(Matter.Vector.normalise(SUB), 0.005 * Math.sqrt(DEPTH) * Math.sqrt(mob[i].mass)) + mob[i].force.x += 1.5 * FORCE.x; + mob[i].force.y += 1.5 * FORCE.y; + } + } //push mobs around player when firing + // range = 600 * this.charge // for (let i = 0, len = mob.length; i < len; ++i) { // const SUB = Matter.Vector.sub(mob[i].position, mech.pos) // const DISTANCE = Matter.Vector.magnitude(SUB) - // if (DISTANCE < RANGE) { - // const DEPTH = RANGE - DISTANCE + // if (DISTANCE < range) { + // const DEPTH = range - DISTANCE // const FORCE = Matter.Vector.mult(Matter.Vector.normalise(SUB), 0.00000001 * DEPTH * DEPTH * DEPTH * Math.sqrt(mob[i].mass)) // mob[i].force.x += FORCE.x // mob[i].force.y += FORCE.y @@ -786,107 +798,109 @@ const b = { if (mech.crouch) { this.charge = this.charge * 0.97 + 0.03 // this.charge converges to 1 } else { - this.charge = this.charge * 0.98 + 0.02 // this.charge converges to 1 + this.charge = this.charge * 0.987 + 0.013 // this.charge converges to 1 } //gently push away mobs while charging - const RANGE = 270 * this.charge - for (let i = 0, len = mob.length; i < len; ++i) { - const SUB = Matter.Vector.sub(mob[i].position, mech.pos) - const DISTANCE = Matter.Vector.magnitude(SUB) - // if (DISTANCE < RANGE) { - // Matter.Body.setVelocity(mob[i], Matter.Vector.rotate(mob[i].velocity, 0.1)) - // } - // const DRAIN = 0.0002 //&& mech.fieldMeter > DRAIN - if (DISTANCE < RANGE) { - // mech.fieldMeter -= DRAIN + mech.fieldRegen; - const DEPTH = RANGE - DISTANCE - const FORCE = Matter.Vector.mult(Matter.Vector.normalise(SUB), 0.000000001 * DEPTH * DEPTH * DEPTH * Math.sqrt(mob[i].mass)) - mob[i].force.x += FORCE.x - mob[i].force.y += FORCE.y - } - } - - // //draw laser targeting - // let best; - // let range = 3000 - // const dir = mech.angle - // const path = [{ - // x: mech.pos.x + 20 * Math.cos(dir), - // y: mech.pos.y + 20 * Math.sin(dir) - // }, - // { - // x: mech.pos.x + range * Math.cos(dir), - // y: mech.pos.y + range * Math.sin(dir) + // const RANGE = 270 * this.charge + // for (let i = 0, len = mob.length; i < len; ++i) { + // const SUB = Matter.Vector.sub(mob[i].position, mech.pos) + // const DISTANCE = Matter.Vector.magnitude(SUB) + // // if (DISTANCE < RANGE) { + // // Matter.Body.setVelocity(mob[i], Matter.Vector.rotate(mob[i].velocity, 0.1)) + // // } + // // const DRAIN = 0.0002 //&& mech.fieldMeter > DRAIN + // if (DISTANCE < RANGE) { + // // mech.fieldMeter -= DRAIN + mech.fieldRegen; + // const DEPTH = RANGE - DISTANCE + // const FORCE = Matter.Vector.mult(Matter.Vector.normalise(SUB), 0.000000001 * DEPTH * DEPTH * DEPTH * Math.sqrt(mob[i].mass)) + // mob[i].force.x += FORCE.x + // mob[i].force.y += FORCE.y // } - // ]; - // const vertexCollision = function (v1, v1End, domain) { - // for (let i = 0; i < domain.length; ++i) { - // let vertices = domain[i].vertices; - // const len = vertices.length - 1; - // for (let j = 0; j < len; j++) { - // results = game.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); - // if (results.onLine1 && results.onLine2) { - // const dx = v1.x - results.x; - // const dy = v1.y - results.y; - // const dist2 = dx * dx + dy * dy; - // if (dist2 < best.dist2) { - // best = { - // x: results.x, - // y: results.y, - // dist2: dist2, - // who: domain[i], - // v1: vertices[j], - // v2: vertices[j + 1] - // }; - // } - // } - // } - // results = game.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); - // if (results.onLine1 && results.onLine2) { - // const dx = v1.x - results.x; - // const dy = v1.y - results.y; - // const dist2 = dx * dx + dy * dy; - // if (dist2 < best.dist2) { - // best = { - // x: results.x, - // y: results.y, - // dist2: dist2, - // who: domain[i], - // v1: vertices[0], - // v2: vertices[len] - // }; - // } - // } - // } - // }; - - // //check for collisions - // best = { - // x: null, - // y: null, - // dist2: Infinity, - // who: null, - // v1: null, - // v2: null - // }; - // vertexCollision(path[0], path[1], mob); - // vertexCollision(path[0], path[1], map); - // vertexCollision(path[0], path[1], body); - // if (best.dist2 != Infinity) { //if hitting something - // path[path.length - 1] = { - // x: best.x, - // y: best.y - // }; // } - // //draw laser beam - // ctx.beginPath(); - // ctx.moveTo(path[0].x, path[0].y); - // ctx.lineTo(path[1].x, path[1].y); - // ctx.strokeStyle = `rgba(50,0,100,0.1)`; - // ctx.lineWidth = this.charge * 3 - // ctx.stroke(); + //draw laser targeting + let best; + let range = 3000 + const dir = mech.angle + const path = [{ + x: mech.pos.x + 20 * Math.cos(dir), + y: mech.pos.y + 20 * Math.sin(dir) + }, + { + x: mech.pos.x + range * Math.cos(dir), + y: mech.pos.y + range * Math.sin(dir) + } + ]; + const vertexCollision = function (v1, v1End, domain) { + for (let i = 0; i < domain.length; ++i) { + let vertices = domain[i].vertices; + const len = vertices.length - 1; + for (let j = 0; j < len; j++) { + results = game.checkLineIntersection(v1, v1End, vertices[j], vertices[j + 1]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) { + best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[j], + v2: vertices[j + 1] + }; + } + } + } + results = game.checkLineIntersection(v1, v1End, vertices[0], vertices[len]); + if (results.onLine1 && results.onLine2) { + const dx = v1.x - results.x; + const dy = v1.y - results.y; + const dist2 = dx * dx + dy * dy; + if (dist2 < best.dist2) { + best = { + x: results.x, + y: results.y, + dist2: dist2, + who: domain[i], + v1: vertices[0], + v2: vertices[len] + }; + } + } + } + }; + + //check for collisions + best = { + x: null, + y: null, + dist2: Infinity, + who: null, + v1: null, + v2: null + }; + vertexCollision(path[0], path[1], mob); + vertexCollision(path[0], path[1], map); + vertexCollision(path[0], path[1], body); + if (best.dist2 != Infinity) { //if hitting something + path[path.length - 1] = { + x: best.x, + y: best.y + }; + } + + //draw laser beam + ctx.beginPath(); + ctx.moveTo(path[0].x, path[0].y); + ctx.lineTo(path[1].x, path[1].y); + ctx.strokeStyle = `rgba(100,0,180,0.7)`; + ctx.lineWidth = this.charge * 1 + ctx.setLineDash([10, 20]); + ctx.stroke(); + ctx.setLineDash([0, 0]); //draw magnetic field const X = mech.pos.x diff --git a/js/engine.js b/js/engine.js index e0651d0..511101a 100644 --- a/js/engine.js +++ b/js/engine.js @@ -179,7 +179,7 @@ function mobCollisionChecks(event) { if (obj.classType === "bullet" && obj.speed > obj.minDmgSpeed) { // const dmg = b.dmgScale * (obj.dmg + 0.15 * obj.mass * Matter.Vector.magnitude(Matter.Vector.sub(mob[k].velocity, obj.velocity))); let dmg = b.dmgScale * (obj.dmg + b.modExtraDmg + 0.15 * obj.mass * Matter.Vector.magnitude(Matter.Vector.sub(mob[k].velocity, obj.velocity))) - if (b.modIsCrit && !mob[k].seePlayer.recall) dmg *= 6 + if (b.modIsCrit && !mob[k].seePlayer.recall) dmg *= 5 mob[k].foundPlayer(); mob[k].damage(dmg); obj.onDmg(); //some bullets do actions when they hits things, like despawn @@ -187,7 +187,8 @@ function mobCollisionChecks(event) { //add dmg to draw queue x: pairs[i].activeContacts[0].vertex.x, y: pairs[i].activeContacts[0].vertex.y, - radius: Math.sqrt(dmg) * 40, + // radius: Math.sqrt(dmg) * 40, + radius: Math.log(2 * dmg + 1.1) * 40, color: game.playerDmgColor, time: game.drawTime }); diff --git a/js/index.js b/js/index.js index 2d4e5f3..d76063c 100644 --- a/js/index.js +++ b/js/index.js @@ -71,7 +71,7 @@ mod power ups ideas add a freeze give mobs more animal-like behaviors - like rainworld + like rain world give mobs something to do when they don't see player explore map eat power ups @@ -180,19 +180,16 @@ document.getElementById("build-button").addEventListener("click", () => { build.list = [] // let text = '

choose up to 5 powers

' let text = - `
-

choose up to 5 powers

+ `
+ + + start + +
-
- - - start - -
` +
+ Choose up to five power ups. Once you start, only health and ammo will drop, so pick carefully. +
` for (let i = 1, len = mech.fieldUpgrades.length; i < len; i++) { text += `
  ${mech.fieldUpgrades[i].name}
${mech.fieldUpgrades[i].description}
` } @@ -248,7 +245,7 @@ document.body.addEventListener("mousemove", (e) => { document.body.addEventListener("mouseup", (e) => { // game.buildingUp(e); //uncomment when building levels - game.mouseDown = false; + // game.mouseDown = false; // console.log(e) if (e.which === 3) { game.mouseDownRight = false; diff --git a/js/level.js b/js/level.js index 6ccc961..4d875c9 100644 --- a/js/level.js +++ b/js/level.js @@ -15,7 +15,7 @@ const level = { if (level.levelsCleared === 0) { // game.difficulty = 6; //for testing to simulate possible mobs spawns // level.startBuildRun(5) - // b.giveGuns(11) + // b.giveGuns(1) // mech.fieldUpgrades[2].effect(); // b.giveMod(13) // spawn.pickList = ["ghoster", "ghoster"] diff --git a/js/mobs.js b/js/mobs.js index 122c697..ce0eae2 100644 --- a/js/mobs.js +++ b/js/mobs.js @@ -29,20 +29,20 @@ const mobs = { ctx.stroke(); } }, - alert(range) { - range = range * range; - for (let i = 0; i < mob.length; i++) { - if (mob[i].distanceToPlayer2() < range) mob[i].locatePlayer(); - } - }, - startle(amount) { - for (let i = 0; i < mob.length; i++) { - if (!mob[i].seePlayer.yes) { - mob[i].force.x += amount * mob[i].mass * (Math.random() - 0.5); - mob[i].force.y += amount * mob[i].mass * (Math.random() - 0.5); - } - } - }, + // alert(range) { + // range = range * range; + // for (let i = 0; i < mob.length; i++) { + // if (mob[i].distanceToPlayer2() < range) mob[i].locatePlayer(); + // } + // }, + // startle(amount) { + // for (let i = 0; i < mob.length; i++) { + // if (!mob[i].seePlayer.yes) { + // mob[i].force.x += amount * mob[i].mass * (Math.random() - 0.5); + // mob[i].force.y += amount * mob[i].mass * (Math.random() - 0.5); + // } + // } + // }, //********************************************************************************************** //********************************************************************************************** spawn(xPos, yPos, sides, radius, color) { @@ -898,16 +898,19 @@ const mobs = { } }, damage(dmg) { + console.log(dmg, "before") + dmg /= Math.sqrt(this.mass) + console.log(dmg, "after") if (b.isModLowHealthDmg) dmg *= (3 / (2 + mech.health)) //up to 50% dmg at zero player health if (b.isModFarAwayDmg) dmg *= 1 + Math.sqrt(Math.max(1000, Math.min(3500, this.distanceToPlayer())) - 1000) * 0.01 //up to 50% dmg at max range of 3500 - this.health -= dmg / Math.sqrt(this.mass); - //this.fill = this.color + this.health + ')'; - if (this.health < 0.1) this.death(); - this.onDamage(this); //custom damage effects if (dmg !== Infinity) { - if (b.modEnergySiphon) mech.fieldMeter += dmg * b.modEnergySiphon - if (b.modHealthDrain) mech.addHealth(dmg * b.modHealthDrain) + if (b.modEnergySiphon) mech.fieldMeter += Math.min(this.health, dmg) * b.modEnergySiphon + if (b.modHealthDrain) mech.addHealth(Math.min(this.health, dmg) * b.modHealthDrain) } + this.health -= dmg + //this.fill = this.color + this.health + ')'; + if (this.health < 0.01) this.death(); + this.onDamage(this); //custom damage effects }, onDamage() { // a placeholder for custom effects on mob damage @@ -996,7 +999,7 @@ const mobs = { mob.splice(i, 1); } }); - mob[i].alertRange2 = Math.pow(mob[i].radius * 3 + 200, 2); + mob[i].alertRange2 = Math.pow(mob[i].radius * 3.5 + 550, 2); World.add(engine.world, mob[i]); //add to world } }; \ No newline at end of file