switch body to have its own collisiosn catagory, also made stealth field pass thorugh bodies and mobs

This commit is contained in:
landgreen
2019-10-05 10:51:15 -07:00
parent 0a834d87a7
commit 99813abf79
6 changed files with 82 additions and 167 deletions

View File

@@ -40,7 +40,7 @@ const b = {
classType: "bullet", classType: "bullet",
collisionFilter: { collisionFilter: {
category: 0x000100, category: 0x000100,
mask: 0x000011 //mask: 0x000101, //for self collision mask: 0x010011 //mask: 0x000101, //for self collision
}, },
minDmgSpeed: 10, minDmgSpeed: 10,
onDmg() {}, //this.endCycle = 0 //triggers despawn onDmg() {}, //this.endCycle = 0 //triggers despawn
@@ -236,7 +236,7 @@ const b = {
fire() { fire() {
// mech.fireCDcycle = game.cycle + 1 // mech.fireCDcycle = game.cycle + 1
//laser drains energy as well as bullets //laser drains energy as well as bullets
const FIELD_DRAIN = 0.004 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 = game.cycle + 100; // cool down if out of energy
} else { } else {
@@ -777,7 +777,7 @@ const b = {
const me = bullet.length; const me = bullet.length;
const dir = mech.angle; const dir = mech.angle;
bullet[me] = Bodies.polygon(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 20, 4.5, b.fireAttributes(dir)); bullet[me] = Bodies.polygon(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 20, 4.5, b.fireAttributes(dir));
b.fireProps(mech.crouch ? 70 : 50, mech.crouch ? 25 : 14, dir, me); //cd , speed b.fireProps(mech.crouch ? 75 : 55, mech.crouch ? 25 : 14, dir, me); //cd , speed
b.drawOneBullet(bullet[me].vertices); b.drawOneBullet(bullet[me].vertices);
Matter.Body.setDensity(bullet[me], 0.000001); Matter.Body.setDensity(bullet[me], 0.000001);
bullet[me].endCycle = game.cycle + 100; bullet[me].endCycle = game.cycle + 100;
@@ -816,7 +816,7 @@ const b = {
classType: "bullet", classType: "bullet",
collisionFilter: { collisionFilter: {
category: 0x000100, category: 0x000100,
mask: 0x000011 //mask: 0x000101, //for self collision mask: 0x000011 //no collide with body
}, },
endCycle: game.cycle + 300 + Math.floor(Math.random() * 240), endCycle: game.cycle + 300 + Math.floor(Math.random() * 240),
minDmgSpeed: 0, minDmgSpeed: 0,
@@ -892,7 +892,7 @@ const b = {
classType: "bullet", classType: "bullet",
collisionFilter: { collisionFilter: {
category: 0x000100, category: 0x000100,
mask: 0x000111 mask: 0x010111 //self collide
}, },
minDmgSpeed: 0, minDmgSpeed: 0,
lockedOn: null, lockedOn: null,
@@ -951,7 +951,7 @@ const b = {
}, },
], ],
fire() { fire() {
if (game.mouseDown && mech.fireCDcycle < game.cycle && !(keys[32] || game.mouseDownRight) && !mech.isHolding && b.inventory.length) { if (game.mouseDown && mech.fireCDcycle < game.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--;
@@ -961,6 +961,9 @@ const b = {
// 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);
} }
if (mech.isHolding) {
mech.drop();
}
} }
}, },
gamepadFire() { gamepadFire() {

View File

@@ -76,17 +76,18 @@ add bullet on damage effects
//collision info: // collision info:
category mask category mask
powerUp: 0x 100000 0x 100001 powerUp: 0x100000 0x100001
mobBull: 0x 010000 0x 001001 body: 0x010000 0x011111
player: 0x 001000 0x 010011 player: 0x001000 0x010011
bullet: 0x 000100 0x 000011 bullet: 0x000100 0x010011
mob: 0x 000010 0x 001101 mob: 0x000010 0x011111
map: 0x 000001 0x 111111 mobBull: 0x000010 0x011101
body: 0x 000001 0x 011111 mobshld: 0x000010 0x001100
map: 0x000001 0x111111
? hold: 0x 000001 0x 000001
*/ */

View File

@@ -99,9 +99,9 @@ const level = {
// spawn.bodyRect(-140, -200, 50, 50); // spawn.bodyRect(-140, -200, 50, 50);
// spawn.bodyRect(-95, -50, 40, 50); // spawn.bodyRect(-95, -50, 40, 50);
// spawn.bodyRect(-90, -100, 60, 50); // spawn.bodyRect(-90, -100, 60, 50);
// spawn.bodyRect(300, -150, 140, 50); spawn.bodyRect(300, -150, 140, 50);
// spawn.bodyRect(300, -150, 30, 30); spawn.bodyRect(300, -150, 30, 30);
// spawn.bodyRect(300, -150, 20, 20); spawn.bodyRect(300, -150, 20, 20);
// spawn.bodyRect(300, -150, 40, 100); // spawn.bodyRect(300, -150, 40, 100);
// spawn.bodyRect(300, -150, 40, 90); // spawn.bodyRect(300, -150, 40, 90);
// spawn.bodyRect(300, -150, 30, 60); // spawn.bodyRect(300, -150, 30, 60);
@@ -115,10 +115,21 @@ const level = {
// powerUps.spawn(400, -400, "field", false, '4'); // powerUps.spawn(400, -400, "field", false, '4');
// powerUps.spawn(400, -400, "gun", false); // powerUps.spawn(400, -400, "gun", false);
// 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) { // for (let i = 0; i < 1; ++i) {
// spawn.shooter(800, -1150); 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.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++) {
@@ -1409,7 +1420,7 @@ const level = {
//needs to be run to put bodies into the world //needs to be run to put bodies into the world
for (let i = 0; i < body.length; i++) { for (let i = 0; i < body.length; i++) {
//body[i].collisionFilter.group = 0; //body[i].collisionFilter.group = 0;
body[i].collisionFilter.category = 0x0000001; body[i].collisionFilter.category = 0x010000;
body[i].collisionFilter.mask = 0x011111; body[i].collisionFilter.mask = 0x011111;
body[i].classType = "body"; body[i].classType = "body";
World.add(engine.world, body[i]); //add to world World.add(engine.world, body[i]); //add to world

View File

@@ -58,7 +58,7 @@ const mobs = {
collisionFilter: { collisionFilter: {
group: 0, group: 0,
category: 0x000010, category: 0x000010,
mask: 0x001111 mask: 0x011111
}, },
onHit: undefined, onHit: undefined,
alive: true, alive: true,
@@ -231,7 +231,8 @@ const mobs = {
// ctx.lineDashOffset = 6*(game.cycle % 215); // ctx.lineDashOffset = 6*(game.cycle % 215);
if (this.distanceToPlayer() < this.laserRange) { if (this.distanceToPlayer() < this.laserRange) {
//if (Math.random()>0.2 && this.seePlayer.yes && this.distanceToPlayer2()<800000) { //if (Math.random()>0.2 && this.seePlayer.yes && this.distanceToPlayer2()<800000) {
mech.damage(0.0004 * game.dmgScale); mech.damage(0.0003 * game.dmgScale);
if (mech.fieldMeter > 0.1) mech.fieldMeter -= 0.005
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(this.position.x, this.position.y); ctx.moveTo(this.position.x, this.position.y);
ctx.lineTo(mech.pos.x, mech.pos.y); ctx.lineTo(mech.pos.x, mech.pos.y);
@@ -980,14 +981,14 @@ const mobs = {
body[len] = Matter.Bodies.fromVertices(this.position.x, this.position.y, this.vertices); body[len] = Matter.Bodies.fromVertices(this.position.x, this.position.y, this.vertices);
Matter.Body.setVelocity(body[len], this.velocity); Matter.Body.setVelocity(body[len], this.velocity);
Matter.Body.setAngularVelocity(body[len], this.angularVelocity); Matter.Body.setAngularVelocity(body[len], this.angularVelocity);
body[len].collisionFilter.category = 0x000001; body[len].collisionFilter.category = 0x010000;
body[len].collisionFilter.mask = 0x011111; body[len].collisionFilter.mask = 0x011111;
// body[len].collisionFilter.category = body[len].collisionFilter.category //0x000001; // body[len].collisionFilter.category = body[len].collisionFilter.category //0x000001;
// body[len].collisionFilter.mask = body[len].collisionFilter.mask //0x011111; // body[len].collisionFilter.mask = body[len].collisionFilter.mask //0x011111;
//large mobs or too many bodyes go intangible and fall until removed from game to help performance //large mobs or too many bodies go intangible and fall until removed from game to help performance
if (body[len].mass > 10 || 40 + 30 * Math.random() < body.length) { if (body[len].mass > 10 || 40 + 30 * Math.random() < body.length) {
body[len].collisionFilter.mask = 0x000100; body[len].collisionFilter.mask = 0x000000;
} }
body[len].classType = "body"; body[len].classType = "body";
World.add(engine.world, body[len]); //add to world World.add(engine.world, body[len]); //add to world

View File

@@ -543,7 +543,7 @@ const mech = {
if (this.isHolding) { if (this.isHolding) {
this.isHolding = false; this.isHolding = false;
this.definePlayerMass() this.definePlayerMass()
this.holdingTarget.collisionFilter.category = 0x000001; this.holdingTarget.collisionFilter.category = 0x010000;
this.holdingTarget.collisionFilter.mask = 0x011111; this.holdingTarget.collisionFilter.mask = 0x011111;
this.holdingTarget = null; this.holdingTarget = null;
this.throwCharge = 0; this.throwCharge = 0;
@@ -621,13 +621,13 @@ const mech = {
this.isHolding = false; this.isHolding = false;
//bullet-like collisions //bullet-like collisions
this.holdingTarget.collisionFilter.category = 0x000100; this.holdingTarget.collisionFilter.category = 0x000100;
this.holdingTarget.collisionFilter.mask = 0x111111; this.holdingTarget.collisionFilter.mask = 0x110111;
//check every second to see if player is away from thrown body, and make solid //check every second to see if player is away from thrown body, and make solid
const solid = function (that) { const solid = function (that) {
const dx = that.position.x - player.position.x; const dx = that.position.x - player.position.x;
const dy = that.position.y - player.position.y; const dy = that.position.y - player.position.y;
if (dx * dx + dy * dy > 10000 && that.speed < 3 && that !== mech.holdingTarget) { if (dx * dx + dy * dy > 10000 && that.speed < 3 && that !== mech.holdingTarget) {
that.collisionFilter.category = 0x000001; //make solid that.collisionFilter.category = 0x010000; //make solid
that.collisionFilter.mask = 0x011111; that.collisionFilter.mask = 0x011111;
} else { } else {
setTimeout(solid, 50, that); setTimeout(solid, 50, that);
@@ -806,8 +806,8 @@ const mech = {
//triggers when a hold target exits and field button is released //triggers when a hold target exits and field button is released
this.isHolding = true; this.isHolding = true;
if (this.holdingTarget) { if (this.holdingTarget) {
this.holdingTarget.collisionFilter.category = 0x000001; this.holdingTarget.collisionFilter.category = 0x010000;
this.holdingTarget.collisionFilter.mask = 0x111111; this.holdingTarget.collisionFilter.mask = 0x011111;
} }
//combine momentum //combine momentum
const px = player.velocity.x * player.mass + this.holdingTarget.velocity.x * this.holdingTarget.mass; const px = player.velocity.x * player.mass + this.holdingTarget.velocity.x * this.holdingTarget.mass;
@@ -907,16 +907,11 @@ const mech = {
game.makeTextLog("<strong style='font-size:30px;'>Kinetic Energy Field</strong><br> (right mouse or space bar)<p> field does damage on contact<br> blocks are thrown at a higher velocity</p>", 1200); game.makeTextLog("<strong style='font-size:30px;'>Kinetic Energy Field</strong><br> (right mouse or space bar)<p> field does damage on contact<br> blocks are thrown at a higher velocity</p>", 1200);
mech.setHoldDefaults(); mech.setHoldDefaults();
//throw quicker and harder //throw quicker and harder
mech.throwChargeRate = 3; //0.5 mech.throwChargeRate = 3;
mech.throwChargeMax = 140; //50 mech.throwChargeMax = 140;
//passive field does extra damage mech.fieldDamage = 2.5; //passive field does extra damage
mech.fieldDamage = 2;
// const startingArc = 0.
mech.fieldArc = 0.09 mech.fieldArc = 0.09
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)
const STARTING_RANGE = 30
mech.grabRange = STARTING_RANGE;
mech.hold = function () { mech.hold = function () {
if (mech.isHolding) { if (mech.isHolding) {
@@ -924,10 +919,6 @@ const mech = {
mech.holding(); mech.holding();
mech.throw(); mech.throw();
} else if ((keys[32] || game.mouseDownRight) && mech.fieldMeter > 0.15) { //not hold but field button is pressed } else if ((keys[32] || game.mouseDownRight) && mech.fieldMeter > 0.15) { //not hold but field button is pressed
//smoothing function to grow range
mech.grabRange = mech.grabRange * 0.94 + 12 //200 * 0.08
//draw field //draw field
const range = mech.grabRange - 20; const range = mech.grabRange - 20;
ctx.beginPath(); ctx.beginPath();
@@ -940,15 +931,14 @@ const mech = {
ctx.fillStyle = "rgba(255,50,150," + (0.13 + 0.18 * Math.random()) + ")"; ctx.fillStyle = "rgba(255,50,150," + (0.13 + 0.18 * Math.random()) + ")";
} }
ctx.fill(); ctx.fill();
//draw random lines in field for cool effect //draw random lines in field for cool effect
eye = 15; eye = 15;
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(mech.pos.x + eye * Math.cos(mech.angle), mech.pos.y + eye * Math.sin(mech.angle)); ctx.moveTo(mech.pos.x + eye * Math.cos(mech.angle), mech.pos.y + eye * Math.sin(mech.angle));
const offAngle = mech.angle + 2 * Math.PI * mech.fieldArc * (Math.random() - 0.5); const offAngle = mech.angle + 2 * Math.PI * mech.fieldArc * (Math.random() - 0.5);
ctx.lineTo(mech.pos.x + range * Math.cos(offAngle), mech.pos.y + range * Math.sin(offAngle)); ctx.lineTo(mech.pos.x + range * Math.cos(offAngle), mech.pos.y + range * Math.sin(offAngle));
ctx.strokeStyle = "rgba(100,20,50,0.2)"; ctx.strokeStyle = "rgba(100,20,50,0.2)";
// ctx.strokeStyle = "rgba(0,0,0,0.4)";
ctx.stroke(); ctx.stroke();
mech.grabPowerUp(); mech.grabPowerUp();
@@ -956,10 +946,8 @@ const mech = {
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 < game.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
mech.pickUp(); mech.pickUp();
mech.grabRange = STARTING_RANGE;
} 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)
mech.grabRange = STARTING_RANGE;
} }
mech.drawFieldMeter() mech.drawFieldMeter()
} }
@@ -1053,12 +1041,12 @@ const mech = {
}, },
() => { () => {
mech.fieldMode = 4; mech.fieldMode = 4;
game.makeTextLog("<strong style='font-size:30px;'>Standing Wave Harmonics</strong><br> (right mouse or space bar) <p>oscillating shields surround player<br>improved energy regeneration<br>improved field shielding efficiency</p>", 1200); game.makeTextLog("<strong style='font-size:30px;'>Standing Wave Harmonics</strong><br> (right mouse or space bar) <p>oscillating shields surround player<br>improved field shielding efficiency</p>", 1200);
mech.setHoldDefaults(); mech.setHoldDefaults();
mech.fieldShieldingScale = 0.3; mech.fieldShieldingScale = 0.15;
mech.fieldRegen = 0.007; //0.0015 // mech.fieldRegen = 0.005; //0.0015
// 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.hold = function () { mech.hold = function () {
grabRange1 = 100 + 95 * Math.sin(game.cycle / 23) grabRange1 = 100 + 95 * Math.sin(game.cycle / 23)
@@ -1125,10 +1113,9 @@ const mech = {
}, },
() => { () => {
mech.fieldMode = 6; mech.fieldMode = 6;
game.makeTextLog("<strong style='font-size:30px;'>Phase Decoherence Field</strong><br> (right mouse or space bar) <p>phase through enemies while field is active<br>can't see or be seen outside field while field is active</p>", 1200); game.makeTextLog("<strong style='font-size:30px;'>Phase Decoherence Field</strong><br> (right mouse or space bar) <p>intangible while field is active<br>can't see or be seen outside field</p>", 1200);
mech.setHoldDefaults(); mech.setHoldDefaults();
// mech.fieldShieldingScale = 3; // mech.grabRange = 230
mech.grabRange = 220
mech.hold = function () { mech.hold = function () {
mech.isStealth = false //isStealth is checked in mob foundPlayer() mech.isStealth = false //isStealth is checked in mob foundPlayer()
@@ -1138,19 +1125,13 @@ const mech = {
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 < game.cycle) {
const DRAIN = 0.002 //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;
mech.isStealth = true //isStealth is checked in mob foundPlayer() mech.isStealth = true //isStealth is checked in mob foundPlayer()
player.collisionFilter.mask = 0x000001 //0x010011 is normals player.collisionFilter.mask = 0x000001 //0x010011 is normals
// if (mech.crouch) {
// mech.grabRange = mech.grabRange * 0.96 + 400 * 0.04;
// } else {
// mech.grabRange = mech.grabRange * 0.96 + 220 * 0.04;
// }
ctx.beginPath(); ctx.beginPath();
ctx.arc(mech.pos.x, mech.pos.y, mech.grabRange, 0, 2 * Math.PI); ctx.arc(mech.pos.x, mech.pos.y, mech.grabRange, 0, 2 * Math.PI);
ctx.globalCompositeOperation = "destination-in"; //in or atop ctx.globalCompositeOperation = "destination-in"; //in or atop
@@ -1251,68 +1232,6 @@ const mech = {
mech.drawFieldMeter() mech.drawFieldMeter()
} }
}, },
// () => {
// mech.fieldMode = 8;
// game.makeTextLog("<strong style='font-size:30px;'>Time Dilation Field</strong><br> (right click or space bar)<p>slows time while field is active</p>", Infinity);
// mech.setHoldDefaults();
// mech.isTimeDilated = false
// // mech.mobMasses = []
// mech.hold = function () {
// if (!mech.isTimeDilated) {
// engine.timing.timeScale = 1
// // for (let i = 0, len = body.length; i < len; i++) {
// // // Matter.Body.setStatic(body[i], false)
// // // if (!body[i].isNotHoldable) body[i].timeScale = 1
// // }
// // for (let i = 0, len = mob.length; i < len; i++) {
// // // mob[i].timeScale = 1
// // // Matter.Body.setStatic(mob[i], false)
// // }
// }
// if (mech.isHolding) {
// mech.drawHold(mech.holdingTarget);
// mech.holding();
// mech.throw();
// } else if ((keys[32] || game.mouseDownRight && mech.fieldMeter > 0.1)) { //not hold but field button is pressed
// mech.drawField();
// mech.grabPowerUp();
// mech.pushMobs();
// mech.lookForPickUp();
// //set time to slow
// // mech.look(); //still works when fps is slow
// // game.fpsCap = 30
// // game.fpsInterval = 1000 / game.fpsCap;
// // for (let i = 0, len = mob.length; i < len; i++) {
// // Matter.Body.update(mob[i], 1, 1, 0)
// // }
// if (!mech.isTimeDilated) {
// mech.isTimeDilated = true
// engine.timing.timeScale = 0.01
// // for (let i = 0, len = body.length; i < len; i++) {
// // // if (!body[i].isNotHoldable) body[i].timeScale = 0.01
// // // mech.mobMasses.push(body[i].mass)
// // // Matter.Body.setStatic(body[i], true)
// // }
// // for (let i = 0, len = mob.length; i < len; i++) {
// // // Matter.Body.setStatic(mob[i], true)
// // // mob[i].timeScale = 0.01
// // }
// }
// } else if (mech.holdingTarget && mech.fireCDcycle < game.cycle && mech.fieldMeter > 0.05) { //holding, but field button is released
// mech.pickUp();
// mech.isTimeDilated = false
// } 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.isTimeDilated = false
// }
// mech.drawFieldMeter()
// }
// },
], ],
drawLeg(stroke) { drawLeg(stroke) {
// if (game.mouseInGame.x > this.pos.x) { // if (game.mouseInGame.x > this.pos.x) {

View File

@@ -12,7 +12,7 @@ const spawn = {
"beamer", "beamer",
"focuser", "focuser",
"laser", "laser", "laser", "laser",
"blinker", // "blinker", //make blinker a boss
"sucker", "sucker",
"exploder", "exploder", "exploder", "exploder", "exploder", "exploder",
"spawner", "spawner",
@@ -424,7 +424,6 @@ const spawn = {
// me.frictionAir = 0.005; // me.frictionAir = 0.005;
me.memory = 600; me.memory = 600;
Matter.Body.setDensity(me, 0.004); //extra dense //normal is 0.001 //makes effective life much larger Matter.Body.setDensity(me, 0.004); //extra dense //normal is 0.001 //makes effective life much larger
// me.collisionFilter.mask = 0x001100; //move through walls
me.do = function () { me.do = function () {
//keep it slow, to stop issues from explosion knock backs //keep it slow, to stop issues from explosion knock backs
if (this.speed > 5) { if (this.speed > 5) {
@@ -619,7 +618,7 @@ const spawn = {
me.alpha = 1; //used in drawSneaker me.alpha = 1; //used in drawSneaker
// me.leaveBody = false; // me.leaveBody = false;
me.canTouchPlayer = false; //used in drawSneaker me.canTouchPlayer = false; //used in drawSneaker
me.collisionFilter.mask = 0x000111; //can't touch player me.collisionFilter.mask = 0x010111; //can't touch player
// me.memory = 420; // me.memory = 420;
// me.seePlayerFreq = 60 + Math.round(Math.random() * 30); // me.seePlayerFreq = 60 + Math.round(Math.random() * 30);
me.do = function () { me.do = function () {
@@ -637,7 +636,7 @@ const spawn = {
this.healthBar(); this.healthBar();
if (!this.canTouchPlayer) { if (!this.canTouchPlayer) {
this.canTouchPlayer = true; this.canTouchPlayer = true;
this.collisionFilter.mask = 0x001111; //can touch player this.collisionFilter.mask = 0x011111; //can touch player
} }
} }
//draw body //draw body
@@ -692,7 +691,7 @@ const spawn = {
this.healthBar(); this.healthBar();
if (!this.canTouchPlayer) { if (!this.canTouchPlayer) {
this.canTouchPlayer = true; this.canTouchPlayer = true;
this.collisionFilter.mask = 0x001110; //can touch player but not walls this.collisionFilter.mask = 0x001100; //can touch player but not walls
} }
} }
//draw body //draw body
@@ -708,7 +707,7 @@ const spawn = {
ctx.stroke(); ctx.stroke();
} else if (this.canTouchPlayer) { } else if (this.canTouchPlayer) {
this.canTouchPlayer = false; this.canTouchPlayer = false;
this.collisionFilter.mask = 0x000110; //can't touch player or walls this.collisionFilter.mask = 0x000100; //can't touch player or walls
} }
}; };
}, },
@@ -720,9 +719,7 @@ const spawn = {
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.collisionFilter.mask = 0x001100; //move through walls
me.isStatic = true; me.isStatic = true;
// me.leaveBody = false;
me.memory = 360; me.memory = 360;
me.seePlayerFreq = 40 + Math.round(Math.random() * 30); me.seePlayerFreq = 40 + Math.round(Math.random() * 30);
me.isBig = false; me.isBig = false;
@@ -754,23 +751,6 @@ const spawn = {
} }
}; };
}, },
// drifter(x, y, radius = 15 + Math.ceil(Math.random() * 40)) {
// mobs.spawn(x, y, 4.5, radius, "transparent");
// let me = mob[mob.length - 1];
// me.stroke = "rgb(0,200,255)"; //used for drawGhost
// Matter.Body.rotate(me, Math.random() * 2 * Math.PI);
// me.blinkRate = 30 + Math.round(Math.random() * 30); //required for blink/drift
// me.blinkLength = 160; //required for blink/drift
// //me.collisionFilter.mask = 0x001100; //move through walls
// me.isStatic = true;
// me.memory = 360;
// me.seePlayerFreq = 40 + Math.round(Math.random() * 30);
// me.do = function () {
// this.healthBar();
// this.seePlayerCheck();
// this.drift();
// };
// },
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");
@@ -867,8 +847,8 @@ const spawn = {
me.restitution = 0.8; me.restitution = 0.8;
me.leaveBody = false; me.leaveBody = false;
me.dropPowerUp = false; me.dropPowerUp = false;
// me.collisionFilter.mask = 0x001000; me.collisionFilter.category = 0x000010;
me.collisionFilter.category = 0x010000; me.collisionFilter.mask = 0x011101;
me.do = function () { me.do = function () {
this.gravity(); this.gravity();
this.timeLimit(); this.timeLimit();
@@ -1005,7 +985,7 @@ const spawn = {
me.stroke = "rgb(220,220,255)"; me.stroke = "rgb(220,220,255)";
Matter.Body.setDensity(me, 0.0001) //very low density to not mess with the original mob's motion Matter.Body.setDensity(me, 0.0001) //very low density to not mess with the original mob's motion
me.shield = true; me.shield = true;
me.collisionFilter.mask = 0x000100; //don't collide with bodies, map, player, and mobs, only bullets me.collisionFilter.mask = 0x001100; //don't collide with bodies, map, player, and mobs, only bullets
consBB[consBB.length] = Constraint.create({ consBB[consBB.length] = Constraint.create({
//attach shield to last spawned mob //attach shield to last spawned mob
bodyA: me, bodyA: me,
@@ -1032,7 +1012,7 @@ const spawn = {
Matter.Body.setDensity(me, 0.00005) //very low density to not mess with the original mob's motion Matter.Body.setDensity(me, 0.00005) //very low density to not mess with the original mob's motion
me.frictionAir = 0; me.frictionAir = 0;
me.shield = true; me.shield = true;
me.collisionFilter.mask = 0x000100; //don't collide with bodies, map, and mobs, only bullets and player me.collisionFilter.mask = 0x001100; //don't collide with bodies, map, and mobs, only bullets and player
//constrain to all mob nodes in boss //constrain to all mob nodes in boss
for (let i = 0; i < nodes; ++i) { for (let i = 0; i < nodes; ++i) {
consBB[consBB.length] = Constraint.create({ consBB[consBB.length] = Constraint.create({
@@ -1218,9 +1198,9 @@ const spawn = {
const breakingPoint = 1300 const breakingPoint = 1300
mobs.spawn(breakingPoint, -100, 0, 7.5, "transparent"); mobs.spawn(breakingPoint, -100, 0, 7.5, "transparent");
let me = mob[mob.length - 1]; let me = mob[mob.length - 1];
//touch only walls //touch nothing
me.collisionFilter.category = 0x100000; me.collisionFilter.category = 0x000000;
me.collisionFilter.mask = 0x100001; me.collisionFilter.mask = 0x000000;
me.inertia = Infinity; me.inertia = Infinity;
me.g = 0.0004; //required for gravity me.g = 0.0004; //required for gravity
me.restitution = 0; me.restitution = 0;
@@ -1282,9 +1262,9 @@ const spawn = {
const breakingPoint = 1425 const breakingPoint = 1425
mobs.spawn(breakingPoint, -100, 0, 2, "transparent"); mobs.spawn(breakingPoint, -100, 0, 2, "transparent");
let me = mob[mob.length - 1]; let me = mob[mob.length - 1];
//touch only walls //touch nothing
me.collisionFilter.category = 0x100000; me.collisionFilter.category = 0x000000;
me.collisionFilter.mask = 0x100001; me.collisionFilter.mask = 0x000000;
me.g = 0.0003; //required for gravity me.g = 0.0003; //required for gravity
// me.restitution = 0; // me.restitution = 0;
me.stroke = "transparent" me.stroke = "transparent"
@@ -1330,9 +1310,9 @@ const spawn = {
const breakingPoint = 1400 const breakingPoint = 1400
mobs.spawn(breakingPoint, -100, 0, 2, "transparent"); mobs.spawn(breakingPoint, -100, 0, 2, "transparent");
let me = mob[mob.length - 1]; let me = mob[mob.length - 1];
//touch only walls //touch nothing
me.collisionFilter.category = 0x100000; me.collisionFilter.category = 0x000000;
me.collisionFilter.mask = 0x100001; me.collisionFilter.mask = 0x000000;
me.g = 0.0003; //required for gravity me.g = 0.0003; //required for gravity
// me.restitution = 0; // me.restitution = 0;
me.stroke = "transparent" me.stroke = "transparent"
@@ -1378,9 +1358,9 @@ const spawn = {
const breakingPoint = 1350 const breakingPoint = 1350
mobs.spawn(breakingPoint, -100, 0, 2, "transparent"); mobs.spawn(breakingPoint, -100, 0, 2, "transparent");
let me = mob[mob.length - 1]; let me = mob[mob.length - 1];
//touch only walls //touch nothing
me.collisionFilter.category = 0x100000; me.collisionFilter.category = 0x000000;
me.collisionFilter.mask = 0x100001; me.collisionFilter.mask = 0x000000;
me.g = 0.0003; //required for gravity me.g = 0.0003; //required for gravity
me.restitution = 0; me.restitution = 0;
me.stroke = "transparent" me.stroke = "transparent"
@@ -1425,9 +1405,9 @@ const spawn = {
const breakingPoint = 1325 const breakingPoint = 1325
mobs.spawn(breakingPoint, -100, 0, 2, "transparent"); mobs.spawn(breakingPoint, -100, 0, 2, "transparent");
let me = mob[mob.length - 1]; let me = mob[mob.length - 1];
//touch only walls //touch nothing
me.collisionFilter.category = 0x100000; me.collisionFilter.category = 0x000000;
me.collisionFilter.mask = 0x100001; me.collisionFilter.mask = 0x000000;
me.g = 0.0003; //required for gravity me.g = 0.0003; //required for gravity
me.restitution = 0; me.restitution = 0;
me.stroke = "transparent" me.stroke = "transparent"