foam bug fixes

This commit is contained in:
landgreen
2019-12-15 17:55:49 -08:00
committed by GitHub
parent 66479c9b82
commit 03b16e223d
5 changed files with 28 additions and 28 deletions

View File

@@ -1789,13 +1789,13 @@ const b = {
name: "foam", //15 name: "foam", //15
description: "spray bubbly foam that <strong>sticks</strong> to enemies<br>does <strong class='color-d'>damage</strong> over time and <strong>slows</strong> movement", description: "spray bubbly foam that <strong>sticks</strong> to enemies<br>does <strong class='color-d'>damage</strong> over time and <strong>slows</strong> movement",
ammo: 0, ammo: 0,
ammoPack: 80, ammoPack: 95,
have: false, have: false,
isStarterGun: true, isStarterGun: true,
fire() { fire() {
const me = bullet.length; const me = bullet.length;
const dir = mech.angle + 0.1 * (Math.random() - 0.5) const dir = mech.angle + 0.2 * (Math.random() - 0.5)
const RADIUS = (9 + 12 * Math.random()) * b.modBulletSize const RADIUS = (6 + 16 * Math.random()) * b.modBulletSize
bullet[me] = Bodies.polygon(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 25, RADIUS, { bullet[me] = Bodies.polygon(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 25, RADIUS, {
angle: dir, angle: dir,
density: 0.000001, // 0.001 is normal density density: 0.000001, // 0.001 is normal density
@@ -1803,7 +1803,7 @@ const b = {
frictionAir: 0, frictionAir: 0,
friction: 0.2, friction: 0.2,
restitution: 0.2, restitution: 0.2,
dmg: b.modExtraDmg, //damage done in addition to the damage from momentum dmg: 0.04 + b.modExtraDmg, //damage done in addition to the damage from momentum
classType: "bullet", classType: "bullet",
collisionFilter: { collisionFilter: {
category: 0x000100, category: 0x000100,
@@ -1815,7 +1815,7 @@ const b = {
radius: RADIUS, radius: RADIUS,
target: null, target: null,
onDmg(who) { onDmg(who) {
if (!this.target && who.alive) { if (!this.target && who.alive && who.dropPowerUp) {
this.target = who; this.target = who;
this.collisionFilter.category = 0x000000; this.collisionFilter.category = 0x000000;
} }
@@ -1852,7 +1852,7 @@ const b = {
Matter.Body.setPosition(this, this.target.position) Matter.Body.setPosition(this, this.target.position)
Matter.Body.setVelocity(this.target, Matter.Vector.mult(this.target.velocity, 0.95)) Matter.Body.setVelocity(this.target, Matter.Vector.mult(this.target.velocity, 0.95))
Matter.Body.setAngularVelocity(this.target, this.target.angularVelocity * 0.96) Matter.Body.setAngularVelocity(this.target, this.target.angularVelocity * 0.96)
this.target.damage(b.dmgScale * 0.0035); this.target.damage(b.dmgScale * 0.0025);
} else { } else {
//look for a new target //look for a new target
this.target = null this.target = null
@@ -1863,7 +1863,7 @@ const b = {
}); });
World.add(engine.world, bullet[me]); //add bullet to world World.add(engine.world, bullet[me]); //add bullet to world
mech.fireCDcycle = mech.cycle + Math.floor((mech.crouch ? 15 : 3) * b.modFireRate); // cool down mech.fireCDcycle = mech.cycle + Math.floor((mech.crouch ? 15 : 3) * b.modFireRate); // cool down
const SPEED = mech.crouch ? 25 : 16 - RADIUS * 0.25; const SPEED = mech.crouch ? 22 : 15 - RADIUS * 0.25;
Matter.Body.setVelocity(bullet[me], { Matter.Body.setVelocity(bullet[me], {
x: SPEED * Math.cos(dir), x: SPEED * Math.cos(dir),
y: SPEED * Math.sin(dir) y: SPEED * Math.sin(dir)

View File

@@ -110,7 +110,7 @@ const level = {
// 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.shooter(800, -1150); spawn.shooter(800, -1050);
// spawn.groupBoss(-600, -550); // spawn.groupBoss(-600, -550);
// spawn.hopper(800, -150); // spawn.hopper(800, -150);
// spawn.beamer(800, -150); // spawn.beamer(800, -150);

View File

@@ -711,7 +711,7 @@ const mobs = {
// } // }
}, },
grow() { grow() {
if (!this.isSleeping) { if (!mech.isBodiesAsleep) {
if (this.seePlayer.recall) { if (this.seePlayer.recall) {
if (this.radius < 80) { if (this.radius < 80) {
const scale = 1.01; const scale = 1.01;
@@ -845,7 +845,7 @@ const mobs = {
} }
}, },
fire() { fire() {
if (!this.isSleeping) { if (!mech.isBodiesAsleep) {
const setNoseShape = () => { const setNoseShape = () => {
const mag = this.radius + this.radius * this.noseLength; const mag = this.radius + this.radius * this.noseLength;
this.vertices[1].x = this.position.x + Math.cos(this.angle) * mag; this.vertices[1].x = this.position.x + Math.cos(this.angle) * mag;
@@ -921,7 +921,7 @@ const mobs = {
this.death(); //death with no power up or body this.death(); //death with no power up or body
}, },
timeLimit() { timeLimit() {
if (!this.isSleeping) { if (!mech.isBodiesAsleep) {
this.timeLeft--; this.timeLeft--;
if (this.timeLeft < 0) { if (this.timeLeft < 0) {
this.dropPowerUp = false; this.dropPowerUp = false;

View File

@@ -846,13 +846,13 @@ const mech = {
}, },
grabPowerUp() { //look for power ups to grab with field grabPowerUp() { //look for power ups to grab with field
if (mech.fieldCDcycle < mech.cycle) { if (mech.fieldCDcycle < mech.cycle) {
const grabPowerUpRange2 = (this.grabRange + 220) * (this.grabRange + 220) const grabPowerUpRange2 = (mech.grabRange + 220) * (mech.grabRange + 220)
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;
const dyP = mech.pos.y - powerUp[i].position.y; const dyP = mech.pos.y - powerUp[i].position.y;
const dist2 = dxP * dxP + dyP * dyP; const dist2 = dxP * dxP + dyP * dyP;
// float towards player if looking at and in range or if very close to player // float towards player if looking at and in range or if very close to player
if (dist2 < grabPowerUpRange2 && this.lookingAt(powerUp[i]) || dist2 < 16000) { if (dist2 < grabPowerUpRange2 && mech.lookingAt(powerUp[i]) || dist2 < 16000) {
if (dist2 < 5000) { //use power up if it is close enough if (dist2 < 5000) { //use power up if it is close enough
Matter.Body.setVelocity(player, { //player knock back, after grabbing power up Matter.Body.setVelocity(player, { //player knock back, after grabbing power up
x: player.velocity.x + ((powerUp[i].velocity.x * powerUp[i].mass) / player.mass) * 0.3, x: player.velocity.x + ((powerUp[i].velocity.x * powerUp[i].mass) / player.mass) * 0.3,
@@ -861,7 +861,7 @@ const mech = {
mech.usePowerUp(i); mech.usePowerUp(i);
return; return;
} }
this.fieldMeter -= this.fieldRegen * 0.5; mech.fieldMeter -= mech.fieldRegen * 0.5;
powerUp[i].force.x += 7 * (dxP / dist2) * powerUp[i].mass; powerUp[i].force.x += 7 * (dxP / dist2) * powerUp[i].mass;
powerUp[i].force.y += 7 * (dyP / dist2) * powerUp[i].mass - powerUp[i].mass * game.g; //negate gravity powerUp[i].force.y += 7 * (dyP / dist2) * powerUp[i].mass - powerUp[i].mass * game.g; //negate gravity
//extra friction //extra friction
@@ -876,11 +876,12 @@ const mech = {
pushMass(who) { pushMass(who) {
const speed = Matter.Vector.magnitude(Matter.Vector.sub(who.velocity, player.velocity)) const speed = Matter.Vector.magnitude(Matter.Vector.sub(who.velocity, player.velocity))
const fieldBlockCost = 0.03 + Math.sqrt(who.mass) * speed * 0.003 //0.012 const fieldBlockCost = 0.03 + Math.sqrt(who.mass) * speed * 0.003 //0.012
if (this.fieldMeter > fieldBlockCost * 0.6) { //shield needs at least some of the cost to block if (mech.fieldMeter > fieldBlockCost * 0.6) { //shield needs at least some of the cost to block
this.fieldMeter -= fieldBlockCost * this.fieldShieldingScale; mech.fieldMeter -= fieldBlockCost * mech.fieldShieldingScale;
if (this.fieldMeter < 0) this.fieldMeter = 0; if (mech.fieldMeter < 0) mech.fieldMeter = 0;
this.drawHold(who); mech.drawHold(who);
mech.fieldCDcycle = mech.cycle + 10; mech.fieldCDcycle = mech.cycle + 10;
mech.holdingTarget = null
//knock backs //knock backs
const unit = Matter.Vector.normalise(Matter.Vector.sub(player.position, who.position)) const unit = Matter.Vector.normalise(Matter.Vector.sub(player.position, who.position))
const mass = Math.min(Math.sqrt(who.mass), 3.5); //large masses above 4*4 can start to overcome the push back const mass = Math.min(Math.sqrt(who.mass), 3.5); //large masses above 4*4 can start to overcome the push back
@@ -1061,9 +1062,9 @@ const mech = {
} else if ((keys[32] || game.mouseDownRight && mech.fieldMeter > 0.1 && mech.fieldCDcycle < mech.cycle)) { //not hold but field button is pressed } else if ((keys[32] || game.mouseDownRight && mech.fieldMeter > 0.1 && mech.fieldCDcycle < mech.cycle)) { //not hold but field button is pressed
mech.drawField(); mech.drawField();
mech.grabPowerUp(); mech.grabPowerUp();
mech.pushMobsFacing();
mech.pushBodyFacing();
mech.lookForPickUp(); mech.lookForPickUp();
mech.pushBodyFacing();
mech.pushMobsFacing();
} else if (mech.holdingTarget && mech.fireCDcycle < mech.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 {
@@ -1294,10 +1295,10 @@ const mech = {
ctx.lineWidth = 2 * Math.random(); ctx.lineWidth = 2 * Math.random();
ctx.stroke(); ctx.stroke();
mech.pushMobs360(110);
// mech.pushBody360(100); //disabled because doesn't work at short range
mech.grabPowerUp(); mech.grabPowerUp();
mech.lookForPickUp(); mech.lookForPickUp();
mech.pushMobs360(110);
// mech.pushBody360(100); //disabled because doesn't work at short range
} else { } else {
mech.fieldCDcycle = mech.cycle + 120; //if out of energy mech.fieldCDcycle = mech.cycle + 120; //if out of energy
} }
@@ -1327,10 +1328,9 @@ const mech = {
} else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) { //push away } else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) { //push away
const DRAIN = 0.0004 const DRAIN = 0.0004
if (mech.fieldMeter > DRAIN) { if (mech.fieldMeter > DRAIN) {
mech.pushMobs360(170);
mech.pushBody360(180);
mech.grabPowerUp(); mech.grabPowerUp();
mech.lookForPickUp(170); mech.lookForPickUp(170);
mech.pushMobs360(170);
//look for nearby objects to make zero-g //look for nearby objects to make zero-g
function zeroG(who, mag = 1.06) { function zeroG(who, mag = 1.06) {
for (let i = 0, len = who.length; i < len; ++i) { for (let i = 0, len = who.length; i < len; ++i) {
@@ -1462,11 +1462,11 @@ const mech = {
mech.holding(); mech.holding();
mech.throw(); mech.throw();
} else if ((keys[32] || game.mouseDownRight && mech.fieldMeter > 0.1 && mech.fieldCDcycle < mech.cycle)) { //not hold but field button is pressed } else if ((keys[32] || game.mouseDownRight && mech.fieldMeter > 0.1 && mech.fieldCDcycle < mech.cycle)) { //not hold but field button is pressed
mech.pushMobsFacing();
mech.pushBodyFacing();
mech.drawField(); mech.drawField();
mech.grabPowerUp(); mech.grabPowerUp();
mech.lookForPickUp(); mech.lookForPickUp();
mech.pushMobsFacing();
mech.pushBodyFacing();
} else if (mech.holdingTarget && mech.fireCDcycle < mech.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 {

View File

@@ -587,7 +587,7 @@ const spawn = {
}; };
// if (Math.random() < Math.min(0.2 + game.difficulty * 0.1, 0.7)) spawn.shield(me, x, y); // if (Math.random() < Math.min(0.2 + game.difficulty * 0.1, 0.7)) spawn.shield(me, x, y);
me.do = function () { me.do = function () {
if (!this.isSleeping) { if (!mech.isBodiesAsleep) {
this.seePlayerByLookingAt(); this.seePlayerByLookingAt();
const dist2 = this.distanceToPlayer2(); const dist2 = this.distanceToPlayer2();
//laser Tracking //laser Tracking
@@ -689,7 +689,7 @@ const spawn = {
this.attraction(); this.attraction();
this.gravity(); this.gravity();
//draw //draw
if (!this.isSleeping) { if (!mech.isBodiesAsleep) {
if (this.seePlayer.yes) { if (this.seePlayer.yes) {
if (this.alpha < 1) this.alpha += 0.01; if (this.alpha < 1) this.alpha += 0.01;
} else { } else {