diff --git a/js/bullets.js b/js/bullets.js
index d88c094..c0dbb1b 100644
--- a/js/bullets.js
+++ b/js/bullets.js
@@ -1454,5 +1454,140 @@ const b = {
b.drawOneBullet(bullet[me].vertices);
}
},
+ {
+ name: "short range laser", //15
+ description: "fire a beam of coherent light
reflects off walls at 75% intensity
uses energy instead of ammunition",
+ ammo: 0,
+ ammoPack: Infinity,
+ have: false,
+ isStarterGun: true,
+ fire() {
+ //laser drains energy as well as bullets
+ const FIELD_DRAIN = 0.001
+ const damage = 0.3
+ 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 = "#f06";
+ const range = 150 + 200 * Math.random() //+ 100 * Math.sin(mech.cycle * 0.3);
+ const dir = mech.angle // + 0.04 * (Math.random() - 0.5)
+ 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 && (!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();
+ }
+ };
+ checkforCollisions();
+ if (best.dist2 != Infinity) {
+ //if hitting something
+ path[path.length - 1] = {
+ x: best.x,
+ y: best.y
+ };
+ laserHitMob(1);
+ }
+ ctx.strokeStyle = color;
+ ctx.lineWidth = 1
+ ctx.beginPath();
+ ctx.moveTo(path[0].x, path[0].y);
+ ctx.lineTo(path[1].x, path[1].y);
+ ctx.stroke();
+ ctx.strokeStyle = "rgba(255,0,60,0.1)"
+ ctx.lineWidth = 10
+ ctx.beginPath();
+ ctx.moveTo(path[0].x, path[0].y);
+ ctx.lineTo(path[1].x, path[1].y);
+ ctx.stroke();
+ }
+ }
+ },
+ // {
+ // name: "melee", //15
+ // description: "rapidly fire a stream of short range bullets",
+ // ammo: 0,
+ // ammoPack: 205,
+ // have: false,
+ // isStarterGun: true,
+ // fire() {
+ // const me = bullet.length;
+ // const dir = mech.angle + (Math.random() - 0.5) * ((mech.crouch) ? 0.1 : 0.7);
+ // bullet[me] = Bodies.rectangle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 12 * b.modBulletSize, 12 * b.modBulletSize, b.fireAttributes(dir));
+ // b.fireProps(mech.crouch ? 6 : 2, mech.crouch ? 30 : 20, dir, me); //cd , speed
+ // bullet[me].endCycle = game.cycle + Math.floor(18 * b.modBulletsLastLonger);
+ // bullet[me].do = function () {
+
+ // };
+ // }
+ // },
]
};
\ No newline at end of file
diff --git a/js/level.js b/js/level.js
index 1108a94..e45a330 100644
--- a/js/level.js
+++ b/js/level.js
@@ -13,7 +13,7 @@ const level = {
start() {
if (level.onLevel === 0) {
// game.difficulty = 6; //for testing to simulate possible mobs spawns
- // b.giveGuns(6)
+ b.giveGuns(15)
// mech.fieldUpgrades[6].effect();
// b.giveMod(13)
// spawn.pickList = ["ghoster", "ghoster"]