mass energy mod, various bug fixes

This commit is contained in:
landgreen
2019-12-09 05:36:21 -08:00
committed by GitHub
parent 1aab11203c
commit e3022bea0c
8 changed files with 1141 additions and 1051 deletions

View File

@@ -25,6 +25,7 @@ const b = {
isModLowHealthDmg: null, isModLowHealthDmg: null,
isModFarAwayDmg: null, isModFarAwayDmg: null,
isModMonogamy: null, isModMonogamy: null,
isModMassEnergy: null,
setModDefaults() { setModDefaults() {
b.modCount = 0; b.modCount = 0;
b.modFireRate = 1; b.modFireRate = 1;
@@ -47,6 +48,7 @@ const b = {
b.isModLowHealthDmg = false; b.isModLowHealthDmg = false;
b.isModFarAwayDmg = false; b.isModFarAwayDmg = false;
b.isModMonogamy = false; b.isModMonogamy = false;
b.isModMassEnergy = false;
mech.Fx = 0.015; mech.Fx = 0.015;
mech.jumpForce = 0.38; mech.jumpForce = 0.38;
mech.throwChargeRate = 2; mech.throwChargeRate = 2;
@@ -116,7 +118,7 @@ const b = {
}, },
{ {
name: "zoospore vector", name: "zoospore vector",
description: "enemies can discharge <strong class='color-s'>spores</strong> on <strong>death</strong><br><strong class='color-s'>spores</strong> seek out enemies", description: "enemies can discharge <strong style='letter-spacing: 2px;'>spores</strong> on <strong>death</strong><br><strong style='letter-spacing: 2px;'>spores</strong> seek out enemies",
have: false, //7 have: false, //7
effect: () => { //good late game maybe? effect: () => { //good late game maybe?
b.modSpores = 0.20; b.modSpores = 0.20;
@@ -148,7 +150,7 @@ const b = {
}, },
{ {
name: "fluoroantimonic acid", name: "fluoroantimonic acid",
description: "each bullet does extra chemical <strong class='color-d'>damage</strong>", description: "each bullet does extra chemical <strong class='color-d'>damage</strong><br>instant damage, unaffected by momentum",
have: false, //11 have: false, //11
effect: () => { //good with guns that fire many bullets at low speeds, minigun, drones, junk-bots, shotgun, superballs, wavebeam effect: () => { //good with guns that fire many bullets at low speeds, minigun, drones, junk-bots, shotgun, superballs, wavebeam
b.modExtraDmg = 0.1 b.modExtraDmg = 0.1
@@ -156,7 +158,7 @@ const b = {
}, },
{ {
name: "annihilation", name: "annihilation",
description: "after <strong>touching</strong> enemies, they are annihilated", description: "after <strong>touching</strong> enemies, they are annihilated<br><em>doesn't trigger health or energy transfer</em>",
have: false, //12 have: false, //12
effect: () => { //good with mods that heal: superconductive healing, entropy transfer effect: () => { //good with mods that heal: superconductive healing, entropy transfer
b.modAnnihilation = true b.modAnnihilation = true
@@ -230,6 +232,14 @@ const b = {
b.isModMonogamy = true b.isModMonogamy = true
} }
}, },
{
name: "mass-energy equivalence",
description: "change the mass of <strong>power ups</strong> into <strong class='color-f'>energy</strong><br>power ups fill your <strong class='color-f'>energy</strong> and <strong class='color-h'>heal</strong> for +3%",
have: false, //21
effect: () => { // good with long term planning
b.isModMassEnergy = true // used in mech.usePowerUp
}
},
], ],
giveMod(i) { giveMod(i) {
b.mods[i].effect(); //give specific mod b.mods[i].effect(); //give specific mod
@@ -1044,7 +1054,7 @@ const b = {
name: "shotgun", //5 name: "shotgun", //5
description: "fire a <strong>burst</strong> of short range bullets<br><em>crouch to reduce recoil</em>", description: "fire a <strong>burst</strong> of short range bullets<br><em>crouch to reduce recoil</em>",
ammo: 0, ammo: 0,
ammoPack: 8, ammoPack: 9,
have: false, have: false,
isStarterGun: true, isStarterGun: true,
fire() { fire() {
@@ -1055,7 +1065,7 @@ const b = {
const me = bullet.length; const me = bullet.length;
const dir = mech.angle + (Math.random() - 0.5) * (mech.crouch ? 0.22 : 0.7) const dir = mech.angle + (Math.random() - 0.5) * (mech.crouch ? 0.22 : 0.7)
bullet[me] = Bodies.rectangle(mech.pos.x + 35 * Math.cos(mech.angle) + 15 * (Math.random() - 0.5), mech.pos.y + 35 * Math.sin(mech.angle) + 15 * (Math.random() - 0.5), side, side, b.fireAttributes(dir)); bullet[me] = Bodies.rectangle(mech.pos.x + 35 * Math.cos(mech.angle) + 15 * (Math.random() - 0.5), mech.pos.y + 35 * Math.sin(mech.angle) + 15 * (Math.random() - 0.5), side, side, b.fireAttributes(dir));
b.fireProps(mech.crouch ? 60 : 30, 40 + Math.random() * 11, dir, me); //cd , speed b.fireProps(mech.crouch ? 65 : 45, 40 + Math.random() * 11, dir, me); //cd , speed
bullet[me].endCycle = game.cycle + Math.floor(55 * b.isModBulletsLastLonger); bullet[me].endCycle = game.cycle + Math.floor(55 * b.isModBulletsLastLonger);
bullet[me].frictionAir = 0.03; bullet[me].frictionAir = 0.03;
bullet[me].do = function () { bullet[me].do = function () {
@@ -1070,7 +1080,7 @@ const b = {
} }
}, { }, {
name: "fléchettes", //6 name: "fléchettes", //6
description: "fire a flight of needles<br><strong>accurate</strong> at long range", description: "fire a flight of long range needles",
ammo: 0, ammo: 0,
ammoPack: 25, ammoPack: 25,
have: false, have: false,
@@ -1218,9 +1228,9 @@ const b = {
fire() { fire() {
b.muzzleFlash(30); b.muzzleFlash(30);
const totalBullets = 5 const totalBullets = 5
const angleStep = (mech.crouch ? 0.06 : 0.15) / totalBullets const angleStep = (mech.crouch ? 0.06 : 0.25) / totalBullets
const SPEED = mech.crouch ? 30 : 25 const SPEED = mech.crouch ? 29 : 25
const CD = mech.crouch ? 45 : 11 const CD = mech.crouch ? 30 : 11
const END = Math.floor((mech.crouch ? 30 : 18) * b.isModBulletsLastLonger); const END = Math.floor((mech.crouch ? 30 : 18) * b.isModBulletsLastLonger);
let dir = mech.angle - angleStep * totalBullets / 2; let dir = mech.angle - angleStep * totalBullets / 2;
const side1 = 17 * b.modBulletSize const side1 = 17 * b.modBulletSize
@@ -1236,7 +1246,7 @@ const b = {
bullet[me].restitution = 0; bullet[me].restitution = 0;
bullet[me].friction = 1; bullet[me].friction = 1;
// bullet[me].dmg = 0.15; // bullet[me].dmg = 0.15;
bullet[me].explodeRad = (mech.crouch ? 70 : 45) + (Math.random() - 0.5) * 50; bullet[me].explodeRad = (mech.crouch ? 70 : 50) + (Math.random() - 0.5) * 50;
bullet[me].onEnd = b.explode; bullet[me].onEnd = b.explode;
bullet[me].onDmg = function () { bullet[me].onDmg = function () {
this.endCycle = 0; //bullet ends cycle after hitting a mob and triggers explosion this.endCycle = 0; //bullet ends cycle after hitting a mob and triggers explosion
@@ -1461,7 +1471,7 @@ const b = {
} }
}, { }, {
name: "spores", //12 name: "spores", //12
description: "fire orbs that discharge <strong class='color-s'>spores</strong><br><strong class='color-s'>spores</strong> seek out enemies", description: "fire orbs that discharge <strong style='letter-spacing: 2px;'>spores</strong><br><strong style='letter-spacing: 2px;'>spores</strong> seek out enemies",
ammo: 0, ammo: 0,
ammoPack: 5, ammoPack: 5,
have: false, have: false,
@@ -1677,17 +1687,16 @@ const b = {
fire() { fire() {
const dir = mech.angle; const dir = mech.angle;
const me = bullet.length; const me = bullet.length;
const RADIUS = (22 + 5 * Math.random()) * b.modBulletSize const RADIUS = (13 + 10 * Math.random()) * b.modBulletSize //(22 + 10 * Math.random()) * b.modBulletSize
const LENGTH = 0.7 + Math.random() bullet[me] = Bodies.polygon(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 3, RADIUS, {
bullet[me] = Bodies.rectangle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), RADIUS * LENGTH, RADIUS / LENGTH, {
angle: dir, angle: dir,
friction: 0, friction: 0,
frictionStatic: 0, frictionStatic: 0,
restitution: 0.8, restitution: 0.5 + 0.5 * Math.random(),
dmg: b.modExtraDmg, // 0.14 //damage done in addition to the damage from momentum dmg: b.modExtraDmg, // 0.14 //damage done in addition to the damage from momentum
minDmgSpeed: 2, minDmgSpeed: 2,
lookFrequency: 37 + Math.floor(27 * Math.random()), lookFrequency: 37 + Math.floor(27 * Math.random()),
acceleration: 0.0015 + 0.0013 * Math.random(),
range: 500 + Math.floor(200 * Math.random()), range: 500 + Math.floor(200 * Math.random()),
endCycle: Infinity, endCycle: Infinity,
classType: "bullet", classType: "bullet",
@@ -1705,8 +1714,7 @@ const b = {
this.lockedOn = null; this.lockedOn = null;
let closeDist = this.range; let closeDist = this.range;
for (let i = 0, len = mob.length; i < len; ++i) { for (let i = 0, len = mob.length; i < len; ++i) {
const TARGET_VECTOR = Matter.Vector.sub(this.vertices[0], mob[i].position) const DIST = Matter.Vector.magnitude(Matter.Vector.sub(this.vertices[0], mob[i].position));
const DIST = Matter.Vector.magnitude(TARGET_VECTOR);
if (DIST - mob[i].radius < closeDist && if (DIST - mob[i].radius < closeDist &&
Matter.Query.ray(map, this.vertices[0], mob[i].position).length === 0 && Matter.Query.ray(map, this.vertices[0], mob[i].position).length === 0 &&
Matter.Query.ray(body, this.vertices[0], mob[i].position).length === 0) { Matter.Query.ray(body, this.vertices[0], mob[i].position).length === 0) {
@@ -1716,13 +1724,12 @@ const b = {
} }
} }
const FIELD_DRAIN = 0.001 const FIELD_DRAIN = 0.0016
if (this.lockedOn && this.lockedOn.alive && mech.fieldMeter > FIELD_DRAIN) { //hit target with laser if (this.lockedOn && this.lockedOn.alive && mech.fieldMeter > FIELD_DRAIN) { //hit target with laser
mech.fieldMeter -= FIELD_DRAIN mech.fieldMeter -= FIELD_DRAIN
//make sure you can still see target //make sure you can still see target
const TARGET_VECTOR = Matter.Vector.sub(this.vertices[0], this.lockedOn.position) const DIST = Matter.Vector.magnitude(Matter.Vector.sub(this.vertices[0], this.lockedOn.position));
const DIST = Matter.Vector.magnitude(TARGET_VECTOR);
if (DIST - this.lockedOn.radius < this.range + 150 && if (DIST - this.lockedOn.radius < this.range + 150 &&
Matter.Query.ray(map, this.vertices[0], this.lockedOn.position).length === 0 && Matter.Query.ray(map, this.vertices[0], this.lockedOn.position).length === 0 &&
Matter.Query.ray(body, this.vertices[0], this.lockedOn.position).length === 0) { Matter.Query.ray(body, this.vertices[0], this.lockedOn.position).length === 0) {
@@ -1744,7 +1751,7 @@ const b = {
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(this.vertices[0].x, this.vertices[0].y); ctx.moveTo(this.vertices[0].x, this.vertices[0].y);
ctx.lineTo(this.lockedOn.vertices[bestVertex].x, this.lockedOn.vertices[bestVertex].y); ctx.lineTo(this.lockedOn.vertices[bestVertex].x, this.lockedOn.vertices[bestVertex].y);
ctx.strokeStyle = "rgb(255,0,40)"; ctx.strokeStyle = "#f00";
ctx.lineWidth = "2" ctx.lineWidth = "2"
ctx.lineDashOffset = 300 * Math.random() ctx.lineDashOffset = 300 * Math.random()
ctx.setLineDash([50 + 100 * Math.random(), 100 * Math.random()]); ctx.setLineDash([50 + 100 * Math.random(), 100 * Math.random()]);
@@ -1752,17 +1759,19 @@ const b = {
ctx.setLineDash([0, 0]); ctx.setLineDash([0, 0]);
ctx.beginPath(); ctx.beginPath();
ctx.arc(this.lockedOn.vertices[bestVertex].x, this.lockedOn.vertices[bestVertex].y, Math.sqrt(dmg) * 100, 0, 2 * Math.PI); ctx.arc(this.lockedOn.vertices[bestVertex].x, this.lockedOn.vertices[bestVertex].y, Math.sqrt(dmg) * 100, 0, 2 * Math.PI);
ctx.fillStyle = "rgba(255,0,40,0.7)" //"#f00" ctx.fillStyle = "#f00";
ctx.fill(); ctx.fill();
} }
} }
const distanceToPlayer = Matter.Vector.magnitude(Matter.Vector.sub(this.position, mech.pos)) const distanceToPlayer = Matter.Vector.magnitude(Matter.Vector.sub(this.position, mech.pos))
if (distanceToPlayer > this.range * 0.2) { //if far away move towards player if (distanceToPlayer > this.range * 0.2) { //if far away move towards player
this.force = Matter.Vector.mult(Matter.Vector.normalise(Matter.Vector.sub(mech.pos, this.position)), this.mass * 0.002) this.force = Matter.Vector.mult(Matter.Vector.normalise(Matter.Vector.sub(mech.pos, this.position)), this.mass * this.acceleration)
this.frictionAir = 0.02 this.frictionAir = 0.02
} else { //close to player } else { //close to player
this.frictionAir = 0 this.frictionAir = 0
//add player's velocity
Matter.Body.setVelocity(this, Matter.Vector.add(Matter.Vector.mult(this.velocity, 1), Matter.Vector.mult(player.velocity, 0.02)));
} }
} }
}) })

View File

@@ -201,6 +201,7 @@ const game = {
} }
}, },
switchGun() { switchGun() {
if (b.modNoAmmo) b.modNoAmmo = 1 //this prevents hacking the mod by switching guns
b.activeGun = b.inventory[b.inventoryGun]; b.activeGun = b.inventory[b.inventoryGun];
game.updateGunHUD(); game.updateGunHUD();
game.boldActiveGunHUD(); game.boldActiveGunHUD();

View File

@@ -15,8 +15,8 @@ const level = {
if (level.levelsCleared === 0) { if (level.levelsCleared === 0) {
// game.difficulty = 6; //for testing to simulate possible mobs spawns // game.difficulty = 6; //for testing to simulate possible mobs spawns
// b.giveGuns(14) // b.giveGuns(14)
// mech.fieldUpgrades[2].effect(); // mech.fieldUpgrades[7].effect();
// b.giveMod(5) // b.giveMod(2)
this.intro(); //starting level this.intro(); //starting level
// this.testingMap(); // this.testingMap();
@@ -107,11 +107,11 @@ const level = {
// spawn.bodyRect(-135, -50, 50, 50); // spawn.bodyRect(-135, -50, 50, 50);
// spawn.bodyRect(-140, -100, 50, 50); // spawn.bodyRect(-140, -100, 50, 50);
// powerUps.spawn(420, -400, "ammo", false); // powerUps.spawn(420, -400, "ammo", false);
powerUps.spawn(450, -400, "mod", false, 6); // powerUps.spawn(450, -400, "mod", false, 6);
// powerUps.spawn(450, -400, "mod", false); // powerUps.spawn(450, -400, "mod", false);
// spawn.bodyRect(-45, -100, 40, 50); // spawn.bodyRect(-45, -100, 40, 50);
spawn.spawner(800, -1150); spawn.spinner(800, -1150);
spawn.groupBoss(-600, -550); // spawn.groupBoss(-600, -550);
// spawn.hopper(800, -150); // spawn.hopper(800, -150);
// spawn.beamer(800, -150); // spawn.beamer(800, -150);
// spawn.grower(800, -250); // spawn.grower(800, -250);

View File

@@ -225,11 +225,34 @@ const mobs = {
// ctx.stroke(); // ctx.stroke();
// return targetPos; // return targetPos;
}, },
hacked() { //set this.hackedTarget variable before running this method
//find a new target
if (!(game.cycle % this.seePlayerFreq)) {
this.hackedTarget = null
for (let i = 0, len = mob.length; i < len; i++) {
if (mob[i] !== this) {
// const DIST = Matter.Vector.magnitude(Matter.Vector.sub(this.position, mob[j]));
if (Matter.Query.ray(map, this.position, mob[i].position).length === 0 &&
Matter.Query.ray(body, this.position, mob[i].position).length === 0) {
this.hackedTarget = mob[i]
}
}
}
}
//acceleration towards targets
if (this.hackedTarget) {
this.force = Matter.Vector.mult(Matter.Vector.normalise(Matter.Vector.sub(this.hackedTarget.position, this.position)), this.mass * 0.0015)
}
},
laserBeam() { laserBeam() {
if (game.cycle % 7 && this.seePlayer.yes) { if (game.cycle % 7 && this.seePlayer.yes) {
ctx.setLineDash([125 * Math.random(), 125 * Math.random()]); ctx.setLineDash([125 * Math.random(), 125 * Math.random()]);
// ctx.lineDashOffset = 6*(game.cycle % 215); // ctx.lineDashOffset = 6*(game.cycle % 215);
if (this.distanceToPlayer() < this.laserRange) { if (this.distanceToPlayer() < this.laserRange && !mech.isStealth) {
//if (Math.random()>0.2 && this.seePlayer.yes && this.distanceToPlayer2()<800000) { //if (Math.random()>0.2 && this.seePlayer.yes && this.distanceToPlayer2()<800000) {
if (b.isModTempResist) { if (b.isModTempResist) {
mech.damage(0.00006 * game.dmgScale); mech.damage(0.00006 * game.dmgScale);
@@ -320,7 +343,7 @@ const mobs = {
}; };
vertexCollision(this.position, look, map); vertexCollision(this.position, look, map);
vertexCollision(this.position, look, body); vertexCollision(this.position, look, body);
vertexCollision(this.position, look, [player]); if (!mech.isStealth) vertexCollision(this.position, look, [player]);
// hitting player // hitting player
if (best.who === player) { if (best.who === player) {
if (b.isModTempResist) { if (b.isModTempResist) {

View File

@@ -517,6 +517,10 @@ const mech = {
powerUp[i].effect(); powerUp[i].effect();
Matter.World.remove(engine.world, powerUp[i]); Matter.World.remove(engine.world, powerUp[i]);
powerUp.splice(i, 1); powerUp.splice(i, 1);
if (b.isModMassEnergy) {
mech.fieldMeter = 1;
mech.addHealth(0.03);
}
}, },
drawLeg(stroke) { drawLeg(stroke) {
// if (game.mouseInGame.x > this.pos.x) { // if (game.mouseInGame.x > this.pos.x) {
@@ -1512,5 +1516,75 @@ const mech = {
} }
} }
}, },
// {
// name: "code injection field",
// description: "capture an enemy in your field for 3 seconds<br>rewrite thier behavior to target your enemies",
// effect: () => {
// mech.fieldMode = 7;
// mech.fieldText();
// mech.setHoldDefaults();
// mech.hackProgress = 0;
// // mech.grabRange = 230
// mech.hold = function () {
// mech.isStealth = false //isStealth is checked in mob foundPlayer()
// player.collisionFilter.mask = 0x010011 //0x010011 is normal
// if (mech.isHolding) {
// mech.hackProgress = 0
// mech.drawHold(mech.holdingTarget);
// mech.holding();
// mech.throw();
// } else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) {
// const DRAIN = 0.0005
// if (mech.fieldMeter > DRAIN) {
// mech.fieldMeter -= DRAIN;
// //try to hack a mob
// for (let i = 0, len = mob.length; i < len; ++i) {
// if (
// Matter.Vector.magnitude(Matter.Vector.sub(mob[i].position, this.pos)) < this.grabRange &&
// this.lookingAt(mob[i]) &&
// Matter.Query.ray(map, mob[i].position, this.pos).length === 0
// ) {
// if (mech.hackProgress > 180) { //hack the mob
// mech.fieldMeter = 0;
// mob[i].hackedTarget = null;
// mob[i].seePlayerFreq = Math.round((30 + 30 * Math.random()) * game.lookFreqScale)
// mob[i].do = function () {
// this.healthBar();
// this.hacked();
// }
// } else { //hold the mob still
// mech.hackProgress++
// range = this.grabRange * 0.9
// Matter.Body.setPosition(mob[i], {
// x: mech.pos.x + range * Math.cos(mech.angle),
// y: mech.pos.y + range * Math.sin(mech.angle),
// });
// Matter.Body.setVelocity(mob[i], player.velocity);
// }
// }
// }
// mech.pushBodyFacing();
// mech.drawField();
// mech.grabPowerUp();
// mech.lookForPickUp();
// } else {
// mech.hackProgress = 0
// mech.fieldCDcycle = mech.cycle + 120;
// }
// } else if (mech.holdingTarget && mech.fireCDcycle < mech.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
// mech.pickUp();
// mech.hackProgress = 0
// } else {
// mech.hackProgress = 0
// 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()
// }
// }
// },
], ],
}; };

View File

@@ -12,14 +12,13 @@ const spawn = {
"beamer", "beamer",
"focuser", "focuser",
"laser", "laser", "laser", "laser",
// "blinker", //make blinker a boss
"sucker", "sucker",
"exploder", "exploder", "exploder", "exploder", "exploder", "exploder",
"spawner", "spawner",
"ghoster", "ghoster",
"sneaker", "sneaker",
], ],
allowedBossList: ["chaser", "spinner", "striker", "springer", "laser", "focuser", "beamer", "exploder", "spawner", "shooter"], //"zoomer", allowedBossList: ["chaser", "spinner", "striker", "springer", "laser", "focuser", "beamer", "exploder", "spawner", "shooter"],
setSpawnList() { setSpawnList() {
//this is run at the start of each new level to determine the possible mobs for the level //this is run at the start of each new level to determine the possible mobs for the level
//each level has 2 mobs: one new mob and one from the last level //each level has 2 mobs: one new mob and one from the last level
@@ -132,6 +131,7 @@ const spawn = {
let me = mob[mob.length - 1]; let me = mob[mob.length - 1];
me.accelMag = 0.0005 * game.accelScale; me.accelMag = 0.0005 * game.accelScale;
me.memory = 60; me.memory = 60;
me.seeAtDistance2 = 1400000 //1200 vision range
Matter.Body.setDensity(me, 0.0005) // normal density is 0.001 // this reduces life by half and decreases knockback Matter.Body.setDensity(me, 0.0005) // normal density is 0.001 // this reduces life by half and decreases knockback
me.do = function () { me.do = function () {
@@ -140,92 +140,92 @@ const spawn = {
this.attraction(); this.attraction();
}; };
}, },
healer(x, y, radius = 20) { // healer(x, y, radius = 20) {
mobs.spawn(x, y, 3, radius, "rgba(50,255,200,0.4)"); // mobs.spawn(x, y, 3, radius, "rgba(50,255,200,0.4)");
let me = mob[mob.length - 1]; // let me = mob[mob.length - 1];
me.frictionAir = 0.02; // me.frictionAir = 0.02;
me.accelMag = 0.0004 * game.accelScale; // me.accelMag = 0.0004 * game.accelScale;
if (map.length) me.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; //required for search // if (map.length) me.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; //required for search
me.lookFrequency = 160 + Math.floor(57 * Math.random()) // me.lookFrequency = 160 + Math.floor(57 * Math.random())
me.lockedOn = null; // me.lockedOn = null;
Matter.Body.setDensity(me, 0.003) // normal density is 0.001 // Matter.Body.setDensity(me, 0.003) // normal density is 0.001
me.do = function () { // me.do = function () {
this.healthBar(); // this.healthBar();
if (!(game.cycle % this.lookFrequency)) { // if (!(game.cycle % this.lookFrequency)) {
//slow self heal // //slow self heal
this.health += 0.02; // this.health += 0.02;
if (this.health > 1) this.health = 1; // if (this.health > 1) this.health = 1;
//target mobs with low health // //target mobs with low health
let closeDist = Infinity; // let closeDist = Infinity;
for (let i = 0; i < mob.length; i++) { // for (let i = 0; i < mob.length; i++) {
if (mob[i] != this && Matter.Query.ray(map, this.position, mob[i].position).length === 0) { // if (mob[i] != this && Matter.Query.ray(map, this.position, mob[i].position).length === 0) {
const TARGET_VECTOR = Matter.Vector.sub(this.position, mob[i].position) // const TARGET_VECTOR = Matter.Vector.sub(this.position, mob[i].position)
const DIST = Matter.Vector.magnitude(TARGET_VECTOR) * mob[i].health * mob[i].health * mob[i].health; //distance is multiplied by mob health to prioritize low health mobs // const DIST = Matter.Vector.magnitude(TARGET_VECTOR) * mob[i].health * mob[i].health * mob[i].health; //distance is multiplied by mob health to prioritize low health mobs
if (DIST < closeDist) { // if (DIST < closeDist) {
closeDist = DIST; // closeDist = DIST;
this.lockedOn = mob[i] // this.lockedOn = mob[i]
} // }
} // }
} // }
} // }
//move away from player if too close // //move away from player if too close
if (this.distanceToPlayer2() < 400000) { // if (this.distanceToPlayer2() < 400000) {
const TARGET_VECTOR = Matter.Vector.sub(this.position, player.position) // const TARGET_VECTOR = Matter.Vector.sub(this.position, player.position)
this.force = Matter.Vector.mult(Matter.Vector.normalise(TARGET_VECTOR), this.mass * this.accelMag * 1.4) // this.force = Matter.Vector.mult(Matter.Vector.normalise(TARGET_VECTOR), this.mass * this.accelMag * 1.4)
if (this.lockedOn) this.lockedOn = null // if (this.lockedOn) this.lockedOn = null
} else if (this.lockedOn && this.lockedOn.alive) { // } else if (this.lockedOn && this.lockedOn.alive) {
//move towards and heal locked on target // //move towards and heal locked on target
const TARGET_VECTOR = Matter.Vector.sub(this.position, this.lockedOn.position) // const TARGET_VECTOR = Matter.Vector.sub(this.position, this.lockedOn.position)
const DIST = Matter.Vector.magnitude(TARGET_VECTOR); // const DIST = Matter.Vector.magnitude(TARGET_VECTOR);
if (DIST > 250) { // if (DIST > 250) {
this.force = Matter.Vector.mult(Matter.Vector.normalise(TARGET_VECTOR), -this.mass * this.accelMag) // this.force = Matter.Vector.mult(Matter.Vector.normalise(TARGET_VECTOR), -this.mass * this.accelMag)
} else { // } else {
if (this.lockedOn.health < 1) { // if (this.lockedOn.health < 1) {
this.lockedOn.health += 0.002; // this.lockedOn.health += 0.002;
if (this.lockedOn.health > 1) this.lockedOn.health = 1; // if (this.lockedOn.health > 1) this.lockedOn.health = 1;
//spin when healing // //spin when healing
this.torque = 0.000005 * this.inertia; // this.torque = 0.000005 * this.inertia;
//draw heal // //draw heal
ctx.beginPath(); // ctx.beginPath();
ctx.moveTo(this.position.x, this.position.y); // ctx.moveTo(this.position.x, this.position.y);
ctx.lineTo(this.lockedOn.position.x, this.lockedOn.position.y); // ctx.lineTo(this.lockedOn.position.x, this.lockedOn.position.y);
ctx.lineWidth = 10 // ctx.lineWidth = 10
ctx.strokeStyle = "rgba(50,255,200,0.4)" // ctx.strokeStyle = "rgba(50,255,200,0.4)"
ctx.stroke(); // ctx.stroke();
} // }
} // }
} else { // } else {
//wander if no heal targets visible // //wander if no heal targets visible
//be sure to declare searchTarget in mob spawn // //be sure to declare searchTarget in mob spawn
const newTarget = function (that) { // const newTarget = function (that) {
that.searchTarget = mob[Math.floor(Math.random() * (mob.length - 1))].position; // that.searchTarget = mob[Math.floor(Math.random() * (mob.length - 1))].position;
}; // };
const sub = Matter.Vector.sub(this.searchTarget, this.position); // const sub = Matter.Vector.sub(this.searchTarget, this.position);
if (Matter.Vector.magnitude(sub) > this.radius * 2) { // if (Matter.Vector.magnitude(sub) > this.radius * 2) {
ctx.beginPath(); // ctx.beginPath();
ctx.strokeStyle = "#aaa"; // ctx.strokeStyle = "#aaa";
ctx.moveTo(this.position.x, this.position.y); // ctx.moveTo(this.position.x, this.position.y);
ctx.lineTo(this.searchTarget.x, this.searchTarget.y); // ctx.lineTo(this.searchTarget.x, this.searchTarget.y);
ctx.stroke(); // ctx.stroke();
//accelerate at 0.6 of normal acceleration // //accelerate at 0.6 of normal acceleration
this.force = Matter.Vector.mult(Matter.Vector.normalise(sub), this.accelMag * this.mass * 0.6); // this.force = Matter.Vector.mult(Matter.Vector.normalise(sub), this.accelMag * this.mass * 0.6);
} else { // } else {
//after reaching random target switch to new target // //after reaching random target switch to new target
newTarget(this); // newTarget(this);
} // }
//switch to a new target after a while // //switch to a new target after a while
if (!(game.cycle % (this.lookFrequency * 15))) { // if (!(game.cycle % (this.lookFrequency * 15))) {
newTarget(this); // newTarget(this);
} // }
} // }
}; // };
}, // },
chaser(x, y, radius = 35 + Math.ceil(Math.random() * 40)) { chaser(x, y, radius = 35 + Math.ceil(Math.random() * 40)) {
mobs.spawn(x, y, 8, radius, "#2c9790"); mobs.spawn(x, y, 8, radius, "#2c9790");
let me = mob[mob.length - 1]; let me = mob[mob.length - 1];
@@ -304,27 +304,27 @@ const spawn = {
this.searchSpring(); this.searchSpring();
}; };
}, },
zoomer(x, y, radius = 20 + Math.ceil(Math.random() * 30)) { // zoomer(x, y, radius = 20 + Math.ceil(Math.random() * 30)) {
mobs.spawn(x, y, 6, radius, "#ffe2fd"); // mobs.spawn(x, y, 6, radius, "#ffe2fd");
let me = mob[mob.length - 1]; // let me = mob[mob.length - 1];
me.trailLength = 20; //required for trails // me.trailLength = 20; //required for trails
me.setupTrail(); //fill trails array up with the current position of mob // me.setupTrail(); //fill trails array up with the current position of mob
me.trailFill = "#ff00f0"; // me.trailFill = "#ff00f0";
me.g = 0.001; //required if using 'gravity' // me.g = 0.001; //required if using 'gravity'
me.frictionAir = 0.02; // me.frictionAir = 0.02;
me.accelMag = 0.004 * game.accelScale; // me.accelMag = 0.004 * game.accelScale;
me.memory = 30; // me.memory = 30;
me.zoomMode = 150; // me.zoomMode = 150;
me.onHit = function () { // me.onHit = function () {
this.zoomMode = 150; // this.zoomMode = 150;
}; // };
me.do = function () { // me.do = function () {
this.healthBar(); // this.healthBar();
this.seePlayerByDistAndLOS(); // this.seePlayerByDistAndLOS();
this.zoom(); // this.zoom();
this.gravity(); // this.gravity();
}; // };
}, // },
hopper(x, y, radius = 30 + Math.ceil(Math.random() * 30)) { hopper(x, y, radius = 30 + Math.ceil(Math.random() * 30)) {
mobs.spawn(x, y, 5, radius, "rgb(0,200,180)"); mobs.spawn(x, y, 5, radius, "rgb(0,200,180)");
let me = mob[mob.length - 1]; let me = mob[mob.length - 1];
@@ -388,12 +388,9 @@ const spawn = {
hue: "blue" hue: "blue"
}); });
//draw attack vector //draw attack vector
const mag = this.radius * 2 + 200; const mag = this.radius * 2.5 + 50;
const gradient = ctx.createRadialGradient(this.position.x, this.position.y, 0, this.position.x, this.position.y, mag); ctx.strokeStyle = "rgba(0,0,0,0.2)";
gradient.addColorStop(0, "rgba(0,0,0,0.2)"); ctx.lineWidth = 3;
gradient.addColorStop(1, "transparent");
ctx.strokeStyle = gradient;
ctx.lineWidth = 5;
ctx.setLineDash([10, 20]); //30 ctx.setLineDash([10, 20]); //30
const dir = Matter.Vector.add(this.position, Matter.Vector.mult(this.burstDir, mag)); const dir = Matter.Vector.add(this.position, Matter.Vector.mult(this.burstDir, mag));
ctx.beginPath(); ctx.beginPath();
@@ -455,7 +452,7 @@ const spawn = {
this.healthBar(); this.healthBar();
//when player is inside event horizon //when player is inside event horizon
if (Matter.Vector.magnitude(Matter.Vector.sub(this.position, player.position)) < eventHorizon) { if (Matter.Vector.magnitude(Matter.Vector.sub(this.position, player.position)) < eventHorizon && !mech.isStealth) {
mech.damage(0.00015 * game.dmgScale); mech.damage(0.00015 * game.dmgScale);
if (mech.fieldMeter > 0.1) mech.fieldMeter -= 0.007 if (mech.fieldMeter > 0.1) mech.fieldMeter -= 0.007
@@ -545,7 +542,7 @@ const spawn = {
ctx.fillStyle = "rgba(0,0,0,0.05)"; ctx.fillStyle = "rgba(0,0,0,0.05)";
ctx.fill(); ctx.fill();
//when player is inside event horizon //when player is inside event horizon
if (Matter.Vector.magnitude(Matter.Vector.sub(this.position, player.position)) < eventHorizon) { if (Matter.Vector.magnitude(Matter.Vector.sub(this.position, player.position)) < eventHorizon && !mech.isStealth) {
mech.damage(0.00015 * game.dmgScale); mech.damage(0.00015 * game.dmgScale);
if (mech.fieldMeter > 0.1) mech.fieldMeter -= 0.007 if (mech.fieldMeter > 0.1) mech.fieldMeter -= 0.007
const angle = Math.atan2(player.position.y - this.position.y, player.position.x - this.position.x); const angle = Math.atan2(player.position.y - this.position.y, player.position.x - this.position.x);
@@ -614,13 +611,9 @@ const spawn = {
this.laserPos = Matter.Vector.add(this.laserPos, Matter.Vector.mult(Matter.Vector.sub(player.position, this.laserPos), 0.1)); this.laserPos = Matter.Vector.add(this.laserPos, Matter.Vector.mult(Matter.Vector.sub(player.position, this.laserPos), 0.1));
let targetDist = Matter.Vector.magnitude(Matter.Vector.sub(this.laserPos, mech.pos)); let targetDist = Matter.Vector.magnitude(Matter.Vector.sub(this.laserPos, mech.pos));
const r = 10; const r = 10;
// ctx.setLineDash([15, 200]);
// 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
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;
@@ -645,11 +638,7 @@ const spawn = {
sub = Matter.Vector.normalise(Matter.Vector.sub(laserOffL, this.position)); sub = Matter.Vector.normalise(Matter.Vector.sub(laserOffL, this.position));
laserOffL = Matter.Vector.add(laserOffL, Matter.Vector.mult(sub, rangeWidth)); laserOffL = Matter.Vector.add(laserOffL, Matter.Vector.mult(sub, rangeWidth));
ctx.lineTo(laserOffL.x, laserOffL.y); ctx.lineTo(laserOffL.x, laserOffL.y);
// ctx.fillStyle = "rgba(0,0,255,0.15)"; ctx.fillStyle = `rgba(0,0,255,${Math.max(0,0.3*r/targetDist)})`
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(); ctx.fill();
} }
} else { } else {
@@ -801,46 +790,46 @@ const spawn = {
} }
}; };
}, },
blinker(x, y, radius = 45 + Math.ceil(Math.random() * 70)) { // blinker(x, y, radius = 45 + Math.ceil(Math.random() * 70)) {
mobs.spawn(x, y, 6, radius, "transparent"); // mobs.spawn(x, y, 6, radius, "transparent");
let me = mob[mob.length - 1]; // let me = mob[mob.length - 1];
Matter.Body.setDensity(me, 0.0005); //normal is 0.001 //makes effective life much lower // Matter.Body.setDensity(me, 0.0005); //normal is 0.001 //makes effective life much lower
me.stroke = "rgb(0,200,255)"; //used for drawGhost // me.stroke = "rgb(0,200,255)"; //used for drawGhost
Matter.Body.rotate(me, Math.random() * 2 * Math.PI); // Matter.Body.rotate(me, Math.random() * 2 * Math.PI);
me.blinkRate = 40 + Math.round(Math.random() * 60); //required for blink // me.blinkRate = 40 + Math.round(Math.random() * 60); //required for blink
me.blinkLength = 150 + Math.round(Math.random() * 200); //required for blink // me.blinkLength = 150 + Math.round(Math.random() * 200); //required for blink
me.isStatic = true; // me.isStatic = true;
me.memory = 360; // me.memory = 360;
me.seePlayerFreq = Math.round((40 + 30 * Math.random()) * game.lookFreqScale); // me.seePlayerFreq = Math.round((40 + 30 * Math.random()) * game.lookFreqScale);
me.isBig = false; // me.isBig = false;
me.scaleMag = Math.max(5 - me.mass, 1.75); // me.scaleMag = Math.max(5 - me.mass, 1.75);
me.onDeath = function () { // me.onDeath = function () {
if (this.isBig) { // if (this.isBig) {
Matter.Body.scale(this, 1 / this.scaleMag, 1 / this.scaleMag); // Matter.Body.scale(this, 1 / this.scaleMag, 1 / this.scaleMag);
this.isBig = false; // this.isBig = false;
} // }
}; // };
me.do = function () { // me.do = function () {
this.healthBar(); // this.healthBar();
this.seePlayerCheck(); // this.seePlayerCheck();
this.blink(); // this.blink();
//strike by expanding // //strike by expanding
if (this.isBig) { // if (this.isBig) {
if (this.cd - this.delay + 15 < game.cycle) { // if (this.cd - this.delay + 15 < game.cycle) {
Matter.Body.scale(this, 1 / this.scaleMag, 1 / this.scaleMag); // Matter.Body.scale(this, 1 / this.scaleMag, 1 / this.scaleMag);
this.isBig = false; // this.isBig = false;
} // }
} else if (this.seePlayer.yes && this.cd < game.cycle) { // } else if (this.seePlayer.yes && this.cd < game.cycle) {
const dist = Matter.Vector.sub(this.seePlayer.position, this.position); // const dist = Matter.Vector.sub(this.seePlayer.position, this.position);
const distMag2 = Matter.Vector.magnitudeSquared(dist); // const distMag2 = Matter.Vector.magnitudeSquared(dist);
if (distMag2 < 80000) { // if (distMag2 < 80000) {
this.cd = game.cycle + this.delay; // this.cd = game.cycle + this.delay;
Matter.Body.scale(this, this.scaleMag, this.scaleMag); // Matter.Body.scale(this, this.scaleMag, this.scaleMag);
this.isBig = true; // this.isBig = true;
} // }
} // }
}; // };
}, // },
bomber(x, y, radius = 120 + Math.ceil(Math.random() * 70)) { bomber(x, y, radius = 120 + Math.ceil(Math.random() * 70)) {
//boss that drops bombs from above and holds a set distance from player //boss that drops bombs from above and holds a set distance from player
mobs.spawn(x, y, 3, radius, "transparent"); mobs.spawn(x, y, 3, radius, "transparent");

View File

@@ -307,12 +307,6 @@ em {
letter-spacing: 1px; letter-spacing: 1px;
} }
.color-s {
color: #055;
font-weight: 900;
letter-spacing: 2px;
}
.faded { .faded {
opacity: 0.7; opacity: 0.7;
font-size: 90%; font-size: 90%;