laser and pulse combined, heal effect difficulty balance, custom mode bug fix

This commit is contained in:
landgreen
2019-12-30 06:44:20 -08:00
parent 624553186c
commit 45b87e8c72
7 changed files with 502 additions and 211 deletions

View File

@@ -1679,21 +1679,16 @@ const b = {
},
{
name: "laser", //14
description: "emit a beam of collimated coherent <strong>light</strong><br>drains <strong class='color-f'>energy</strong> instead of ammunition",
description: "drain <strong class='color-f'>energy</strong> to emit a beam of coherent <strong>light</strong><br>when crouched, initiate a fusion <strong class='color-e'>explosion</strong>",
ammo: 0,
ammoPack: Infinity,
have: false,
isStarterGun: true,
fire() {
const FIELD_DRAIN = 0.002 //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 {
mech.fieldMeter -= mech.fieldRegen + FIELD_DRAIN
if (mech.crouch) { //crouch fire mode
//calculate laser collision
let best;
const color = "#f00";
const range = 3000;
let range = 3000
const path = [{
x: mech.pos.x + 20 * Math.cos(mech.angle),
y: mech.pos.y + 20 * Math.sin(mech.angle)
@@ -1743,54 +1738,153 @@ const b = {
}
}
};
const checkForCollisions = function () {
best = {
x: null,
y: null,
dist2: Infinity,
who: null,
v1: null,
v2: null
};
vertexCollision(path[path.length - 2], path[path.length - 1], mob);
vertexCollision(path[path.length - 2], path[path.length - 1], map);
vertexCollision(path[path.length - 2], path[path.length - 1], body);
};
const laserHitMob = function (dmg) {
if (best.who.alive) {
dmg *= b.dmgScale * damage;
best.who.damage(dmg);
best.who.locatePlayer();
//draw mob damage circle
ctx.fillStyle = color;
ctx.beginPath();
ctx.arc(path[path.length - 1].x, path[path.length - 1].y, Math.sqrt(dmg) * 100, 0, 2 * Math.PI);
ctx.fill();
}
};
const reflection = function () {
// https://math.stackexchange.com/questions/13261/how-to-get-a-reflection-vector
const n = Vector.perp(Vector.normalise(Vector.sub(best.v1, best.v2)));
const d = Vector.sub(path[path.length - 1], path[path.length - 2]);
const nn = Vector.mult(n, 2 * Vector.dot(d, n));
const r = Vector.normalise(Vector.sub(d, nn));
path[path.length] = Vector.add(Vector.mult(r, range), path[path.length - 1]);
//check for collisions
best = {
x: null,
y: null,
dist2: Infinity,
who: null,
v1: null,
v2: null
};
//beam before reflection
checkForCollisions();
if (best.dist2 != Infinity) {
//if hitting something
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
};
laserHitMob(1);
}
//1st reflection beam
reflection();
//ugly bug fix: this stops the reflection on a bug where the beam gets trapped inside a body
let who = best.who;
//use energy to explode
const energy = mech.fieldMeter * 0.25
mech.fieldMeter -= energy
if (best.who) b.explosion(path[1], 1200 * energy)
mech.fireCDcycle = mech.cycle + Math.floor(65 * b.modFireRate); // cool down
//draw laser beam
ctx.beginPath();
ctx.moveTo(path[0].x, path[0].y);
ctx.lineTo(path[1].x, path[1].y);
ctx.strokeStyle = "rgba(255,0,0,0.13)"
ctx.lineWidth = 60 * energy / 0.2
ctx.stroke();
ctx.strokeStyle = "rgba(255,0,0,0.2)"
ctx.lineWidth = 18
ctx.stroke();
ctx.strokeStyle = "#f00";
ctx.lineWidth = 4
ctx.stroke();
//draw little dots along the laser path
const sub = Vector.sub(path[1], path[0])
const mag = Vector.magnitude(sub)
for (let i = 0, len = Math.floor(mag * 0.03 * energy / 0.2); i < len; i++) {
const dist = Math.random()
game.drawList.push({
x: path[0].x + sub.x * dist + 13 * (Math.random() - 0.5),
y: path[0].y + sub.y * dist + 13 * (Math.random() - 0.5),
radius: 1 + 4 * Math.random(),
color: "rgba(255,0,0,0.5)",
time: Math.floor(2 + 33 * Math.random() * Math.random())
});
}
} else { //normal fire mode
const FIELD_DRAIN = 0.002 //laser drains energy as well as bullets
const damage = 0.045
if (mech.fieldMeter < FIELD_DRAIN) {
mech.fireCDcycle = mech.cycle + 100; // cool down if out of energy
} else {
mech.fieldMeter -= mech.fieldRegen + FIELD_DRAIN
let best;
const color = "#f00";
const range = 3000;
const path = [{
x: mech.pos.x + 20 * Math.cos(mech.angle),
y: mech.pos.y + 20 * Math.sin(mech.angle)
},
{
x: mech.pos.x + range * Math.cos(mech.angle),
y: mech.pos.y + range * Math.sin(mech.angle)
}
];
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 && (!domain[i].mob || domain[i].alive)) {
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 && (!domain[i].mob || domain[i].alive)) {
best = {
x: results.x,
y: results.y,
dist2: dist2,
who: domain[i],
v1: vertices[0],
v2: vertices[len]
};
}
}
}
};
const checkForCollisions = function () {
best = {
x: null,
y: null,
dist2: Infinity,
who: null,
v1: null,
v2: null
};
vertexCollision(path[path.length - 2], path[path.length - 1], mob);
vertexCollision(path[path.length - 2], path[path.length - 1], map);
vertexCollision(path[path.length - 2], path[path.length - 1], body);
};
const laserHitMob = function (dmg) {
if (best.who.alive) {
dmg *= b.dmgScale * damage;
best.who.damage(dmg);
best.who.locatePlayer();
//draw mob damage circle
ctx.fillStyle = color;
ctx.beginPath();
ctx.arc(path[path.length - 1].x, path[path.length - 1].y, Math.sqrt(dmg) * 100, 0, 2 * Math.PI);
ctx.fill();
}
};
const reflection = function () {
// https://math.stackexchange.com/questions/13261/how-to-get-a-reflection-vector
const n = Vector.perp(Vector.normalise(Vector.sub(best.v1, best.v2)));
const d = Vector.sub(path[path.length - 1], path[path.length - 2]);
const nn = Vector.mult(n, 2 * Vector.dot(d, n));
const r = Vector.normalise(Vector.sub(d, nn));
path[path.length] = Vector.add(Vector.mult(r, range), path[path.length - 1]);
};
//beam before reflection
checkForCollisions();
if (best.dist2 != Infinity) {
//if hitting something
@@ -1798,22 +1892,24 @@ const b = {
x: best.x,
y: best.y
};
laserHitMob(0.8);
laserHitMob(1);
//2nd reflection beam
//1st reflection beam
reflection();
//ugly bug fix: this stops the reflection on a bug where the beam gets trapped inside a body
if (who !== best.who) {
reflection();
checkForCollisions();
if (best.dist2 != Infinity) {
//if hitting something
path[path.length - 1] = {
x: best.x,
y: best.y
};
laserHitMob(0.63);
let who = best.who;
checkForCollisions();
if (best.dist2 != Infinity) {
//if hitting something
path[path.length - 1] = {
x: best.x,
y: best.y
};
laserHitMob(0.8);
//2nd reflection beam
//ugly bug fix: this stops the reflection on a bug where the beam gets trapped inside a body
if (who !== best.who) {
reflection();
checkForCollisions();
if (best.dist2 != Infinity) {
@@ -1822,147 +1918,330 @@ const b = {
x: best.x,
y: best.y
};
laserHitMob(0.5);
laserHitMob(0.63);
reflection();
checkForCollisions();
if (best.dist2 != Infinity) {
//if hitting something
path[path.length - 1] = {
x: best.x,
y: best.y
};
laserHitMob(0.5);
}
}
}
}
}
}
ctx.fillStyle = color;
ctx.strokeStyle = color;
ctx.lineWidth = 2;
ctx.lineDashOffset = 300 * Math.random()
// ctx.setLineDash([200 * Math.random(), 250 * Math.random()]);
ctx.fillStyle = color;
ctx.strokeStyle = color;
ctx.lineWidth = 2;
ctx.lineDashOffset = 300 * Math.random()
// ctx.setLineDash([200 * Math.random(), 250 * Math.random()]);
ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]);
for (let i = 1, len = path.length; i < len; ++i) {
ctx.beginPath();
ctx.moveTo(path[i - 1].x, path[i - 1].y);
ctx.lineTo(path[i].x, path[i].y);
ctx.stroke();
ctx.globalAlpha *= 0.65; //reflections are less intense
// ctx.globalAlpha -= 0.1; //reflections are less intense
ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]);
for (let i = 1, len = path.length; i < len; ++i) {
ctx.beginPath();
ctx.moveTo(path[i - 1].x, path[i - 1].y);
ctx.lineTo(path[i].x, path[i].y);
ctx.stroke();
ctx.globalAlpha *= 0.65; //reflections are less intense
// ctx.globalAlpha -= 0.1; //reflections are less intense
}
ctx.setLineDash([0, 0]);
ctx.globalAlpha = 1;
}
ctx.setLineDash([0, 0]);
ctx.globalAlpha = 1;
}
}
},
{
name: "pulse", //15
description: "power a <strong>laser</strong> that initiates a fusion <strong class='color-e'>explosion</strong><br>each pulse drains 25% of your current <strong class='color-f'>energy</strong>",
ammo: 0,
ammoPack: Infinity,
have: false,
isStarterGun: true,
fire() {
//calculate laser collision
let best;
let range = 3000
const path = [{
x: mech.pos.x + 20 * Math.cos(mech.angle),
y: mech.pos.y + 20 * Math.sin(mech.angle)
},
{
x: mech.pos.x + range * Math.cos(mech.angle),
y: mech.pos.y + range * Math.sin(mech.angle)
}
];
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 && (!domain[i].mob || domain[i].alive)) {
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 && (!domain[i].mob || domain[i].alive)) {
best = {
x: results.x,
y: results.y,
dist2: dist2,
who: domain[i],
v1: vertices[0],
v2: vertices[len]
};
}
}
}
};
// {
// name: "laser", //14
// description: "emit a beam of collimated coherent <strong>light</strong><br>drains <strong class='color-f'>energy</strong> instead of ammunition",
// ammo: 0,
// ammoPack: Infinity,
// have: false,
// isStarterGun: true,
// fire() {
// const FIELD_DRAIN = 0.002 //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 {
// mech.fieldMeter -= mech.fieldRegen + FIELD_DRAIN
// let best;
// const color = "#f00";
// const range = 3000;
// const path = [{
// x: mech.pos.x + 20 * Math.cos(mech.angle),
// y: mech.pos.y + 20 * Math.sin(mech.angle)
// },
// {
// x: mech.pos.x + range * Math.cos(mech.angle),
// y: mech.pos.y + range * Math.sin(mech.angle)
// }
// ];
// 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 && (!domain[i].mob || domain[i].alive)) {
// 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 && (!domain[i].mob || domain[i].alive)) {
// best = {
// x: results.x,
// y: results.y,
// dist2: dist2,
// who: domain[i],
// v1: vertices[0],
// v2: vertices[len]
// };
// }
// }
// }
// };
// const checkForCollisions = function () {
// best = {
// x: null,
// y: null,
// dist2: Infinity,
// who: null,
// v1: null,
// v2: null
// };
// vertexCollision(path[path.length - 2], path[path.length - 1], mob);
// vertexCollision(path[path.length - 2], path[path.length - 1], map);
// vertexCollision(path[path.length - 2], path[path.length - 1], body);
// };
// const laserHitMob = function (dmg) {
// if (best.who.alive) {
// dmg *= b.dmgScale * damage;
// best.who.damage(dmg);
// best.who.locatePlayer();
// //draw mob damage circle
// ctx.fillStyle = color;
// ctx.beginPath();
// ctx.arc(path[path.length - 1].x, path[path.length - 1].y, Math.sqrt(dmg) * 100, 0, 2 * Math.PI);
// ctx.fill();
// }
// };
//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
};
}
// const reflection = function () {
// // https://math.stackexchange.com/questions/13261/how-to-get-a-reflection-vector
// const n = Vector.perp(Vector.normalise(Vector.sub(best.v1, best.v2)));
// const d = Vector.sub(path[path.length - 1], path[path.length - 2]);
// const nn = Vector.mult(n, 2 * Vector.dot(d, n));
// const r = Vector.normalise(Vector.sub(d, nn));
// path[path.length] = Vector.add(Vector.mult(r, range), path[path.length - 1]);
// };
// //beam before reflection
// checkForCollisions();
// if (best.dist2 != Infinity) {
// //if hitting something
// path[path.length - 1] = {
// x: best.x,
// y: best.y
// };
// laserHitMob(1);
//use energy to explode
const energy = mech.fieldMeter * 0.25
mech.fieldMeter -= energy
if (best.who) b.explosion(path[1], 1300 * energy)
mech.fireCDcycle = mech.cycle + Math.floor(60 * b.modFireRate); // cool down
// //1st reflection beam
// reflection();
// //ugly bug fix: this stops the reflection on a bug where the beam gets trapped inside a body
// let who = best.who;
// checkForCollisions();
// if (best.dist2 != Infinity) {
// //if hitting something
// path[path.length - 1] = {
// x: best.x,
// y: best.y
// };
// laserHitMob(0.8);
//draw laser beam
ctx.beginPath();
ctx.moveTo(path[0].x, path[0].y);
ctx.lineTo(path[1].x, path[1].y);
ctx.strokeStyle = "rgba(255,0,0,0.13)"
ctx.lineWidth = 60 * energy / 0.2
ctx.stroke();
ctx.strokeStyle = "rgba(255,0,0,0.2)"
ctx.lineWidth = 18
ctx.stroke();
ctx.strokeStyle = "#f00";
ctx.lineWidth = 4
ctx.stroke();
// //2nd reflection beam
// //ugly bug fix: this stops the reflection on a bug where the beam gets trapped inside a body
// if (who !== best.who) {
// reflection();
// checkForCollisions();
// if (best.dist2 != Infinity) {
// //if hitting something
// path[path.length - 1] = {
// x: best.x,
// y: best.y
// };
// laserHitMob(0.63);
//draw little dots along the laser path
const sub = Vector.sub(path[1], path[0])
const mag = Vector.magnitude(sub)
for (let i = 0, len = Math.floor(mag * 0.03 * energy / 0.2); i < len; i++) {
const dist = Math.random()
game.drawList.push({
x: path[0].x + sub.x * dist + 13 * (Math.random() - 0.5),
y: path[0].y + sub.y * dist + 13 * (Math.random() - 0.5),
radius: 1 + 4 * Math.random(),
color: "rgba(255,0,0,0.5)",
time: Math.floor(2 + 33 * Math.random() * Math.random())
});
}
}
},
// reflection();
// checkForCollisions();
// if (best.dist2 != Infinity) {
// //if hitting something
// path[path.length - 1] = {
// x: best.x,
// y: best.y
// };
// laserHitMob(0.5);
// }
// }
// }
// }
// }
// ctx.fillStyle = color;
// ctx.strokeStyle = color;
// ctx.lineWidth = 2;
// ctx.lineDashOffset = 300 * Math.random()
// // ctx.setLineDash([200 * Math.random(), 250 * Math.random()]);
// ctx.setLineDash([50 + 120 * Math.random(), 50 * Math.random()]);
// for (let i = 1, len = path.length; i < len; ++i) {
// ctx.beginPath();
// ctx.moveTo(path[i - 1].x, path[i - 1].y);
// ctx.lineTo(path[i].x, path[i].y);
// ctx.stroke();
// ctx.globalAlpha *= 0.65; //reflections are less intense
// // ctx.globalAlpha -= 0.1; //reflections are less intense
// }
// ctx.setLineDash([0, 0]);
// ctx.globalAlpha = 1;
// }
// }
// },
// {
// name: "pulse", //15
// description: "power a <strong>laser</strong> that initiates a fusion <strong class='color-e'>explosion</strong><br>each pulse drains 25% of your current <strong class='color-f'>energy</strong>",
// ammo: 0,
// ammoPack: Infinity,
// have: false,
// isStarterGun: true,
// fire() {
// //calculate laser collision
// let best;
// let range = 3000
// const path = [{
// x: mech.pos.x + 20 * Math.cos(mech.angle),
// y: mech.pos.y + 20 * Math.sin(mech.angle)
// },
// {
// x: mech.pos.x + range * Math.cos(mech.angle),
// y: mech.pos.y + range * Math.sin(mech.angle)
// }
// ];
// 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 && (!domain[i].mob || domain[i].alive)) {
// 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 && (!domain[i].mob || domain[i].alive)) {
// 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
// };
// }
// //use energy to explode
// const energy = mech.fieldMeter * 0.25
// mech.fieldMeter -= energy
// if (best.who) b.explosion(path[1], 1300 * energy)
// mech.fireCDcycle = mech.cycle + Math.floor(60 * b.modFireRate); // cool down
// //draw laser beam
// ctx.beginPath();
// ctx.moveTo(path[0].x, path[0].y);
// ctx.lineTo(path[1].x, path[1].y);
// ctx.strokeStyle = "rgba(255,0,0,0.13)"
// ctx.lineWidth = 60 * energy / 0.2
// ctx.stroke();
// ctx.strokeStyle = "rgba(255,0,0,0.2)"
// ctx.lineWidth = 18
// ctx.stroke();
// ctx.strokeStyle = "#f00";
// ctx.lineWidth = 4
// ctx.stroke();
// //draw little dots along the laser path
// const sub = Vector.sub(path[1], path[0])
// const mag = Vector.magnitude(sub)
// for (let i = 0, len = Math.floor(mag * 0.03 * energy / 0.2); i < len; i++) {
// const dist = Math.random()
// game.drawList.push({
// x: path[0].x + sub.x * dist + 13 * (Math.random() - 0.5),
// y: path[0].y + sub.y * dist + 13 * (Math.random() - 0.5),
// radius: 1 + 4 * Math.random(),
// color: "rgba(255,0,0,0.5)",
// time: Math.floor(2 + 33 * Math.random() * Math.random())
// });
// }
// }
// },
{
name: "foam", //16
description: "spray bubbly foam that <strong>sticks</strong> to enemies<br>does <strong class='color-d'>damage</strong> over time and <strong>slows</strong> movement",