time stop field added, extra mech.cycle
This commit is contained in:
176
js/bullets.js
176
js/bullets.js
@@ -23,7 +23,7 @@ const b = {
|
|||||||
game.makeGunHUD();
|
game.makeGunHUD();
|
||||||
},
|
},
|
||||||
fireProps(cd, speed, dir, me) {
|
fireProps(cd, speed, dir, me) {
|
||||||
mech.fireCDcycle = game.cycle + cd; // cool down
|
mech.fireCDcycle = mech.cycle + cd; // cool down
|
||||||
Matter.Body.setVelocity(bullet[me], {
|
Matter.Body.setVelocity(bullet[me], {
|
||||||
x: mech.Vx / 2 + speed * Math.cos(dir),
|
x: mech.Vx / 2 + speed * Math.cos(dir),
|
||||||
y: mech.Vy / 2 + speed * Math.sin(dir)
|
y: mech.Vy / 2 + speed * Math.sin(dir)
|
||||||
@@ -191,7 +191,7 @@ const b = {
|
|||||||
// sub = Matter.Vector.sub(bullet[me].position, bullet[i].position);
|
// sub = Matter.Vector.sub(bullet[me].position, bullet[i].position);
|
||||||
// dist = Matter.Vector.magnitude(sub);
|
// dist = Matter.Vector.magnitude(sub);
|
||||||
// if (dist < bullet[me].explodeRad) {
|
// if (dist < bullet[me].explodeRad) {
|
||||||
// bullet[i].endCycle = game.cycle;
|
// bullet[i].endCycle = mech.cycle;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
@@ -247,11 +247,11 @@ const b = {
|
|||||||
ammoPack: Infinity,
|
ammoPack: Infinity,
|
||||||
have: false,
|
have: false,
|
||||||
fire() {
|
fire() {
|
||||||
// mech.fireCDcycle = game.cycle + 1
|
// mech.fireCDcycle = mech.cycle + 1
|
||||||
//laser drains energy as well as bullets
|
//laser drains energy as well as bullets
|
||||||
const FIELD_DRAIN = 0.003
|
const FIELD_DRAIN = 0.003
|
||||||
if (mech.fieldMeter < FIELD_DRAIN) {
|
if (mech.fieldMeter < FIELD_DRAIN) {
|
||||||
mech.fireCDcycle = game.cycle + 100; // cool down if out of energy
|
mech.fireCDcycle = mech.cycle + 100; // cool down if out of energy
|
||||||
} else {
|
} else {
|
||||||
mech.fieldMeter -= mech.fieldRegen + FIELD_DRAIN
|
mech.fieldMeter -= mech.fieldRegen + FIELD_DRAIN
|
||||||
let best;
|
let best;
|
||||||
@@ -406,11 +406,11 @@ const b = {
|
|||||||
// ammoPack: Infinity,
|
// ammoPack: Infinity,
|
||||||
// have: false,
|
// have: false,
|
||||||
// fire() {
|
// fire() {
|
||||||
// // mech.fireCDcycle = game.cycle + 1
|
// // mech.fireCDcycle = mech.cycle + 1
|
||||||
// //laser drains energy as well as bullets
|
// //laser drains energy as well as bullets
|
||||||
// const FIELD_DRAIN = 0.0001 //should be 0.001
|
// const FIELD_DRAIN = 0.0001 //should be 0.001
|
||||||
// if (mech.fieldMeter < FIELD_DRAIN) {
|
// if (mech.fieldMeter < FIELD_DRAIN) {
|
||||||
// mech.fireCDcycle = game.cycle + 100; // cool down if out of energy
|
// mech.fireCDcycle = mech.cycle + 100; // cool down if out of energy
|
||||||
// } else {
|
// } else {
|
||||||
// mech.fieldMeter -= mech.fieldRegen + FIELD_DRAIN
|
// mech.fieldMeter -= mech.fieldRegen + FIELD_DRAIN
|
||||||
// let best;
|
// let best;
|
||||||
@@ -508,7 +508,7 @@ const b = {
|
|||||||
// x: path[i].x - path[i - 1].x,
|
// x: path[i].x - path[i - 1].x,
|
||||||
// y: path[i].y - path[i - 1].y
|
// y: path[i].y - path[i - 1].y
|
||||||
// }
|
// }
|
||||||
// const a = game.cycle * 5
|
// const a = mech.cycle * 5
|
||||||
// p1 = {
|
// p1 = {
|
||||||
// x: d.x / 2 * Math.cos(a) - d.y / 2 * Math.sin(a),
|
// x: d.x / 2 * Math.cos(a) - d.y / 2 * Math.sin(a),
|
||||||
// y: d.x / 2 * Math.sin(a) + d.y / 2 * Math.cos(a),
|
// y: d.x / 2 * Math.sin(a) + d.y / 2 * Math.cos(a),
|
||||||
@@ -592,19 +592,17 @@ const b = {
|
|||||||
onDmg() {},
|
onDmg() {},
|
||||||
onEnd() {},
|
onEnd() {},
|
||||||
do() {
|
do() {
|
||||||
//wiggle
|
if (!mech.isBodiesAsleep) {
|
||||||
this.cycle++
|
this.cycle++
|
||||||
const THRUST = wiggleMag * Math.cos(this.cycle * 0.3)
|
const THRUST = wiggleMag * Math.cos(this.cycle * 0.3)
|
||||||
this.force = Matter.Vector.mult(Matter.Vector.normalise(this.direction), this.mass * THRUST)
|
this.force = Matter.Vector.mult(Matter.Vector.normalise(this.direction), this.mass * THRUST) //wiggle
|
||||||
|
|
||||||
//shrink
|
if (this.cycle > 0 && !(Math.floor(this.cycle) % 6)) Matter.Body.scale(this, SCALE, SCALE); //shrink
|
||||||
if (this.cycle > 0 && !(Math.floor(this.cycle) % 6)) {
|
|
||||||
Matter.Body.scale(this, SCALE, SCALE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
World.add(engine.world, bullet[me]); //add bullet to world
|
World.add(engine.world, bullet[me]); //add bullet to world
|
||||||
mech.fireCDcycle = game.cycle + (mech.crouch ? 8 : 4); // cool down
|
mech.fireCDcycle = mech.cycle + (mech.crouch ? 8 : 4); // cool down
|
||||||
const SPEED = mech.crouch ? 5.2 : 4.5;
|
const SPEED = mech.crouch ? 5.2 : 4.5;
|
||||||
Matter.Body.setVelocity(bullet[me], {
|
Matter.Body.setVelocity(bullet[me], {
|
||||||
x: SPEED * Math.cos(DIR),
|
x: SPEED * Math.cos(DIR),
|
||||||
@@ -726,70 +724,80 @@ const b = {
|
|||||||
};
|
};
|
||||||
bullet[me].lockedOn = null;
|
bullet[me].lockedOn = null;
|
||||||
bullet[me].do = function () {
|
bullet[me].do = function () {
|
||||||
if (!(game.cycle % this.lookFrequency)) {
|
if (!mech.isBodiesAsleep) {
|
||||||
this.close = null;
|
if (!(mech.cycle % this.lookFrequency)) {
|
||||||
this.lockedOn = null;
|
this.closestTarget = null;
|
||||||
let closeDist = Infinity;
|
this.lockedOn = null;
|
||||||
for (let i = 0, len = mob.length; i < len; ++i) {
|
let closeDist = Infinity;
|
||||||
if (
|
|
||||||
mob[i].alive &&
|
//look for targets
|
||||||
mob[i].dropPowerUp &&
|
for (let i = 0, len = mob.length; i < len; ++i) {
|
||||||
Matter.Query.ray(map, this.position, mob[i].position).length === 0 &&
|
if (
|
||||||
Matter.Query.ray(body, this.position, mob[i].position).length === 0
|
mob[i].alive &&
|
||||||
) {
|
mob[i].dropPowerUp &&
|
||||||
const dist = Matter.Vector.magnitude(Matter.Vector.sub(this.position, mob[i].position));
|
Matter.Query.ray(map, this.position, mob[i].position).length === 0 &&
|
||||||
if (dist < closeDist) {
|
Matter.Query.ray(body, this.position, mob[i].position).length === 0
|
||||||
this.close = mob[i].position;
|
) {
|
||||||
closeDist = dist;
|
const dist = Matter.Vector.magnitude(Matter.Vector.sub(this.position, mob[i].position));
|
||||||
this.lockedOn = mob[i];
|
if (dist < closeDist) {
|
||||||
|
this.closestTarget = mob[i].position;
|
||||||
|
closeDist = dist;
|
||||||
|
this.lockedOn = mob[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//explode when bullet is close enough to target
|
||||||
|
if (this.closestTarget && closeDist < this.explodeRad * 0.7) {
|
||||||
|
this.endCycle = 0; //bullet ends cycle after doing damage //this also triggers explosion
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.lockedOn) {
|
||||||
|
this.frictionAir = 0.04; //extra friction
|
||||||
|
|
||||||
|
//draw locked on targeting
|
||||||
|
ctx.beginPath();
|
||||||
|
const vertices = this.lockedOn.vertices;
|
||||||
|
ctx.moveTo(this.position.x, this.position.y);
|
||||||
|
const mod = Math.floor((game.cycle / 3) % vertices.length);
|
||||||
|
ctx.lineTo(vertices[mod].x, vertices[mod].y);
|
||||||
|
ctx.strokeStyle = "rgba(0,0,155,0.35)"; //"#2f6";
|
||||||
|
ctx.lineWidth = 1;
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//rotate missile towards the target
|
||||||
|
if (this.closestTarget) {
|
||||||
|
const face = {
|
||||||
|
x: Math.cos(this.angle),
|
||||||
|
y: Math.sin(this.angle)
|
||||||
|
};
|
||||||
|
const target = Matter.Vector.normalise(Matter.Vector.sub(this.position, this.closestTarget));
|
||||||
|
if (Matter.Vector.dot(target, face) > -0.98) {
|
||||||
|
if (Matter.Vector.cross(target, face) > 0) {
|
||||||
|
Matter.Body.rotate(this, 0.08);
|
||||||
|
} else {
|
||||||
|
Matter.Body.rotate(this, -0.08);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//explode when bullet is close enough to target
|
//accelerate in direction bullet is facing
|
||||||
if (this.close && closeDist < this.explodeRad * 0.7) {
|
const dir = this.angle; // + (Math.random() - 0.5);
|
||||||
this.endCycle = 0; //bullet ends cycle after doing damage //this also triggers explosion
|
this.force.x += Math.cos(dir) * thrust;
|
||||||
}
|
this.force.y += Math.sin(dir) * thrust;
|
||||||
|
|
||||||
if (this.lockedOn) {
|
//draw rocket
|
||||||
this.frictionAir = 0.04; //extra friction
|
ctx.beginPath();
|
||||||
|
ctx.arc(this.position.x - Math.cos(this.angle) * 27 + (Math.random() - 0.5) * 4, this.position.y - Math.sin(this.angle) * 27 + (Math.random() - 0.5) * 4, 11, 0, 2 * Math.PI);
|
||||||
//draw locked on targeting
|
ctx.fillStyle = "rgba(255,155,0,0.5)";
|
||||||
ctx.beginPath();
|
ctx.fill();
|
||||||
const vertices = this.lockedOn.vertices;
|
} else {
|
||||||
ctx.moveTo(this.position.x, this.position.y);
|
//draw rocket with time stop
|
||||||
const mod = Math.floor((game.cycle / 3) % vertices.length);
|
ctx.beginPath();
|
||||||
ctx.lineTo(vertices[mod].x, vertices[mod].y);
|
ctx.arc(this.position.x - Math.cos(this.angle) * 27, this.position.y - Math.sin(this.angle) * 27, 11, 0, 2 * Math.PI);
|
||||||
ctx.strokeStyle = "rgba(0,0,155,0.35)"; //"#2f6";
|
ctx.fillStyle = "rgba(255,155,0,0.5)";
|
||||||
ctx.lineWidth = 1;
|
ctx.fill();
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//rotate missile towards the target
|
|
||||||
if (this.close) {
|
|
||||||
const face = {
|
|
||||||
x: Math.cos(this.angle),
|
|
||||||
y: Math.sin(this.angle)
|
|
||||||
};
|
|
||||||
const target = Matter.Vector.normalise(Matter.Vector.sub(this.position, this.close));
|
|
||||||
if (Matter.Vector.dot(target, face) > -0.98) {
|
|
||||||
if (Matter.Vector.cross(target, face) > 0) {
|
|
||||||
Matter.Body.rotate(this, 0.08);
|
|
||||||
} else {
|
|
||||||
Matter.Body.rotate(this, -0.08);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//accelerate in direction bullet is facing
|
|
||||||
const dir = this.angle; // + (Math.random() - 0.5);
|
|
||||||
this.force.x += Math.cos(dir) * thrust;
|
|
||||||
this.force.y += Math.sin(dir) * thrust;
|
|
||||||
|
|
||||||
//draw rocket
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(this.position.x - Math.cos(this.angle) * 27 + (Math.random() - 0.5) * 4, this.position.y - Math.sin(this.angle) * 27 + (Math.random() - 0.5) * 4, 11, 0, 2 * Math.PI);
|
|
||||||
ctx.fillStyle = "rgba(255,155,0,0.5)";
|
|
||||||
ctx.fill();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -934,9 +942,11 @@ const b = {
|
|||||||
bullet[me].minDmgSpeed = 0;
|
bullet[me].minDmgSpeed = 0;
|
||||||
bullet[me].onDmg = function () {};
|
bullet[me].onDmg = function () {};
|
||||||
bullet[me].do = function () {
|
bullet[me].do = function () {
|
||||||
const SCALE = 1.017
|
if (!mech.isBodiesAsleep) {
|
||||||
Matter.Body.scale(this, SCALE, SCALE);
|
const SCALE = 1.017
|
||||||
this.frictionAir += 0.00023;
|
Matter.Body.scale(this, SCALE, SCALE);
|
||||||
|
this.frictionAir += 0.00023;
|
||||||
|
}
|
||||||
|
|
||||||
this.force.y += this.mass * 0.00045;
|
this.force.y += this.mass * 0.00045;
|
||||||
|
|
||||||
@@ -978,7 +988,7 @@ const b = {
|
|||||||
|
|
||||||
//find mob targets
|
//find mob targets
|
||||||
if (!(game.cycle % this.lookFrequency)) {
|
if (!(game.cycle % this.lookFrequency)) {
|
||||||
this.close = null;
|
this.closestTarget = null;
|
||||||
this.lockedOn = null;
|
this.lockedOn = null;
|
||||||
let closeDist = Infinity;
|
let closeDist = Infinity;
|
||||||
for (let i = 0, len = mob.length; i < len; ++i) {
|
for (let i = 0, len = mob.length; i < len; ++i) {
|
||||||
@@ -987,7 +997,7 @@ const b = {
|
|||||||
const targetVector = Matter.Vector.sub(this.position, mob[i].position)
|
const targetVector = Matter.Vector.sub(this.position, mob[i].position)
|
||||||
const dist = Matter.Vector.magnitude(targetVector);
|
const dist = Matter.Vector.magnitude(targetVector);
|
||||||
if (dist < closeDist) {
|
if (dist < closeDist) {
|
||||||
this.close = mob[i].position;
|
this.closestTarget = mob[i].position;
|
||||||
closeDist = dist;
|
closeDist = dist;
|
||||||
this.lockedOn = Matter.Vector.normalise(targetVector);
|
this.lockedOn = Matter.Vector.normalise(targetVector);
|
||||||
if (0.3 > Math.random()) break //doesn't always target the closest mob
|
if (0.3 > Math.random()) break //doesn't always target the closest mob
|
||||||
@@ -1110,13 +1120,13 @@ const b = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
fire() {
|
fire() {
|
||||||
if (game.mouseDown && mech.fireCDcycle < game.cycle && !(keys[32] || game.mouseDownRight) && b.inventory.length) {
|
if (game.mouseDown && mech.fireCDcycle < mech.cycle && !(keys[32] || game.mouseDownRight) && b.inventory.length) {
|
||||||
if (b.guns[this.activeGun].ammo > 0) {
|
if (b.guns[this.activeGun].ammo > 0) {
|
||||||
b.guns[this.activeGun].fire();
|
b.guns[this.activeGun].fire();
|
||||||
b.guns[this.activeGun].ammo--;
|
b.guns[this.activeGun].ammo--;
|
||||||
game.updateGunHUD();
|
game.updateGunHUD();
|
||||||
} else {
|
} else {
|
||||||
mech.fireCDcycle = game.cycle + 30; //cooldown
|
mech.fireCDcycle = mech.cycle + 30; //cooldown
|
||||||
// game.makeTextLog("<div style='font-size:140%;'>NO AMMO</div><span class = 'box'>E</span> / <span class = 'box'>Q</span>", 200);
|
// game.makeTextLog("<div style='font-size:140%;'>NO AMMO</div><span class = 'box'>E</span> / <span class = 'box'>Q</span>", 200);
|
||||||
game.makeTextLog("<div style='font-size:140%;'>NO AMMO</div> <p style='font-size:90%;'><strong>Q</strong>, <strong>E</strong>, and <strong>mouse wheel</strong> change weapons</p>", 200);
|
game.makeTextLog("<div style='font-size:140%;'>NO AMMO</div> <p style='font-size:90%;'><strong>Q</strong>, <strong>E</strong>, and <strong>mouse wheel</strong> change weapons</p>", 200);
|
||||||
}
|
}
|
||||||
@@ -1126,13 +1136,13 @@ const b = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
gamepadFire() {
|
gamepadFire() {
|
||||||
if (game.gamepad.rightTrigger && mech.fireCDcycle < game.cycle && !(keys[32] || game.gamepad.leftTrigger) && !mech.isHolding && b.inventory.length) {
|
if (game.gamepad.rightTrigger && mech.fireCDcycle < mech.cycle && !(keys[32] || game.gamepad.leftTrigger) && !mech.isHolding && b.inventory.length) {
|
||||||
if (b.guns[this.activeGun].ammo > 0) {
|
if (b.guns[this.activeGun].ammo > 0) {
|
||||||
b.guns[this.activeGun].fire();
|
b.guns[this.activeGun].fire();
|
||||||
b.guns[this.activeGun].ammo--;
|
b.guns[this.activeGun].ammo--;
|
||||||
game.updateGunHUD();
|
game.updateGunHUD();
|
||||||
} else {
|
} else {
|
||||||
mech.fireCDcycle = game.cycle + 30; //cooldown
|
mech.fireCDcycle = mech.cycle + 30; //cooldown
|
||||||
game.makeTextLog("<div style='font-size:140%;'>NO AMMO</div><p style='font-size:90%;'><strong>Q</strong>, <strong>E</strong>, and <strong>mouse wheel</strong> change weapons</p>", 200);
|
game.makeTextLog("<div style='font-size:140%;'>NO AMMO</div><p style='font-size:90%;'><strong>Q</strong>, <strong>E</strong>, and <strong>mouse wheel</strong> change weapons</p>", 200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,9 +89,9 @@ function mobCollisionChecks(event) {
|
|||||||
function collide(obj) {
|
function collide(obj) {
|
||||||
//player and mob collision
|
//player and mob collision
|
||||||
if (obj === playerBody || obj === playerHead) {
|
if (obj === playerBody || obj === playerHead) {
|
||||||
if (mech.damageImmune < game.cycle) {
|
if (mech.damageImmune < mech.cycle) {
|
||||||
//player is immune to mob collision damage for 30 cycles
|
//player is immune to mob collision damage for 30 cycles
|
||||||
mech.damageImmune = game.cycle + 30;
|
mech.damageImmune = mech.cycle + 30;
|
||||||
mob[k].foundPlayer();
|
mob[k].foundPlayer();
|
||||||
let dmg = Math.min(Math.max(0.025 * Math.sqrt(mob[k].mass), 0.05), 0.3) * game.dmgScale; //player damage is capped at 0.3*dmgScale of 1.0
|
let dmg = Math.min(Math.max(0.025 * Math.sqrt(mob[k].mass), 0.05), 0.3) * game.dmgScale; //player damage is capped at 0.3*dmgScale of 1.0
|
||||||
mech.damage(dmg);
|
mech.damage(dmg);
|
||||||
|
|||||||
14
js/game.js
14
js/game.js
@@ -4,6 +4,7 @@ const game = {
|
|||||||
loop() {},
|
loop() {},
|
||||||
mouseLoop() {
|
mouseLoop() {
|
||||||
game.cycle++; //tracks game cycles
|
game.cycle++; //tracks game cycles
|
||||||
|
mech.cycle++; //tracks player cycles //used to alow time to stop for everything, but the player
|
||||||
if (game.clearNow) {
|
if (game.clearNow) {
|
||||||
game.clearNow = false;
|
game.clearNow = false;
|
||||||
game.clearMap();
|
game.clearMap();
|
||||||
@@ -52,6 +53,7 @@ const game = {
|
|||||||
},
|
},
|
||||||
gamepadLoop() {
|
gamepadLoop() {
|
||||||
game.cycle++; //tracks game cycles
|
game.cycle++; //tracks game cycles
|
||||||
|
mech.cycle++; //tracks player cycles //used to alow time to stop for everything, but the player
|
||||||
// game.polGamepad();
|
// game.polGamepad();
|
||||||
if (game.clearNow) {
|
if (game.clearNow) {
|
||||||
game.clearNow = false;
|
game.clearNow = false;
|
||||||
@@ -313,10 +315,10 @@ const game = {
|
|||||||
makeTextLog(text, time = 180) {
|
makeTextLog(text, time = 180) {
|
||||||
document.getElementById("text-log").innerHTML = text;
|
document.getElementById("text-log").innerHTML = text;
|
||||||
document.getElementById("text-log").style.opacity = 1;
|
document.getElementById("text-log").style.opacity = 1;
|
||||||
game.lastLogTime = game.cycle + time;
|
game.lastLogTime = mech.cycle + time;
|
||||||
},
|
},
|
||||||
textLog() {
|
textLog() {
|
||||||
if (game.lastLogTime && game.lastLogTime < game.cycle) {
|
if (game.lastLogTime && game.lastLogTime < mech.cycle) {
|
||||||
game.lastLogTime = 0;
|
game.lastLogTime = 0;
|
||||||
// document.getElementById("text-log").innerHTML = " ";
|
// document.getElementById("text-log").innerHTML = " ";
|
||||||
document.getElementById("text-log").style.opacity = 0;
|
document.getElementById("text-log").style.opacity = 0;
|
||||||
@@ -745,7 +747,7 @@ const game = {
|
|||||||
// if 4000px deep
|
// if 4000px deep
|
||||||
if (mech.pos.y > game.fallHeight) mech.death();
|
if (mech.pos.y > game.fallHeight) mech.death();
|
||||||
|
|
||||||
if (!(game.cycle % 420)) {
|
if (!(mech.cycle % 420)) {
|
||||||
remove = function (who) {
|
remove = function (who) {
|
||||||
let i = who.length;
|
let i = who.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
@@ -778,6 +780,8 @@ const game = {
|
|||||||
|
|
||||||
ctx.fillText("cycle: " + game.cycle, x, line);
|
ctx.fillText("cycle: " + game.cycle, x, line);
|
||||||
line += 20;
|
line += 20;
|
||||||
|
ctx.fillText("player cycle: " + mech.cycle, x, line);
|
||||||
|
line += 20;
|
||||||
ctx.fillText("x: " + player.position.x.toFixed(0), x, line);
|
ctx.fillText("x: " + player.position.x.toFixed(0), x, line);
|
||||||
line += 20;
|
line += 20;
|
||||||
ctx.fillText("y: " + player.position.y.toFixed(0), x, line);
|
ctx.fillText("y: " + player.position.y.toFixed(0), x, line);
|
||||||
@@ -814,7 +818,7 @@ const game = {
|
|||||||
draw: {
|
draw: {
|
||||||
powerUp() {
|
powerUp() {
|
||||||
// draw power up
|
// draw power up
|
||||||
// ctx.globalAlpha = 0.4 * Math.sin(game.cycle * 0.15) + 0.6;
|
// ctx.globalAlpha = 0.4 * Math.sin(mech.cycle * 0.15) + 0.6;
|
||||||
// for (let i = 0, len = powerUp.length; i < len; ++i) {
|
// for (let i = 0, len = powerUp.length; i < len; ++i) {
|
||||||
// let vertices = powerUp[i].vertices;
|
// let vertices = powerUp[i].vertices;
|
||||||
// ctx.beginPath();
|
// ctx.beginPath();
|
||||||
@@ -827,7 +831,7 @@ const game = {
|
|||||||
// ctx.fill();
|
// ctx.fill();
|
||||||
// }
|
// }
|
||||||
// ctx.globalAlpha = 1;
|
// ctx.globalAlpha = 1;
|
||||||
ctx.globalAlpha = 0.4 * Math.sin(game.cycle * 0.15) + 0.6;
|
ctx.globalAlpha = 0.4 * Math.sin(mech.cycle * 0.15) + 0.6;
|
||||||
for (let i = 0, len = powerUp.length; i < len; ++i) {
|
for (let i = 0, len = powerUp.length; i < len; ++i) {
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.arc(powerUp[i].position.x, powerUp[i].position.y, powerUp[i].size, 0, 2 * Math.PI);
|
ctx.arc(powerUp[i].position.x, powerUp[i].position.y, powerUp[i].size, 0, 2 * Math.PI);
|
||||||
|
|||||||
37
js/level.js
37
js/level.js
@@ -16,13 +16,13 @@ const level = {
|
|||||||
// game.levelsCleared = 4; //for testing to simulate possible mobs spawns
|
// game.levelsCleared = 4; //for testing to simulate possible mobs spawns
|
||||||
// b.giveGuns(1) // set a starting gun for testing
|
// b.giveGuns(1) // set a starting gun for testing
|
||||||
// b.giveGuns("all", 1000)
|
// b.giveGuns("all", 1000)
|
||||||
// mech.fieldUpgrades[5]() //give a field power up for testing
|
mech.fieldUpgrades[1]() //give a field power up for testing
|
||||||
this.intro(); //starting level
|
// this.intro(); //starting level
|
||||||
// this.testingMap();
|
// this.testingMap();
|
||||||
// this.bosses();
|
// this.bosses();
|
||||||
// this.aerie();
|
// this.aerie();
|
||||||
// this.rooftops();
|
// this.rooftops();
|
||||||
// this.warehouse();
|
this.warehouse();
|
||||||
// this.highrise();
|
// this.highrise();
|
||||||
// this.office();
|
// this.office();
|
||||||
} else {
|
} else {
|
||||||
@@ -44,8 +44,9 @@ const level = {
|
|||||||
//******************************************************************************************************************
|
//******************************************************************************************************************
|
||||||
//******************************************************************************************************************
|
//******************************************************************************************************************
|
||||||
testingMap() {
|
testingMap() {
|
||||||
|
//start with all guns
|
||||||
|
b.giveGuns("all", 1000)
|
||||||
game.zoomScale = 1400 //1400 is normal
|
game.zoomScale = 1400 //1400 is normal
|
||||||
game.zoomTransition(1400)
|
|
||||||
spawn.setSpawnList();
|
spawn.setSpawnList();
|
||||||
game.levelsCleared = 3; //for testing to simulate all possible mobs spawns
|
game.levelsCleared = 3; //for testing to simulate all possible mobs spawns
|
||||||
for (let i = 0; i < game.levelsCleared; i++) {
|
for (let i = 0; i < game.levelsCleared; i++) {
|
||||||
@@ -58,9 +59,9 @@ const level = {
|
|||||||
level.exit.x = 3500;
|
level.exit.x = 3500;
|
||||||
level.exit.y = -870;
|
level.exit.y = -870;
|
||||||
this.addZone(level.exit.x, level.exit.y, 100, 30, "nextLevel");
|
this.addZone(level.exit.x, level.exit.y, 100, 30, "nextLevel");
|
||||||
|
document.body.style.backgroundColor = "#dcdcde";
|
||||||
|
|
||||||
|
|
||||||
//start with all guns
|
|
||||||
b.giveGuns("all", 1000)
|
|
||||||
|
|
||||||
|
|
||||||
// this.addZone(250, -1000, 500, 1500, "laser");
|
// this.addZone(250, -1000, 500, 1500, "laser");
|
||||||
@@ -68,13 +69,6 @@ const level = {
|
|||||||
// setTimeout(function() {
|
// setTimeout(function() {
|
||||||
// document.body.style.backgroundColor = "#eee";
|
// document.body.style.backgroundColor = "#eee";
|
||||||
// }, 1);
|
// }, 1);
|
||||||
document.body.style.backgroundColor = "#fff";
|
|
||||||
// document.body.style.backgroundColor = "#fafcff";
|
|
||||||
// document.body.style.backgroundColor = "#bbb";
|
|
||||||
// document.body.style.backgroundColor = "#eee4e4";
|
|
||||||
// document.body.style.backgroundColor = "#dcdcde";
|
|
||||||
// document.body.style.backgroundColor = "#e0e5e0";
|
|
||||||
|
|
||||||
// this.addQueryRegion(550, -25, 100, 50, "bounce", { Vx: 0, Vy: -25 });
|
// this.addQueryRegion(550, -25, 100, 50, "bounce", { Vx: 0, Vy: -25 });
|
||||||
// level.fillBG.push({ x: 550, y: -25, width: 100, height: 50, color: "#ff0" });
|
// level.fillBG.push({ x: 550, y: -25, width: 100, height: 50, color: "#ff0" });
|
||||||
|
|
||||||
@@ -123,20 +117,9 @@ const level = {
|
|||||||
// spawn.bodyRect(-45, -100, 40, 50);
|
// spawn.bodyRect(-45, -100, 40, 50);
|
||||||
// spawn.focuser(800, -1150);
|
// spawn.focuser(800, -1150);
|
||||||
// spawn.groupBoss(-600, -550);
|
// spawn.groupBoss(-600, -550);
|
||||||
// for (let i = 0; i < 1; ++i) {
|
spawn.starter(800, -150, 100);
|
||||||
spawn.shooter(800, -150, 10);
|
// spawn.grower(800, -250);
|
||||||
spawn.shooter(800, -150, 10);
|
// spawn.blinker(800, -250, 40);
|
||||||
spawn.shooter(800, -100, 10);
|
|
||||||
spawn.shooter(800, -50, 10);
|
|
||||||
spawn.shooter(800, -150, 10);
|
|
||||||
spawn.shooter(800, -150, 10);
|
|
||||||
spawn.shooter(800, -100, 10);
|
|
||||||
spawn.shooter(800, -50, 10);
|
|
||||||
spawn.shooter(800, -150, 10);
|
|
||||||
spawn.shooter(800, -150, 10);
|
|
||||||
spawn.shooter(800, -100, 10);
|
|
||||||
spawn.shooter(800, -50, 10);
|
|
||||||
// }
|
|
||||||
// spawn.groupBoss(900, -1070);
|
// spawn.groupBoss(900, -1070);
|
||||||
// for (let i = 0; i < 20; i++) {
|
// for (let i = 0; i < 20; i++) {
|
||||||
// spawn.randomBoss(-100, -1470);
|
// spawn.randomBoss(-100, -1470);
|
||||||
|
|||||||
126
js/mobs.js
126
js/mobs.js
@@ -681,20 +681,22 @@ const mobs = {
|
|||||||
// }
|
// }
|
||||||
},
|
},
|
||||||
grow() {
|
grow() {
|
||||||
if (this.seePlayer.recall) {
|
if (!mech.isBodiesAsleep) {
|
||||||
if (this.radius < 80) {
|
if (this.seePlayer.recall) {
|
||||||
const scale = 1.01;
|
if (this.radius < 80) {
|
||||||
Matter.Body.scale(this, scale, scale);
|
const scale = 1.01;
|
||||||
this.radius *= scale;
|
Matter.Body.scale(this, scale, scale);
|
||||||
// this.torque = -0.00002 * this.inertia;
|
this.radius *= scale;
|
||||||
this.fill = `hsl(144, ${this.radius}%, 50%)`;
|
// this.torque = -0.00002 * this.inertia;
|
||||||
}
|
this.fill = `hsl(144, ${this.radius}%, 50%)`;
|
||||||
} else {
|
}
|
||||||
if (this.radius > 15) {
|
} else {
|
||||||
const scale = 0.99;
|
if (this.radius > 15) {
|
||||||
Matter.Body.scale(this, scale, scale);
|
const scale = 0.99;
|
||||||
this.radius *= scale;
|
Matter.Body.scale(this, scale, scale);
|
||||||
this.fill = `hsl(144, ${this.radius}%, 50%)`;
|
this.radius *= scale;
|
||||||
|
this.fill = `hsl(144, ${this.radius}%, 50%)`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -813,50 +815,52 @@ const mobs = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
fire() {
|
fire() {
|
||||||
const setNoseShape = () => {
|
if (!mech.isBodiesAsleep) {
|
||||||
const mag = this.radius + this.radius * this.noseLength;
|
const setNoseShape = () => {
|
||||||
this.vertices[1].x = this.position.x + Math.cos(this.angle) * mag;
|
const mag = this.radius + this.radius * this.noseLength;
|
||||||
this.vertices[1].y = this.position.y + Math.sin(this.angle) * mag;
|
this.vertices[1].x = this.position.x + Math.cos(this.angle) * mag;
|
||||||
};
|
this.vertices[1].y = this.position.y + Math.sin(this.angle) * mag;
|
||||||
//throw a mob/bullet at player
|
};
|
||||||
if (this.seePlayer.recall) {
|
//throw a mob/bullet at player
|
||||||
//set direction to turn to fire
|
if (this.seePlayer.recall) {
|
||||||
if (!(game.cycle % this.seePlayerFreq)) {
|
//set direction to turn to fire
|
||||||
this.fireDir = Matter.Vector.normalise(Matter.Vector.sub(this.seePlayer.position, this.position));
|
if (!(game.cycle % this.seePlayerFreq)) {
|
||||||
this.fireDir.y -= Math.abs(this.seePlayer.position.x - this.position.x) / 1600; //gives the bullet an arc
|
this.fireDir = Matter.Vector.normalise(Matter.Vector.sub(this.seePlayer.position, this.position));
|
||||||
this.fireAngle = Math.atan2(this.fireDir.y, this.fireDir.x);
|
this.fireDir.y -= Math.abs(this.seePlayer.position.x - this.position.x) / 1600; //gives the bullet an arc
|
||||||
|
this.fireAngle = Math.atan2(this.fireDir.y, this.fireDir.x);
|
||||||
|
}
|
||||||
|
//rotate towards fireAngle
|
||||||
|
const angle = this.angle + Math.PI / 2;
|
||||||
|
c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y;
|
||||||
|
const threshold = 0.1;
|
||||||
|
if (c > threshold) {
|
||||||
|
this.torque += 0.000004 * this.inertia;
|
||||||
|
} else if (c < -threshold) {
|
||||||
|
this.torque -= 0.000004 * this.inertia;
|
||||||
|
} else if (this.noseLength > 1.5) {
|
||||||
|
//fire
|
||||||
|
spawn.bullet(this.vertices[1].x, this.vertices[1].y, 5 + Math.ceil(this.radius / 15), 5);
|
||||||
|
const v = 15;
|
||||||
|
Matter.Body.setVelocity(mob[mob.length - 1], {
|
||||||
|
x: this.velocity.x + this.fireDir.x * v + Math.random(),
|
||||||
|
y: this.velocity.y + this.fireDir.y * v + Math.random()
|
||||||
|
});
|
||||||
|
this.noseLength = 0;
|
||||||
|
// recoil
|
||||||
|
this.force.x -= 0.005 * this.fireDir.x * this.mass;
|
||||||
|
this.force.y -= 0.005 * this.fireDir.y * this.mass;
|
||||||
|
}
|
||||||
|
if (this.noseLength < 1.5) this.noseLength += this.fireFreq;
|
||||||
|
setNoseShape();
|
||||||
|
} else if (this.noseLength > 0.1) {
|
||||||
|
this.noseLength -= this.fireFreq / 2;
|
||||||
|
setNoseShape();
|
||||||
}
|
}
|
||||||
//rotate towards fireAngle
|
// else if (this.noseLength < -0.1) {
|
||||||
const angle = this.angle + Math.PI / 2;
|
// this.noseLength += this.fireFreq / 4;
|
||||||
c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y;
|
// setNoseShape();
|
||||||
const threshold = 0.1;
|
// }
|
||||||
if (c > threshold) {
|
|
||||||
this.torque += 0.000004 * this.inertia;
|
|
||||||
} else if (c < -threshold) {
|
|
||||||
this.torque -= 0.000004 * this.inertia;
|
|
||||||
} else if (this.noseLength > 1.5) {
|
|
||||||
//fire
|
|
||||||
spawn.bullet(this.vertices[1].x, this.vertices[1].y, 5 + Math.ceil(this.radius / 15), 5);
|
|
||||||
const v = 15;
|
|
||||||
Matter.Body.setVelocity(mob[mob.length - 1], {
|
|
||||||
x: this.velocity.x + this.fireDir.x * v + Math.random(),
|
|
||||||
y: this.velocity.y + this.fireDir.y * v + Math.random()
|
|
||||||
});
|
|
||||||
this.noseLength = 0;
|
|
||||||
// recoil
|
|
||||||
this.force.x -= 0.005 * this.fireDir.x * this.mass;
|
|
||||||
this.force.y -= 0.005 * this.fireDir.y * this.mass;
|
|
||||||
}
|
|
||||||
if (this.noseLength < 1.5) this.noseLength += this.fireFreq;
|
|
||||||
setNoseShape();
|
|
||||||
} else if (this.noseLength > 0.1) {
|
|
||||||
this.noseLength -= this.fireFreq / 2;
|
|
||||||
setNoseShape();
|
|
||||||
}
|
}
|
||||||
// else if (this.noseLength < -0.1) {
|
|
||||||
// this.noseLength += this.fireFreq / 4;
|
|
||||||
// setNoseShape();
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
turnToFacePlayer() {
|
turnToFacePlayer() {
|
||||||
//turn to face player
|
//turn to face player
|
||||||
@@ -887,10 +891,12 @@ const mobs = {
|
|||||||
this.death(); //death with no power up or body
|
this.death(); //death with no power up or body
|
||||||
},
|
},
|
||||||
timeLimit() {
|
timeLimit() {
|
||||||
this.timeLeft--;
|
if (!mech.isBodiesAsleep) {
|
||||||
if (this.timeLeft < 0) {
|
this.timeLeft--;
|
||||||
this.dropPowerUp = false;
|
if (this.timeLeft < 0) {
|
||||||
this.death(); //death with no power up
|
this.dropPowerUp = false;
|
||||||
|
this.death(); //death with no power up
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
healthBar() {
|
healthBar() {
|
||||||
|
|||||||
161
js/player.js
161
js/player.js
@@ -52,6 +52,7 @@ const mech = {
|
|||||||
});
|
});
|
||||||
World.add(engine.world, mech.holdConstraint);
|
World.add(engine.world, mech.holdConstraint);
|
||||||
},
|
},
|
||||||
|
cycle: 0,
|
||||||
width: 50,
|
width: 50,
|
||||||
radius: 30,
|
radius: 30,
|
||||||
fillColor: "#fff",
|
fillColor: "#fff",
|
||||||
@@ -218,7 +219,7 @@ const mech = {
|
|||||||
if (momentum > 100) {
|
if (momentum > 100) {
|
||||||
this.doCrouch();
|
this.doCrouch();
|
||||||
this.yOff = this.yOffWhen.jump;
|
this.yOff = this.yOffWhen.jump;
|
||||||
this.hardLandCD = game.cycle + Math.min(momentum / 6 - 6, 40)
|
this.hardLandCD = mech.cycle + Math.min(momentum / 6 - 6, 40)
|
||||||
} else {
|
} else {
|
||||||
this.yOffGoal = this.yOffWhen.stand;
|
this.yOffGoal = this.yOffWhen.stand;
|
||||||
}
|
}
|
||||||
@@ -228,11 +229,11 @@ const mech = {
|
|||||||
keyMove() {
|
keyMove() {
|
||||||
if (this.onGround) { //on ground **********************
|
if (this.onGround) { //on ground **********************
|
||||||
if (this.crouch) {
|
if (this.crouch) {
|
||||||
if (!(keys[83] || keys[40]) && this.isHeadClear && this.hardLandCD < game.cycle) this.undoCrouch();
|
if (!(keys[83] || keys[40]) && this.isHeadClear && this.hardLandCD < mech.cycle) this.undoCrouch();
|
||||||
} else if (keys[83] || keys[40] || this.hardLandCD > game.cycle) {
|
} else if (keys[83] || keys[40] || this.hardLandCD > mech.cycle) {
|
||||||
this.doCrouch(); //on ground && not crouched and pressing s or down
|
this.doCrouch(); //on ground && not crouched and pressing s or down
|
||||||
} else if ((keys[87] || keys[38]) && this.buttonCD_jump + 20 < game.cycle && this.yOffWhen.stand > 23) {
|
} else if ((keys[87] || keys[38]) && this.buttonCD_jump + 20 < mech.cycle && this.yOffWhen.stand > 23) {
|
||||||
this.buttonCD_jump = game.cycle; //can't jump again until 20 cycles pass
|
this.buttonCD_jump = mech.cycle; //can't jump again until 20 cycles pass
|
||||||
|
|
||||||
//apply a fraction of the jump force to the body the player is jumping off of
|
//apply a fraction of the jump force to the body the player is jumping off of
|
||||||
Matter.Body.applyForce(mech.standingOn, mech.pos, {
|
Matter.Body.applyForce(mech.standingOn, mech.pos, {
|
||||||
@@ -274,7 +275,7 @@ const mech = {
|
|||||||
} else { // in air **********************************
|
} else { // in air **********************************
|
||||||
//check for short jumps
|
//check for short jumps
|
||||||
if (
|
if (
|
||||||
this.buttonCD_jump + 60 > game.cycle && //just pressed jump
|
this.buttonCD_jump + 60 > mech.cycle && //just pressed jump
|
||||||
!(keys[87] || keys[38]) && //but not pressing jump key
|
!(keys[87] || keys[38]) && //but not pressing jump key
|
||||||
this.Vy < 0 //moving up
|
this.Vy < 0 //moving up
|
||||||
) {
|
) {
|
||||||
@@ -298,11 +299,11 @@ const mech = {
|
|||||||
gamepadMove() {
|
gamepadMove() {
|
||||||
if (this.onGround) { //on ground **********************
|
if (this.onGround) { //on ground **********************
|
||||||
if (this.crouch) {
|
if (this.crouch) {
|
||||||
if (game.gamepad.leftAxis.y !== -1 && this.isHeadClear && this.hardLandCD < game.cycle) this.undoCrouch();
|
if (game.gamepad.leftAxis.y !== -1 && this.isHeadClear && this.hardLandCD < mech.cycle) this.undoCrouch();
|
||||||
} else if (game.gamepad.leftAxis.y === -1 || this.hardLandCD > game.cycle) {
|
} else if (game.gamepad.leftAxis.y === -1 || this.hardLandCD > mech.cycle) {
|
||||||
this.doCrouch(); //on ground && not crouched and pressing s or down
|
this.doCrouch(); //on ground && not crouched and pressing s or down
|
||||||
} else if (game.gamepad.jump && this.buttonCD_jump + 20 < game.cycle && this.yOffWhen.stand > 23) {
|
} else if (game.gamepad.jump && this.buttonCD_jump + 20 < mech.cycle && this.yOffWhen.stand > 23) {
|
||||||
this.buttonCD_jump = game.cycle; //can't jump again until 20 cycles pass
|
this.buttonCD_jump = mech.cycle; //can't jump again until 20 cycles pass
|
||||||
|
|
||||||
//apply a fraction of the jump force to the body the player is jumping off of
|
//apply a fraction of the jump force to the body the player is jumping off of
|
||||||
Matter.Body.applyForce(mech.standingOn, mech.pos, {
|
Matter.Body.applyForce(mech.standingOn, mech.pos, {
|
||||||
@@ -344,7 +345,7 @@ const mech = {
|
|||||||
} else { // in air **********************************
|
} else { // in air **********************************
|
||||||
//check for short jumps
|
//check for short jumps
|
||||||
if (
|
if (
|
||||||
this.buttonCD_jump + 60 > game.cycle && //just pressed jump
|
this.buttonCD_jump + 60 > mech.cycle && //just pressed jump
|
||||||
!game.gamepad.jump && //but not pressing jump key
|
!game.gamepad.jump && //but not pressing jump key
|
||||||
this.Vy < 0 //moving up
|
this.Vy < 0 //moving up
|
||||||
) {
|
) {
|
||||||
@@ -381,7 +382,7 @@ const mech = {
|
|||||||
},
|
},
|
||||||
health: 0,
|
health: 0,
|
||||||
// regen() {
|
// regen() {
|
||||||
// if (this.health < 1 && game.cycle % 15 === 0) {
|
// if (this.health < 1 && mech.cycle % 15 === 0) {
|
||||||
// this.addHealth(0.01);
|
// this.addHealth(0.01);
|
||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
@@ -439,10 +440,10 @@ const mech = {
|
|||||||
game.fpsCap = game.fpsCapDefault
|
game.fpsCap = game.fpsCapDefault
|
||||||
game.fpsInterval = 1000 / game.fpsCap;
|
game.fpsInterval = 1000 / game.fpsCap;
|
||||||
}
|
}
|
||||||
mech.defaultFPSCycle = game.cycle
|
mech.defaultFPSCycle = mech.cycle
|
||||||
|
|
||||||
const normalFPS = function () {
|
const normalFPS = function () {
|
||||||
if (mech.defaultFPSCycle < game.cycle) { //back to default values
|
if (mech.defaultFPSCycle < mech.cycle) { //back to default values
|
||||||
game.fpsCap = game.fpsCapDefault
|
game.fpsCap = game.fpsCapDefault
|
||||||
game.fpsInterval = 1000 / game.fpsCap;
|
game.fpsInterval = 1000 / game.fpsCap;
|
||||||
document.getElementById("dmg").style.transition = "opacity 1s";
|
document.getElementById("dmg").style.transition = "opacity 1s";
|
||||||
@@ -511,6 +512,8 @@ const mech = {
|
|||||||
this.Fx = 0.015; //run Force on ground
|
this.Fx = 0.015; //run Force on ground
|
||||||
this.FxAir = 0.015; //run Force in Air
|
this.FxAir = 0.015; //run Force in Air
|
||||||
this.gravity = 0.0019;
|
this.gravity = 0.0019;
|
||||||
|
mech.isBodiesAsleep = true;
|
||||||
|
mech.wakeCheck();
|
||||||
// this.phaseBlocks(0x011111)
|
// this.phaseBlocks(0x011111)
|
||||||
},
|
},
|
||||||
drawFieldMeter(range = 60) {
|
drawFieldMeter(range = 60) {
|
||||||
@@ -617,7 +620,7 @@ const mech = {
|
|||||||
}
|
}
|
||||||
} else if (this.throwCharge > 0) {
|
} else if (this.throwCharge > 0) {
|
||||||
//throw the body
|
//throw the body
|
||||||
this.fireCDcycle = game.cycle + this.fieldFireCD;
|
this.fireCDcycle = mech.cycle + this.fieldFireCD;
|
||||||
this.isHolding = false;
|
this.isHolding = false;
|
||||||
//bullet-like collisions
|
//bullet-like collisions
|
||||||
this.holdingTarget.collisionFilter.category = 0x000100;
|
this.holdingTarget.collisionFilter.category = 0x000100;
|
||||||
@@ -675,7 +678,7 @@ const mech = {
|
|||||||
},
|
},
|
||||||
grabPowerUp() {
|
grabPowerUp() {
|
||||||
//look for power ups to grab
|
//look for power ups to grab
|
||||||
if (mech.fieldCDcycle < game.cycle) {
|
if (mech.fieldCDcycle < mech.cycle) {
|
||||||
const grabPowerUpRange2 = (this.grabRange + 200) * (this.grabRange + 200)
|
const grabPowerUpRange2 = (this.grabRange + 200) * (this.grabRange + 200)
|
||||||
for (let i = 0, len = powerUp.length; i < len; ++i) {
|
for (let i = 0, len = powerUp.length; i < len; ++i) {
|
||||||
const dxP = mech.pos.x - powerUp[i].position.x;
|
const dxP = mech.pos.x - powerUp[i].position.x;
|
||||||
@@ -699,7 +702,7 @@ const mech = {
|
|||||||
y: player.velocity.y + ((powerUp[i].velocity.y * powerUp[i].mass) / player.mass) * 0.2
|
y: player.velocity.y + ((powerUp[i].velocity.y * powerUp[i].mass) / player.mass) * 0.2
|
||||||
});
|
});
|
||||||
mech.usePowerUp(i);
|
mech.usePowerUp(i);
|
||||||
// this.fireCDcycle = game.cycle + 10; //cool down
|
// this.fireCDcycle = mech.cycle + 10; //cool down
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// return;
|
// return;
|
||||||
@@ -822,6 +825,32 @@ const mech = {
|
|||||||
this.holdingTarget.collisionFilter.category = 0x000000;
|
this.holdingTarget.collisionFilter.category = 0x000000;
|
||||||
this.holdingTarget.collisionFilter.mask = 0x000000;
|
this.holdingTarget.collisionFilter.mask = 0x000000;
|
||||||
},
|
},
|
||||||
|
wakeCheck() {
|
||||||
|
if (mech.isBodiesAsleep) {
|
||||||
|
mech.isBodiesAsleep = false;
|
||||||
|
|
||||||
|
function wake(who) {
|
||||||
|
for (let i = 0, len = who.length; i < len; ++i) {
|
||||||
|
Matter.Sleeping.set(who[i], false)
|
||||||
|
if (who[i].storeVelocity) {
|
||||||
|
Matter.Body.setVelocity(who[i], {
|
||||||
|
x: who[i].storeVelocity.x,
|
||||||
|
y: who[i].storeVelocity.y
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wake(mob);
|
||||||
|
wake(body);
|
||||||
|
wake(bullet);
|
||||||
|
for (let i = 0, len = cons.length; i < len; i++) {
|
||||||
|
if (cons[i].stiffness === 0) {
|
||||||
|
cons[i].stiffness = cons[i].storeStiffness
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// wake(powerUp);
|
||||||
|
}
|
||||||
|
},
|
||||||
hold() {},
|
hold() {},
|
||||||
fieldUpgrades: [
|
fieldUpgrades: [
|
||||||
() => {
|
() => {
|
||||||
@@ -838,7 +867,7 @@ const mech = {
|
|||||||
mech.grabPowerUp();
|
mech.grabPowerUp();
|
||||||
mech.pushMobs();
|
mech.pushMobs();
|
||||||
mech.lookForPickUp();
|
mech.lookForPickUp();
|
||||||
} else if (mech.holdingTarget && mech.fireCDcycle < game.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
} else if (mech.holdingTarget && mech.fireCDcycle < mech.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
||||||
mech.pickUp();
|
mech.pickUp();
|
||||||
} else {
|
} else {
|
||||||
mech.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists)
|
mech.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists)
|
||||||
@@ -848,59 +877,69 @@ const mech = {
|
|||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
mech.fieldMode = 1;
|
mech.fieldMode = 1;
|
||||||
game.makeTextLog("<strong style='font-size:30px;'>Inertia Negation Field</strong><br> (right mouse or space bar)<p> field slows objects in range<br> <span style='color:#a00;'>decreased</span> field shielding efficiency</p>", 1200);
|
game.makeTextLog("<strong style='font-size:30px;'>Time Dilation Field</strong><br> (right mouse or space bar)<p> field stops all objects except player</p>", 1200);
|
||||||
// <br> field does <span style='color:#a00;'>not</span> shield player
|
// <br> field does <span style='color:#a00;'>not</span> shield player
|
||||||
mech.setHoldDefaults();
|
mech.setHoldDefaults();
|
||||||
mech.grabRange = 900;
|
// mech.grabRange = 900;
|
||||||
mech.fieldShieldingScale = 12;
|
mech.fieldShieldingScale = 12;
|
||||||
// mech.fieldArc = 1; //field covers full 360 degrees
|
// mech.fieldArc = 1; //field covers full 360 degrees
|
||||||
// mech.calculateFieldThreshold(); //run after setting fieldArc, used for powerUp grab and mobPush with lookingAt(mob)
|
// mech.calculateFieldThreshold(); //run after setting fieldArc, used for powerUp grab and mobPush with lookingAt(mob)
|
||||||
|
|
||||||
|
mech.isBodiesAsleep = false;
|
||||||
mech.hold = function () {
|
mech.hold = function () {
|
||||||
|
|
||||||
|
function sleep(who) {
|
||||||
|
for (let i = 0, len = who.length; i < len; ++i) {
|
||||||
|
if (!who[i].isSleeping) who[i].storeVelocity = who[i].velocity
|
||||||
|
Matter.Sleeping.set(who[i], true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mech.isHolding) {
|
if (mech.isHolding) {
|
||||||
|
mech.wakeCheck();
|
||||||
mech.drawHold(mech.holdingTarget);
|
mech.drawHold(mech.holdingTarget);
|
||||||
mech.holding();
|
mech.holding();
|
||||||
mech.throw();
|
mech.throw();
|
||||||
} else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < game.cycle) {
|
} else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) {
|
||||||
const DRAIN = 0.001 //mech.fieldRegen = 0.0015
|
const DRAIN = 0.002 //mech.fieldRegen = 0.0015
|
||||||
if (mech.fieldMeter > DRAIN) {
|
if (mech.fieldMeter > DRAIN) {
|
||||||
mech.fieldMeter -= DRAIN;
|
mech.fieldMeter -= DRAIN;
|
||||||
mech.grabPowerUp();
|
mech.grabPowerUp();
|
||||||
// mech.pushMobs();
|
mech.lookForPickUp(180);
|
||||||
mech.pushMobs360(180);
|
|
||||||
mech.lookForPickUp(160);
|
|
||||||
|
|
||||||
//draw slow field
|
//draw field everywhere
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(mech.pos.x, mech.pos.y + 15, mech.grabRange, 0, 2 * Math.PI);
|
|
||||||
ctx.fillStyle = "rgba(255,255,255," + (0.5 + 0.17 * Math.random()) + ")";
|
ctx.fillStyle = "rgba(255,255,255," + (0.5 + 0.17 * Math.random()) + ")";
|
||||||
ctx.fill();
|
ctx.fillRect(-100000, -100000, 200000, 200000)
|
||||||
|
|
||||||
function slow(who, friction = 0) {
|
//stop time
|
||||||
for (let i = 0, len = who.length; i < len; ++i) {
|
mech.isBodiesAsleep = true;
|
||||||
dist = Matter.Vector.magnitude(Matter.Vector.sub(who[i].position, mech.pos))
|
sleep(mob);
|
||||||
if (dist < mech.grabRange) {
|
sleep(body);
|
||||||
Matter.Body.setAngularVelocity(who[i], who[i].angularVelocity * friction)
|
sleep(bullet);
|
||||||
Matter.Body.setVelocity(who[i], {
|
for (let i = 0, len = cons.length; i < len; i++) {
|
||||||
x: who[i].velocity.x * friction,
|
if (cons[i].stiffness !== 0) {
|
||||||
y: who[i].velocity.y * friction
|
cons[i].storeStiffness = cons[i].stiffness;
|
||||||
});
|
cons[i].stiffness = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
slow(mob);
|
game.cycle--; //pause all functions that depend on game cycle increasing
|
||||||
slow(body);
|
|
||||||
slow(bullet);
|
|
||||||
slow(powerUp);
|
|
||||||
} else {
|
} else {
|
||||||
mech.fieldCDcycle = game.cycle + 120;
|
mech.wakeCheck();
|
||||||
|
mech.fieldCDcycle = mech.cycle + 120;
|
||||||
}
|
}
|
||||||
} else if (mech.holdingTarget && mech.fireCDcycle < game.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
} else if (mech.holdingTarget && mech.fireCDcycle < mech.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
||||||
|
mech.wakeCheck();
|
||||||
mech.pickUp();
|
mech.pickUp();
|
||||||
} else {
|
} else {
|
||||||
|
mech.wakeCheck();
|
||||||
mech.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists)
|
mech.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists)
|
||||||
}
|
}
|
||||||
mech.drawFieldMeter()
|
mech.drawFieldMeter()
|
||||||
|
if (mech.fieldMode !== 1) {
|
||||||
|
//wake up if this is no longer the current field mode, like after a new power up
|
||||||
|
mech.wakeCheck();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
@@ -945,7 +984,7 @@ const mech = {
|
|||||||
mech.grabPowerUp();
|
mech.grabPowerUp();
|
||||||
mech.pushMobs();
|
mech.pushMobs();
|
||||||
mech.lookForPickUp();
|
mech.lookForPickUp();
|
||||||
} else if (mech.holdingTarget && mech.fireCDcycle < game.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
} else if (mech.holdingTarget && mech.fireCDcycle < mech.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
||||||
mech.pickUp();
|
mech.pickUp();
|
||||||
} else {
|
} else {
|
||||||
mech.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists)
|
mech.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists)
|
||||||
@@ -970,7 +1009,7 @@ const mech = {
|
|||||||
mech.drawHold(mech.holdingTarget);
|
mech.drawHold(mech.holdingTarget);
|
||||||
mech.holding();
|
mech.holding();
|
||||||
mech.throw();
|
mech.throw();
|
||||||
} else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < game.cycle) { //push away
|
} else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) { //push away
|
||||||
const DRAIN = 0.001 //mech.fieldRegen = 0.0015
|
const DRAIN = 0.001 //mech.fieldRegen = 0.0015
|
||||||
if (mech.fieldMeter > DRAIN) {
|
if (mech.fieldMeter > DRAIN) {
|
||||||
mech.fieldMeter -= DRAIN;
|
mech.fieldMeter -= DRAIN;
|
||||||
@@ -1028,9 +1067,9 @@ const mech = {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
//trigger cool down
|
//trigger cool down
|
||||||
mech.fieldCDcycle = game.cycle + 120;
|
mech.fieldCDcycle = mech.cycle + 120;
|
||||||
}
|
}
|
||||||
} else if (mech.holdingTarget && mech.fireCDcycle < game.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
} else if (mech.holdingTarget && mech.fireCDcycle < mech.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
||||||
mech.pickUp();
|
mech.pickUp();
|
||||||
mech.grabRange = 0
|
mech.grabRange = 0
|
||||||
} else {
|
} else {
|
||||||
@@ -1057,15 +1096,15 @@ const mech = {
|
|||||||
} else if ((keys[32] || game.mouseDownRight && mech.fieldMeter > 0.1)) { //not hold but field button is pressed
|
} else if ((keys[32] || game.mouseDownRight && mech.fieldMeter > 0.1)) { //not hold but field button is pressed
|
||||||
mech.grabPowerUp();
|
mech.grabPowerUp();
|
||||||
mech.lookForPickUp(180);
|
mech.lookForPickUp(180);
|
||||||
} else if (mech.holdingTarget && mech.fireCDcycle < game.cycle) { //holding, but field button is released
|
} else if (mech.holdingTarget && mech.fireCDcycle < mech.cycle) { //holding, but field button is released
|
||||||
mech.pickUp();
|
mech.pickUp();
|
||||||
} else {
|
} else {
|
||||||
mech.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists)
|
mech.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists)
|
||||||
}
|
}
|
||||||
if (mech.fieldMeter > 0.1) {
|
if (mech.fieldMeter > 0.1) {
|
||||||
const grabRange1 = 80 + 80 * Math.sin(game.cycle / 23)
|
const grabRange1 = 80 + 80 * Math.sin(mech.cycle / 23)
|
||||||
const grabRange2 = 80 + 80 * Math.sin(game.cycle / 37)
|
const grabRange2 = 80 + 80 * Math.sin(mech.cycle / 37)
|
||||||
const grabRange3 = 80 + 80 * Math.sin(game.cycle / 47)
|
const grabRange3 = 80 + 80 * Math.sin(mech.cycle / 47)
|
||||||
const netGrabRange = Math.max(grabRange1, grabRange2, grabRange3)
|
const netGrabRange = Math.max(grabRange1, grabRange2, grabRange3)
|
||||||
ctx.fillStyle = "rgba(110,170,200," + (0.15 + 0.15 * Math.random()) + ")";
|
ctx.fillStyle = "rgba(110,170,200," + (0.15 + 0.15 * Math.random()) + ")";
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
@@ -1104,7 +1143,7 @@ const mech = {
|
|||||||
mech.drawField();
|
mech.drawField();
|
||||||
mech.grabPowerUp();
|
mech.grabPowerUp();
|
||||||
mech.lookForPickUp();
|
mech.lookForPickUp();
|
||||||
} else if (mech.holdingTarget && mech.fireCDcycle < game.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
} else if (mech.holdingTarget && mech.fireCDcycle < mech.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
||||||
mech.pickUp();
|
mech.pickUp();
|
||||||
} else {
|
} else {
|
||||||
mech.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists)
|
mech.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists)
|
||||||
@@ -1125,7 +1164,7 @@ const mech = {
|
|||||||
mech.drawHold(mech.holdingTarget);
|
mech.drawHold(mech.holdingTarget);
|
||||||
mech.holding();
|
mech.holding();
|
||||||
mech.throw();
|
mech.throw();
|
||||||
} else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < game.cycle) {
|
} else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) {
|
||||||
const DRAIN = 0.0035 //mech.fieldRegen = 0.0015
|
const DRAIN = 0.0035 //mech.fieldRegen = 0.0015
|
||||||
if (mech.fieldMeter > DRAIN) {
|
if (mech.fieldMeter > DRAIN) {
|
||||||
mech.fieldMeter -= DRAIN;
|
mech.fieldMeter -= DRAIN;
|
||||||
@@ -1148,9 +1187,9 @@ const mech = {
|
|||||||
mech.grabPowerUp();
|
mech.grabPowerUp();
|
||||||
mech.lookForPickUp(110);
|
mech.lookForPickUp(110);
|
||||||
} else {
|
} else {
|
||||||
mech.fieldCDcycle = game.cycle + 120;
|
mech.fieldCDcycle = mech.cycle + 120;
|
||||||
}
|
}
|
||||||
} else if (mech.holdingTarget && mech.fireCDcycle < game.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
} else if (mech.holdingTarget && mech.fireCDcycle < mech.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
||||||
mech.pickUp();
|
mech.pickUp();
|
||||||
} else {
|
} else {
|
||||||
mech.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists)
|
mech.holdingTarget = null; //clears holding target (this is so you only pick up right after the field button is released and a hold target exists)
|
||||||
@@ -1169,7 +1208,7 @@ const mech = {
|
|||||||
// mech.drawHold(mech.holdingTarget);
|
// mech.drawHold(mech.holdingTarget);
|
||||||
// mech.holding();
|
// mech.holding();
|
||||||
// mech.throw();
|
// mech.throw();
|
||||||
// } else if ((keys[32] || game.mouseDownRight && mech.fieldCDcycle < game.cycle)) { //not hold but field button is pressed
|
// } else if ((keys[32] || game.mouseDownRight && mech.fieldCDcycle < mech.cycle)) { //not hold but field button is pressed
|
||||||
// mech.grabPowerUp();
|
// mech.grabPowerUp();
|
||||||
// mech.lookForPickUp(Math.max(180, mech.grabRange));
|
// mech.lookForPickUp(Math.max(180, mech.grabRange));
|
||||||
// mech.pushMobs360(140);
|
// mech.pushMobs360(140);
|
||||||
@@ -1180,7 +1219,7 @@ const mech = {
|
|||||||
// mech.fieldMeter -= DRAIN;
|
// mech.fieldMeter -= DRAIN;
|
||||||
// mech.damage(0.00005 + 0.00000012 * mech.grabRange)
|
// mech.damage(0.00005 + 0.00000012 * mech.grabRange)
|
||||||
// //draw damage field
|
// //draw damage field
|
||||||
// mech.grabRange = mech.grabRange * 0.997 + (1350 + 150 * Math.cos(game.cycle / 30)) * 0.003
|
// mech.grabRange = mech.grabRange * 0.997 + (1350 + 150 * Math.cos(mech.cycle / 30)) * 0.003
|
||||||
// let gradient = ctx.createRadialGradient(this.pos.x, this.pos.y, 0, this.pos.x, this.pos.y, mech.grabRange);
|
// let gradient = ctx.createRadialGradient(this.pos.x, this.pos.y, 0, this.pos.x, this.pos.y, mech.grabRange);
|
||||||
// gradient.addColorStop(0, 'rgba(255,255,255,0.7)');
|
// gradient.addColorStop(0, 'rgba(255,255,255,0.7)');
|
||||||
// gradient.addColorStop(1, 'rgba(255,0,50,' + (0.6 + 0.2 * Math.random()) + ')');
|
// gradient.addColorStop(1, 'rgba(255,0,50,' + (0.6 + 0.2 * Math.random()) + ')');
|
||||||
@@ -1204,7 +1243,7 @@ const mech = {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// } else {
|
// } else {
|
||||||
// mech.fieldCDcycle = game.cycle + 120;
|
// mech.fieldCDcycle = mech.cycle + 120;
|
||||||
// }
|
// }
|
||||||
// } else {
|
// } else {
|
||||||
// mech.grabRange = 180;
|
// mech.grabRange = 180;
|
||||||
@@ -1212,7 +1251,7 @@ const mech = {
|
|||||||
// mech.grabPowerUp();
|
// mech.grabPowerUp();
|
||||||
// mech.lookForPickUp();
|
// mech.lookForPickUp();
|
||||||
// }
|
// }
|
||||||
// } else if (mech.holdingTarget && mech.fireCDcycle < game.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
// } else if (mech.holdingTarget && mech.fireCDcycle < mech.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
|
||||||
// mech.grabRange = 0
|
// mech.grabRange = 0
|
||||||
// mech.pickUp();
|
// mech.pickUp();
|
||||||
// } else {
|
// } else {
|
||||||
|
|||||||
111
js/spawn.js
111
js/spawn.js
@@ -602,58 +602,60 @@ const spawn = {
|
|||||||
// if (Math.random() < Math.min(0.2 + game.levelsCleared * 0.1, 0.7)) spawn.shield(me, x, y);
|
// if (Math.random() < Math.min(0.2 + game.levelsCleared * 0.1, 0.7)) spawn.shield(me, x, y);
|
||||||
me.do = function () {
|
me.do = function () {
|
||||||
this.healthBar();
|
this.healthBar();
|
||||||
this.seePlayerByLookingAt();
|
if (!mech.isBodiesAsleep) {
|
||||||
const dist2 = this.distanceToPlayer2();
|
this.seePlayerByLookingAt();
|
||||||
//laser Tracking
|
const dist2 = this.distanceToPlayer2();
|
||||||
if (this.seePlayer.yes && dist2 < 4000000 && !mech.isStealth) {
|
//laser Tracking
|
||||||
this.attraction();
|
if (this.seePlayer.yes && dist2 < 4000000 && !mech.isStealth) {
|
||||||
const rangeWidth = 2000; //this is sqrt of 4000000 from above if()
|
this.attraction();
|
||||||
//targeting laser will slowly move from the mob to the player's position
|
const rangeWidth = 2000; //this is sqrt of 4000000 from above if()
|
||||||
this.laserPos = Matter.Vector.add(this.laserPos, Matter.Vector.mult(Matter.Vector.sub(player.position, this.laserPos), 0.1));
|
//targeting laser will slowly move from the mob to the player's position
|
||||||
let targetDist = Matter.Vector.magnitude(Matter.Vector.sub(this.laserPos, mech.pos));
|
this.laserPos = Matter.Vector.add(this.laserPos, Matter.Vector.mult(Matter.Vector.sub(player.position, this.laserPos), 0.1));
|
||||||
const r = 10;
|
let targetDist = Matter.Vector.magnitude(Matter.Vector.sub(this.laserPos, mech.pos));
|
||||||
|
const r = 10;
|
||||||
|
|
||||||
// ctx.setLineDash([15, 200]);
|
// ctx.setLineDash([15, 200]);
|
||||||
// ctx.lineDashOffset = 20*(game.cycle % 215);
|
// ctx.lineDashOffset = 20*(game.cycle % 215);
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(this.position.x, this.position.y);
|
ctx.moveTo(this.position.x, this.position.y);
|
||||||
if (targetDist < r + 15) {
|
if (targetDist < r + 15) {
|
||||||
// || dist2 < 80000
|
// || dist2 < 80000
|
||||||
targetDist = r + 10;
|
targetDist = r + 10;
|
||||||
//charge at player
|
//charge at player
|
||||||
const forceMag = this.accelMag * 40 * this.mass;
|
const forceMag = this.accelMag * 40 * this.mass;
|
||||||
const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x);
|
const angle = Math.atan2(this.seePlayer.position.y - this.position.y, this.seePlayer.position.x - this.position.x);
|
||||||
this.force.x += forceMag * Math.cos(angle);
|
this.force.x += forceMag * Math.cos(angle);
|
||||||
this.force.y += forceMag * Math.sin(angle);
|
this.force.y += forceMag * Math.sin(angle);
|
||||||
|
} else {
|
||||||
|
//high friction if can't lock onto player
|
||||||
|
Matter.Body.setVelocity(this, {
|
||||||
|
x: this.velocity.x * 0.96,
|
||||||
|
y: this.velocity.y * 0.96
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (dist2 > 80000) {
|
||||||
|
const laserWidth = 0.002;
|
||||||
|
let laserOffR = Matter.Vector.rotateAbout(this.laserPos, (targetDist - r) * laserWidth, this.position);
|
||||||
|
let sub = Matter.Vector.normalise(Matter.Vector.sub(laserOffR, this.position));
|
||||||
|
laserOffR = Matter.Vector.add(laserOffR, Matter.Vector.mult(sub, rangeWidth));
|
||||||
|
ctx.lineTo(laserOffR.x, laserOffR.y);
|
||||||
|
|
||||||
|
let laserOffL = Matter.Vector.rotateAbout(this.laserPos, (targetDist - r) * -laserWidth, this.position);
|
||||||
|
sub = Matter.Vector.normalise(Matter.Vector.sub(laserOffL, this.position));
|
||||||
|
laserOffL = Matter.Vector.add(laserOffL, Matter.Vector.mult(sub, rangeWidth));
|
||||||
|
ctx.lineTo(laserOffL.x, laserOffL.y);
|
||||||
|
// ctx.fillStyle = "rgba(0,0,255,0.15)";
|
||||||
|
var gradient = ctx.createRadialGradient(this.position.x, this.position.y, 0, this.position.x, this.position.y, rangeWidth);
|
||||||
|
gradient.addColorStop(0, `rgba(0,0,255,${((r + 5) * (r + 5)) / (targetDist * targetDist)})`);
|
||||||
|
gradient.addColorStop(1, "transparent");
|
||||||
|
ctx.fillStyle = gradient;
|
||||||
|
ctx.fill();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//high friction if can't lock onto player
|
this.laserPos = this.position;
|
||||||
Matter.Body.setVelocity(this, {
|
|
||||||
x: this.velocity.x * 0.96,
|
|
||||||
y: this.velocity.y * 0.96
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (dist2 > 80000) {
|
};
|
||||||
const laserWidth = 0.002;
|
}
|
||||||
let laserOffR = Matter.Vector.rotateAbout(this.laserPos, (targetDist - r) * laserWidth, this.position);
|
|
||||||
let sub = Matter.Vector.normalise(Matter.Vector.sub(laserOffR, this.position));
|
|
||||||
laserOffR = Matter.Vector.add(laserOffR, Matter.Vector.mult(sub, rangeWidth));
|
|
||||||
ctx.lineTo(laserOffR.x, laserOffR.y);
|
|
||||||
|
|
||||||
let laserOffL = Matter.Vector.rotateAbout(this.laserPos, (targetDist - r) * -laserWidth, this.position);
|
|
||||||
sub = Matter.Vector.normalise(Matter.Vector.sub(laserOffL, this.position));
|
|
||||||
laserOffL = Matter.Vector.add(laserOffL, Matter.Vector.mult(sub, rangeWidth));
|
|
||||||
ctx.lineTo(laserOffL.x, laserOffL.y);
|
|
||||||
// ctx.fillStyle = "rgba(0,0,255,0.15)";
|
|
||||||
var gradient = ctx.createRadialGradient(this.position.x, this.position.y, 0, this.position.x, this.position.y, rangeWidth);
|
|
||||||
gradient.addColorStop(0, `rgba(0,0,255,${((r + 5) * (r + 5)) / (targetDist * targetDist)})`);
|
|
||||||
gradient.addColorStop(1, "transparent");
|
|
||||||
ctx.fillStyle = gradient;
|
|
||||||
ctx.fill();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.laserPos = this.position;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
laser(x, y, radius = 30) {
|
laser(x, y, radius = 30) {
|
||||||
//only on level 1
|
//only on level 1
|
||||||
@@ -706,14 +708,17 @@ const spawn = {
|
|||||||
me.collisionFilter.mask = 0x010111; //can't touch player
|
me.collisionFilter.mask = 0x010111; //can't touch player
|
||||||
// me.memory = 420;
|
// me.memory = 420;
|
||||||
me.do = function () {
|
me.do = function () {
|
||||||
|
|
||||||
this.seePlayerCheck();
|
this.seePlayerCheck();
|
||||||
this.attraction();
|
this.attraction();
|
||||||
this.gravity();
|
this.gravity();
|
||||||
//draw
|
//draw
|
||||||
if (this.seePlayer.yes) {
|
if (!mech.isBodiesAsleep) {
|
||||||
if (this.alpha < 1) this.alpha += 0.01;
|
if (this.seePlayer.yes) {
|
||||||
} else {
|
if (this.alpha < 1) this.alpha += 0.01;
|
||||||
if (this.alpha > 0) this.alpha -= 0.03;
|
} else {
|
||||||
|
if (this.alpha > 0) this.alpha -= 0.03;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (this.alpha > 0) {
|
if (this.alpha > 0) {
|
||||||
if (this.alpha > 0.95) {
|
if (this.alpha > 0.95) {
|
||||||
|
|||||||
Reference in New Issue
Block a user