From bdbae2a2242a297d5a81f20e55b249f89992c197 Mon Sep 17 00:00:00 2001 From: landgreen Date: Tue, 14 Jan 2020 05:50:52 -0800 Subject: [PATCH] field damamge graphics --- js/bullets.js | 3 ++- js/level.js | 4 ++-- js/player.js | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/js/bullets.js b/js/bullets.js index 683d666..37006de 100644 --- a/js/bullets.js +++ b/js/bullets.js @@ -218,7 +218,7 @@ const b = { maxCount: 4, count: 0, effect() { - b.modBlockDmg += 0.7 + b.modBlockDmg += 0.7 //if you change this value also update the for loop in the electricity graphics in mech.pushMass } }, { @@ -722,6 +722,7 @@ const b = { bullet[bIndex] = Bodies.rectangle(where.x, where.y, 45 * b.modBulletSize, 16 * b.modBulletSize, { angle: angle, friction: 1, + frictionStatic: 1, frictionAir: 0, restitution: 0, dmg: 0, //damage done in addition to the damage from momentum diff --git a/js/level.js b/js/level.js index acff22e..7bfc163 100644 --- a/js/level.js +++ b/js/level.js @@ -14,9 +14,9 @@ const level = { start() { if (level.levelsCleared === 0) { // game.difficulty = 6; //for testing to simulate possible mobs spawns - // b.giveGuns(9) + // b.giveGuns(10) // mech.setField(3) - // b.giveMod(3); + // b.giveMod(13); level.intro(); //starting level // level.testingMap(); diff --git a/js/player.js b/js/player.js index 83052b0..970954a 100644 --- a/js/player.js +++ b/js/player.js @@ -901,11 +901,27 @@ const mech = { mech.drawHold(who); mech.fieldCDcycle = mech.cycle + 10; mech.holdingTarget = null + const unit = Vector.normalise(Vector.sub(player.position, who.position)) if (b.modBlockDmg) { who.damage(b.modBlockDmg) + //draw electricity + const step = mech.grabRange / 5 + ctx.beginPath(); + for (let i = 0, len = 2 * b.modBlockDmg / 0.7; i < len; i++) { + let x = mech.pos.x - 20 * unit.x; + let y = mech.pos.y - 20 * unit.y; + ctx.moveTo(x, y); + for (let i = 0; i < 8; i++) { + x += step * (-unit.x + 1.5 * (Math.random() - 0.5)) + y += step * (-unit.y + 1.5 * (Math.random() - 0.5)) + ctx.lineTo(x, y); + } + } + ctx.lineWidth = 2.5; + ctx.strokeStyle = "#f0f"; + ctx.stroke(); } //knock backs - const unit = Vector.normalise(Vector.sub(player.position, who.position)) const massRoot = Math.sqrt(Math.min(12, Math.max(0.15, who.mass))); // masses above 12 can start to overcome the push back Matter.Body.setVelocity(who, { x: player.velocity.x - (15 * unit.x) / massRoot,