general balancing around crouch alt fire

This commit is contained in:
landgreen
2019-09-16 04:42:47 -07:00
parent a16bfedfbd
commit aa3882e34b
7 changed files with 213 additions and 302 deletions

View File

@@ -207,7 +207,7 @@ const b = {
knock = Matter.Vector.mult(Matter.Vector.normalise(sub), (-Math.sqrt(dmg * damageScale) * mob[i].mass) / 18); knock = Matter.Vector.mult(Matter.Vector.normalise(sub), (-Math.sqrt(dmg * damageScale) * mob[i].mass) / 18);
mob[i].force.x += knock.x; mob[i].force.x += knock.x;
mob[i].force.y += knock.y; mob[i].force.y += knock.y;
damageScale *= 0.85 damageScale *= 0.7 //reduced damage for each additional explosion target
} else if (!mob[i].seePlayer.recall && dist < alertRange) { } else if (!mob[i].seePlayer.recall && dist < alertRange) {
mob[i].locatePlayer(); mob[i].locatePlayer();
knock = Matter.Vector.mult(Matter.Vector.normalise(sub), (-Math.sqrt(dmg * damageScale) * mob[i].mass) / 35); knock = Matter.Vector.mult(Matter.Vector.normalise(sub), (-Math.sqrt(dmg * damageScale) * mob[i].mass) / 35);
@@ -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.006 const FIELD_DRAIN = 0.004
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 {
@@ -308,7 +308,7 @@ const b = {
}; };
const laserHitMob = function (dmg) { const laserHitMob = function (dmg) {
if (best.who.alive) { if (best.who.alive) {
dmg *= b.dmgScale * 0.05; dmg *= b.dmgScale * 0.045;
best.who.damage(dmg); best.who.damage(dmg);
best.who.locatePlayer(); best.who.locatePlayer();
//draw mob damage circle //draw mob damage circle
@@ -386,29 +386,10 @@ const b = {
} }
} }
}, },
{
name: "rapid fire",
ammo: 0,
ammoPack: 100,
have: false,
fire() {
const me = bullet.length;
b.muzzleFlash(15);
// if (Math.random() > 0.2) mobs.alert(500);
const dir = mech.angle + (Math.random() - 0.5) * ((mech.crouch) ? 0.05 : 0.15);
bullet[me] = Bodies.rectangle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 17, 5, b.fireAttributes(dir));
b.fireProps(5, 40, dir, me); //cd , speed
bullet[me].endCycle = game.cycle + 60;
bullet[me].frictionAir = 0.01;
bullet[me].do = function () {
this.force.y += this.mass * 0.001;
};
}
},
{ {
name: "one shot", name: "one shot",
ammo: 0, ammo: 0,
ammoPack: 4, ammoPack: 5,
have: false, have: false,
fire() { fire() {
b.muzzleFlash(45); b.muzzleFlash(45);
@@ -416,16 +397,89 @@ const b = {
const me = bullet.length; const me = bullet.length;
const dir = mech.angle; const dir = mech.angle;
bullet[me] = Bodies.rectangle(mech.pos.x + 50 * Math.cos(mech.angle), mech.pos.y + 50 * Math.sin(mech.angle), 70, 30, b.fireAttributes(dir)); bullet[me] = Bodies.rectangle(mech.pos.x + 50 * Math.cos(mech.angle), mech.pos.y + 50 * Math.sin(mech.angle), 70, 30, b.fireAttributes(dir));
b.fireProps(mech.crouch ? 40 : 30, 54, dir, me); //cd , speed b.fireProps(mech.crouch ? 55 : 40, 50, dir, me); //cd , speed
bullet[me].endCycle = game.cycle + 180; bullet[me].endCycle = game.cycle + 180;
bullet[me].do = function () { bullet[me].do = function () {
this.force.y += this.mass * 0.0005; this.force.y += this.mass * 0.0005;
}; };
//knock back //knock back
const KNOCK = (mech.crouch) ? 0.015 : 0.15 const KNOCK = (mech.crouch) ? 0.025 : 0.25
player.force.x -= KNOCK * Math.cos(dir) player.force.x -= KNOCK * Math.cos(dir)
player.force.y -= 0.5 * KNOCK * Math.sin(dir) player.force.y -= KNOCK * Math.sin(dir) * 0.5 //reduce knock back in vertical direction to stop super jumps
}
},
{
name: "rapid fire",
ammo: 0,
ammoPack: 105,
have: false,
fire() {
const me = bullet.length;
b.muzzleFlash(15);
// if (Math.random() > 0.2) mobs.alert(500);
const dir = mech.angle + (Math.random() - 0.5) * ((mech.crouch) ? 0.07 : 0.16);
bullet[me] = Bodies.rectangle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 17, 5, b.fireAttributes(dir));
b.fireProps(mech.crouch ? 11 : 5, mech.crouch ? 44 : 36, dir, me); //cd , speed
bullet[me].endCycle = game.cycle + 65;
bullet[me].frictionAir = 0.01;
bullet[me].do = function () {
this.force.y += this.mass * 0.0005;
};
}
},
{
name: "wave beam",
ammo: 0,
ammoPack: 110,
have: false,
fire() {
const me = bullet.length;
const DIR = mech.angle
const SCALE = mech.crouch ? 0.963 : 0.95
const wiggleMag = ((mech.flipLegs === 1) ? 1 : -1) * ((mech.crouch) ? 0.004 : 0.005)
bullet[me] = Bodies.circle(mech.pos.x + 25 * Math.cos(DIR), mech.pos.y + 25 * Math.sin(DIR), 10, {
angle: DIR,
cycle: -0.43, //adjust this number until the bullets line up with the cross hairs
endCycle: game.cycle + (mech.crouch ? 155 : 120),
inertia: Infinity,
frictionAir: 0,
minDmgSpeed: 0,
dmg: 0.13, //damage done in addition to the damage from momentum
classType: "bullet",
collisionFilter: {
category: 0x000100,
mask: 0x000010
},
onDmg() {},
onEnd() {},
do() {
//wiggle
this.cycle++
const THRUST = wiggleMag * Math.cos(this.cycle * 0.3)
this.force = Matter.Vector.mult(Matter.Vector.normalise(this.direction), this.mass * THRUST)
//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
mech.fireCDcycle = game.cycle + (mech.crouch ? 8 : 4); // cool down
const SPEED = mech.crouch ? 5.2 : 4.5;
Matter.Body.setVelocity(bullet[me], {
x: SPEED * Math.cos(DIR),
y: SPEED * Math.sin(DIR)
});
bullet[me].direction = Matter.Vector.perp(bullet[me].velocity)
// if (mech.angle + Math.PI / 2 > 0) {
// bullet[me].direction = Matter.Vector.perp(bullet[me].velocity, true)
// } else {
// bullet[me].direction = Matter.Vector.perp(bullet[me].velocity)
// }
World.add(engine.world, bullet[me]); //add bullet to world
} }
}, },
{ {
@@ -436,12 +490,12 @@ const b = {
fire() { fire() {
b.muzzleFlash(20); b.muzzleFlash(20);
// mobs.alert(450); // mobs.alert(450);
const SPREAD = mech.crouch ? 0.03 : 0.14 const SPREAD = mech.crouch ? 0.04 : 0.14
let dir = mech.angle - SPREAD; let dir = mech.angle - SPREAD;
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
const me = bullet.length; const me = bullet.length;
bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 7, b.fireAttributes(dir)); bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 7, b.fireAttributes(dir));
b.fireProps(mech.crouch ? 30 : 20, mech.crouch ? 34 : 27, dir, me); //cd , speed b.fireProps(mech.crouch ? 40 : 20, mech.crouch ? 34 : 26, dir, me); //cd , speed
Matter.Body.setDensity(bullet[me], 0.0001); Matter.Body.setDensity(bullet[me], 0.0001);
bullet[me].endCycle = game.cycle + 360; bullet[me].endCycle = game.cycle + 360;
bullet[me].dmg = 0.5; bullet[me].dmg = 0.5;
@@ -465,21 +519,20 @@ const b = {
// mobs.alert(650); // mobs.alert(650);
for (let i = 0; i < 9; i++) { for (let i = 0; i < 9; i++) {
const me = bullet.length; const me = bullet.length;
const dir = mech.angle + (Math.random() - 0.5) * (mech.crouch ? 0.1 : 0.6) const dir = mech.angle + (Math.random() - 0.5) * (mech.crouch ? 0.2 : 0.6)
bullet[me] = Bodies.rectangle( 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), 11, 11, b.fireAttributes(dir));
mech.pos.x + 35 * Math.cos(mech.angle) + 15 * (Math.random() - 0.5), b.fireProps(mech.crouch ? 60 : 30, 36 + Math.random() * 11, dir, me); //cd , speed
mech.pos.y + 35 * Math.sin(mech.angle) + 15 * (Math.random() - 0.5),
11,
11,
b.fireAttributes(dir)
);
b.fireProps(mech.crouch ? 40 : 30, 36 + Math.random() * 11, dir, me); //cd , speed
bullet[me].endCycle = game.cycle + 60; bullet[me].endCycle = game.cycle + 60;
bullet[me].frictionAir = 0.02; bullet[me].frictionAir = 0.02;
bullet[me].do = function () { bullet[me].do = function () {
this.force.y += this.mass * 0.001; this.force.y += this.mass * 0.001;
}; };
} }
//knock back
const KNOCK = (mech.crouch) ? 0.015 : 0.15
player.force.x -= KNOCK * Math.cos(mech.angle)
player.force.y -= KNOCK * Math.sin(mech.angle) * 0.5 //reduce knock back in vertical direction to stop super jumps
} }
}, },
{ {
@@ -491,9 +544,9 @@ const b = {
const me = bullet.length; const me = bullet.length;
const dir = mech.angle; const dir = mech.angle;
bullet[me] = Bodies.rectangle(mech.pos.x + 40 * Math.cos(mech.angle), mech.pos.y + 40 * Math.sin(mech.angle), 31, 2, b.fireAttributes(dir)); bullet[me] = Bodies.rectangle(mech.pos.x + 40 * Math.cos(mech.angle), mech.pos.y + 40 * Math.sin(mech.angle), 31, 2, b.fireAttributes(dir));
b.fireProps((mech.crouch ? 17 : 23), 45, dir, me); //cd , speed b.fireProps(mech.crouch ? 40 : 20, mech.crouch ? 45 : 37, dir, me); //cd , speed
bullet[me].endCycle = game.cycle + 180; bullet[me].endCycle = game.cycle + 180;
bullet[me].dmg = 1; bullet[me].dmg = mech.crouch ? 1.35 : 1;
b.drawOneBullet(bullet[me].vertices); b.drawOneBullet(bullet[me].vertices);
bullet[me].do = function () { bullet[me].do = function () {
//low gravity //low gravity
@@ -509,103 +562,88 @@ const b = {
fireCycle: 0, fireCycle: 0,
ammoLoaded: 0, ammoLoaded: 0,
fire() { fire() {
//calculate how many new missiles have loaded since the last time fired const thrust = 0.0003;
const ammoLoadTime = 36 let dir = mech.angle + (0.5 - Math.random()) * (mech.crouch ? 0 : 0.2);
const maxLoaded = 6 const me = bullet.length;
this.ammoLoaded += Math.floor(Math.abs(game.cycle - this.fireCycle) / ammoLoadTime) bullet[me] = Bodies.rectangle(mech.pos.x + 40 * Math.cos(mech.angle), mech.pos.y + 40 * Math.sin(mech.angle) - 3, 30, 4, b.fireAttributes(dir));
this.ammoLoaded = Math.min(maxLoaded, this.ammoLoaded) b.fireProps(mech.crouch ? 70 : 30, -3 * (0.5 - Math.random()) + (mech.crouch ? 25 : -8), dir, me); //cd , speed
b.drawOneBullet(bullet[me].vertices);
if (this.ammoLoaded < 1) { // Matter.Body.setDensity(bullet[me], 0.01) //doesn't help with reducing explosion knock backs
mech.fireCDcycle = game.cycle + ammoLoadTime; // cool down if no ammo loaded bullet[me].force.y += 0.00045; //a small push down at first to make it seem like the missile is briefly falling
this.ammo++; //counteract the normal ammo reduction by adding back one if not firing bullet[me].frictionAir = 0
} else { bullet[me].endCycle = game.cycle + Math.floor(265 + Math.random() * 20);
this.fireCycle = game.cycle //keep track of last time fired to calculate ammo loaded bullet[me].explodeRad = 150 + 40 * Math.random();
this.ammoLoaded-- bullet[me].lookFrequency = Math.floor(8 + Math.random() * 7);
bullet[me].onEnd = b.explode; //makes bullet do explosive damage at end
const thrust = 0.0003; bullet[me].onDmg = function () {
let dir = mech.angle + (0.5 - Math.random()) * (mech.crouch ? 0 : 0.1); this.endCycle = 0; //bullet ends cycle after doing damage // also triggers explosion
const me = bullet.length; };
bullet[me] = Bodies.rectangle(mech.pos.x + 40 * Math.cos(mech.angle), mech.pos.y + 40 * Math.sin(mech.angle) - 3, 30, 4, b.fireAttributes(dir)); bullet[me].lockedOn = null;
b.fireProps(mech.crouch ? 25 : 6, -3 * (0.5 - Math.random()) + (mech.crouch ? 15 : -8), dir, me); //cd , speed bullet[me].do = function () {
b.drawOneBullet(bullet[me].vertices); if (!(game.cycle % this.lookFrequency)) {
// Matter.Body.setDensity(bullet[me], 0.01) //doesn't help with reducing explosion knock backs this.close = null;
bullet[me].force.y += 0.00045; //a small push down at first to make it seem like the missile is briefly falling this.lockedOn = null;
bullet[me].frictionAir = 0 let closeDist = Infinity;
bullet[me].endCycle = game.cycle + Math.floor(265 + Math.random() * 20); for (let i = 0, len = mob.length; i < len; ++i) {
bullet[me].explodeRad = 145 + 40 * Math.random(); if (
bullet[me].lookFrequency = Math.floor(8 + Math.random() * 7); mob[i].alive &&
bullet[me].onEnd = b.explode; //makes bullet do explosive damage at end mob[i].dropPowerUp &&
bullet[me].onDmg = function () { Matter.Query.ray(map, this.position, mob[i].position).length === 0 &&
this.endCycle = 0; //bullet ends cycle after doing damage // also triggers explosion Matter.Query.ray(body, this.position, mob[i].position).length === 0
}; ) {
bullet[me].lockedOn = null; const dist = Matter.Vector.magnitude(Matter.Vector.sub(this.position, mob[i].position));
bullet[me].do = function () { if (dist < closeDist) {
if (!(game.cycle % this.lookFrequency)) { this.close = mob[i].position;
this.close = null; closeDist = dist;
this.lockedOn = null; this.lockedOn = mob[i];
let closeDist = Infinity;
for (let i = 0, len = mob.length; i < len; ++i) {
if (
mob[i].alive &&
mob[i].dropPowerUp &&
Matter.Query.ray(map, this.position, mob[i].position).length === 0 &&
Matter.Query.ray(body, this.position, mob[i].position).length === 0
) {
const dist = Matter.Vector.magnitude(Matter.Vector.sub(this.position, mob[i].position));
if (dist < closeDist) {
this.close = mob[i].position;
closeDist = dist;
this.lockedOn = mob[i];
}
}
}
//explode when bullet is close enough to target
if (this.close && 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.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 //explode when bullet is close enough to target
const dir = this.angle; // + (Math.random() - 0.5); if (this.close && closeDist < this.explodeRad * 0.7) {
this.force.x += Math.cos(dir) * thrust; this.endCycle = 0; //bullet ends cycle after doing damage //this also triggers explosion
this.force.y += Math.sin(dir) * thrust; }
//draw rocket if (this.lockedOn) {
ctx.beginPath(); this.frictionAir = 0.04; //extra friction
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();
//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.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();
} }
} }
}, },
@@ -617,18 +655,21 @@ const b = {
fire() { fire() {
b.muzzleFlash(30); b.muzzleFlash(30);
const totalBullets = 5 const totalBullets = 5
const angleStep = 0.08 / totalBullets const angleStep = (mech.crouch ? 0.06 : 0.15) / totalBullets
const SPEED = mech.crouch ? 27 : 20
const CD = mech.crouch ? 50 : 20
const END = mech.crouch ? 27 : 18
let dir = mech.angle - angleStep * totalBullets / 2; let dir = mech.angle - angleStep * totalBullets / 2;
for (let i = 0; i < totalBullets; i++) { //5 -> 7 for (let i = 0; i < totalBullets; i++) { //5 -> 7
dir += angleStep dir += angleStep
const me = bullet.length; const me = bullet.length;
bullet[me] = Bodies.rectangle(mech.pos.x + 50 * Math.cos(mech.angle), mech.pos.y + 50 * Math.sin(mech.angle), 17, 4, b.fireAttributes(dir)); bullet[me] = Bodies.rectangle(mech.pos.x + 50 * Math.cos(mech.angle), mech.pos.y + 50 * Math.sin(mech.angle), 17, 4, b.fireAttributes(dir));
b.fireProps(mech.crouch ? 30 : 20, 24 + 30 * Math.random() - i, dir, me); //cd , speed b.fireProps(CD, SPEED + 25 * Math.random() - i, dir, me); //cd , speed
//Matter.Body.setDensity(bullet[me], 0.00001); //Matter.Body.setDensity(bullet[me], 0.00001);
bullet[me].endCycle = i + game.cycle + (mech.crouch ? 29 : 18) bullet[me].endCycle = i + game.cycle + END
bullet[me].restitution = 0; bullet[me].restitution = 0;
bullet[me].friction = 1; bullet[me].friction = 1;
bullet[me].explodeRad = 70 + (Math.random() - 0.5) * 50; bullet[me].explodeRad = 75 + (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
@@ -659,7 +700,7 @@ const b = {
bullet[me].totalCycles = 120; bullet[me].totalCycles = 120;
bullet[me].endCycle = game.cycle + bullet[me].totalCycles; bullet[me].endCycle = game.cycle + bullet[me].totalCycles;
bullet[me].restitution = 0.6; bullet[me].restitution = 0.6;
bullet[me].explodeRad = 125; bullet[me].explodeRad = 130;
bullet[me].onEnd = b.explode; //makes bullet do explosive damage before despawn bullet[me].onEnd = b.explode; //makes bullet do explosive damage before despawn
bullet[me].minDmgSpeed = 1; bullet[me].minDmgSpeed = 1;
bullet[me].dmg = 0.25; bullet[me].dmg = 0.25;
@@ -675,7 +716,7 @@ const b = {
{ {
name: "grenades", name: "grenades",
ammo: 0, ammo: 0,
ammoPack: 4, ammoPack: 5,
have: false, have: false,
fire() { fire() {
const me = bullet.length; const me = bullet.length;
@@ -692,7 +733,7 @@ const b = {
bullet[me].restitution = 0; bullet[me].restitution = 0;
bullet[me].friction = 1; bullet[me].friction = 1;
bullet[me].explodeRad = 350 + Math.floor(Math.random() * 60); bullet[me].explodeRad = 380 + Math.floor(Math.random() * 60);
bullet[me].onEnd = b.explode; //makes bullet do explosive damage before despawn bullet[me].onEnd = b.explode; //makes bullet do explosive damage before despawn
bullet[me].minDmgSpeed = 1; bullet[me].minDmgSpeed = 1;
bullet[me].onDmg = function () { bullet[me].onDmg = function () {
@@ -732,7 +773,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 ? 45 : 25, mech.crouch ? 26 : 17, dir, me); //cd , speed b.fireProps(mech.crouch ? 60 : 35, mech.crouch ? 30 : 17, 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;
@@ -757,7 +798,7 @@ const b = {
//spawn bullets on end //spawn bullets on end
bullet[me].onEnd = function () { bullet[me].onEnd = function () {
const NUM = 11; const NUM = 12;
for (let i = 0; i < NUM; i++) { for (let i = 0; i < NUM; i++) {
const bIndex = bullet.length; const bIndex = bullet.length;
const RADIUS = 4 + 2 * Math.random(); const RADIUS = 4 + 2 * Math.random();
@@ -767,7 +808,7 @@ const b = {
angle: dir, angle: dir,
friction: 0, friction: 0,
frictionAir: 0.01, frictionAir: 0.01,
dmg: 1.3, //damage done in addition to the damage from momentum dmg: 1, //damage done in addition to the damage from momentum
classType: "bullet", classType: "bullet",
collisionFilter: { collisionFilter: {
category: 0x000100, category: 0x000100,
@@ -829,7 +870,7 @@ const b = {
{ {
name: "drones", name: "drones",
ammo: 0, ammo: 0,
ammoPack: 25, ammoPack: 27,
have: false, have: false,
fire() { fire() {
const THRUST = 0.0015 const THRUST = 0.0015
@@ -841,7 +882,7 @@ const b = {
friction: 0, friction: 0,
frictionAir: 0.0005, frictionAir: 0.0005,
restitution: 1, restitution: 1,
dmg: 0.18, //damage done in addition to the damage from momentum dmg: 0.15, //damage done in addition to the damage from momentum
lookFrequency: 79 + Math.floor(32 * Math.random()), lookFrequency: 79 + Math.floor(32 * Math.random()),
endCycle: game.cycle + 720 + 300 * Math.random(), endCycle: game.cycle + 720 + 300 * Math.random(),
classType: "bullet", classType: "bullet",
@@ -904,142 +945,6 @@ const b = {
// }; // };
} }
}, },
{
name: "wave beam",
ammo: 0,
ammoPack: 120,
have: false,
fire() {
const me = bullet.length;
const DIR = mech.angle
const wiggleMag = ((mech.flipLegs === 1) ? 1 : -1) * ((mech.crouch) ? 0.0025 : 0.0045)
bullet[me] = Bodies.circle(mech.pos.x + 25 * Math.cos(DIR), mech.pos.y + 25 * Math.sin(DIR), 10, {
angle: DIR,
cycle: -0.43, //adjust this number until the bullets line up with the cross hairs
endCycle: game.cycle + 125,
inertia: Infinity,
frictionAir: 0,
minDmgSpeed: 0,
dmg: 0.15, //damage done in addition to the damage from momentum
classType: "bullet",
collisionFilter: {
category: 0x000100,
mask: 0x000010
},
onDmg() {
// this.endCycle = 0; //bullet ends cycle after doing damage
//recalculate the direction of wiggle
// this.direction = Matter.Vector.perp(this.velocity)
},
onEnd() {},
do() {
//wiggle
this.cycle++
const THRUST = wiggleMag * Math.cos(this.cycle * 0.3)
this.force = Matter.Vector.mult(Matter.Vector.normalise(this.direction), this.mass * THRUST)
//shrink
if (this.cycle > 0 && !(Math.floor(this.cycle) % 6)) {
const SCALE = 0.95
Matter.Body.scale(this, SCALE, SCALE);
}
}
});
World.add(engine.world, bullet[me]); //add bullet to world
mech.fireCDcycle = game.cycle + (mech.crouch ? 6 : 4); // cool down
const SPEED = mech.crouch ? 6 : 4.5;
Matter.Body.setVelocity(bullet[me], {
x: SPEED * Math.cos(DIR),
y: SPEED * Math.sin(DIR)
});
bullet[me].direction = Matter.Vector.perp(bullet[me].velocity)
// if (mech.angle + Math.PI / 2 > 0) {
// bullet[me].direction = Matter.Vector.perp(bullet[me].velocity, true)
// } else {
// bullet[me].direction = Matter.Vector.perp(bullet[me].velocity)
// }
World.add(engine.world, bullet[me]); //add bullet to world
}
},
// {
// name: "wave beam",
// ammo: 0,
// ammoPack: 120,
// have: false,
// fire() {
// mech.fireCDcycle = game.cycle + 7; // cool down
// const endCycle = game.cycle + 94
// const bulletRadius = 5;
// const speed = 35;
// const spread = Math.PI / 2 * 0.65 // smaller = faster speed, larger = faster rotation?
// const dir = mech.angle
// const pos = {
// x: mech.pos.x + 20 * Math.cos(mech.angle),
// y: mech.pos.y + 20 * Math.sin(mech.angle)
// }
// const props = {
// angle: dir,
// endCycle: endCycle,
// inertia: Infinity,
// restitution: 1,
// friction: 1,
// frictionAir: -0.003,
// minDmgSpeed: 0,
// isConstrained: true,
// dmg: 0, //damage done in addition to the damage from momentum
// classType: "bullet",
// collisionFilter: {
// category: 0x000100,
// mask: 0x000010
// },
// onDmg() {
// if (this.isConstrained) {
// this.isConstrained = false
// b.removeConsBB(this)
// // this.endCycle = 0 //triggers despawn
// }
// },
// onEnd() {
// if (this.isConstrained) {
// this.isConstrained = false
// b.removeConsBB(this)
// }
// },
// do() {}
// }
// //first bullet
// const me = bullet.length;
// bullet[me] = Bodies.circle(pos.x, pos.y, bulletRadius, props);
// Matter.Body.setVelocity(bullet[me], {
// x: speed * Math.cos(dir + spread),
// y: speed * Math.sin(dir + spread)
// });
// World.add(engine.world, bullet[me]); //add bullet to world
// // Matter.Body.setDensity(bullet[me], 0.0005); //0.001 is normal
// //second bullet
// const me2 = bullet.length;
// bullet[me2] = Bodies.circle(pos.x, pos.y, bulletRadius, props);
// Matter.Body.setVelocity(bullet[me2], {
// x: speed * Math.cos(dir - spread),
// y: speed * Math.sin(dir - spread)
// });
// World.add(engine.world, bullet[me2]); //add bullet to world
// // Matter.Body.setDensity(bullet[me2], 0.0005); //0.001 is normal
// //constraint
// const meCons = consBB.length
// consBB[meCons] = Constraint.create({
// bodyA: bullet[me],
// bodyB: bullet[me2],
// stiffness: 0.008
// });
// World.add(engine.world, consBB[meCons]);
// }
// }
], ],
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) && !mech.isHolding && b.inventory.length) {

View File

@@ -44,9 +44,6 @@ specific gun power ups
drones: last longer drones: last longer
wave beam: longer range wave beam: longer range
down key to modify gun
needles: +dmg, slower fire rate
game mechanics game mechanics
mechanics that support the physics engine mechanics that support the physics engine
add rope/constraint add rope/constraint

View File

@@ -13,8 +13,8 @@ const level = {
// game.zoomScale = 1400 //1400 // game.zoomScale = 1400 //1400
if (game.levelsCleared === 0) { if (game.levelsCleared === 0) {
this.intro(); //starting level this.intro(); //starting level
// b.giveGuns(11) // set a starting gun for testing // b.giveGuns(0) // set a starting gun for testing
// game.levelsCleared = 3; //for testing to simulate all possible mobs spawns // game.levelsCleared = 3; //for testing to simulate possible mobs spawns
// this.bosses(); // this.bosses();
// this.testingMap(); // this.testingMap();
// this.skyscrapers(); // this.skyscrapers();
@@ -37,8 +37,8 @@ const level = {
game.zoomScale = 1400 //1400 is normal game.zoomScale = 1400 //1400 is normal
game.zoomTransition(1400) game.zoomTransition(1400)
spawn.setSpawnList(); spawn.setSpawnList();
game.levelsCleared = 7; //for testing to simulate all possible mobs spawns game.levelsCleared = 3; //for testing to simulate all possible mobs spawns
for (let i = 0; i < 7; i++) { for (let i = 0; i < game.levelsCleared; i++) {
game.dmgScale += 0.4; //damage done by mobs increases each level game.dmgScale += 0.4; //damage done by mobs increases each level
b.dmgScale *= 0.9; //damage done by player decreases each level b.dmgScale *= 0.9; //damage done by player decreases each level
} }
@@ -109,15 +109,15 @@ const level = {
// spawn.bodyRect(600, -150, 140, 100); // spawn.bodyRect(600, -150, 140, 100);
// spawn.bodyRect(400, -150, 140, 160); // spawn.bodyRect(400, -150, 140, 160);
// spawn.bodyRect(500, -150, 110, 110); // spawn.bodyRect(500, -150, 110, 110);
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.starter(800, -1150); // spawn.starter(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.chaser(800, -1150); spawn.shooter(800, -1150);
// } // }
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);
// } // }
@@ -497,13 +497,14 @@ const level = {
spawn.boost(1800, -1000, 1200); spawn.boost(1800, -1000, 1200);
spawn.bodyRect(1625, -1100, 100, 75); spawn.bodyRect(1625, -1100, 100, 75);
spawn.bodyRect(1350, -1025, 400, 25); // ground plank spawn.bodyRect(1350, -1025, 400, 25); // ground plank
spawn.mapRect(-700, -1000, 2100, 100); //lower left ledge spawn.mapRect(-725, -1000, 2150, 100); //lower left ledge
spawn.bodyRect(350, -1100, 200, 100, 0.8); spawn.bodyRect(350, -1100, 200, 100, 0.8);
spawn.bodyRect(370, -1200, 100, 100, 0.8); spawn.bodyRect(370, -1200, 100, 100, 0.8);
spawn.bodyRect(360, -1300, 100, 100, 0.8); spawn.bodyRect(360, -1300, 100, 100, 0.8);
spawn.bodyRect(950, -1050, 300, 50, 0.8); spawn.bodyRect(950, -1050, 300, 50, 0.8);
spawn.bodyRect(-600, -1250, 400, 250, 0.8); spawn.bodyRect(-600, -1250, 400, 250, 0.8);
spawn.mapRect(1600, -1000, 1650, 100); //middle ledge spawn.mapRect(1575, -1000, 1700, 100); //middle ledge
spawn.mapRect(3400, -1000, 75, 25);
spawn.bodyRect(2600, -1950, 100, 250, 0.8); spawn.bodyRect(2600, -1950, 100, 250, 0.8);
spawn.bodyRect(2700, -1125, 125, 125, 0.8); spawn.bodyRect(2700, -1125, 125, 125, 0.8);
spawn.bodyRect(2710, -1250, 125, 125, 0.8); spawn.bodyRect(2710, -1250, 125, 125, 0.8);

View File

@@ -884,7 +884,7 @@ const mobs = {
Matter.Body.setAngle(this, angle - Math.PI); Matter.Body.setAngle(this, angle - Math.PI);
}, },
explode() { explode() {
mech.damage(Math.min(Math.max(0.02 * Math.sqrt(this.mass), 0.05), 0.35) * game.dmgScale); mech.damage(Math.min(Math.max(0.02 * Math.sqrt(this.mass), 0.01), 0.35) * game.dmgScale);
this.dropPowerUp = false; this.dropPowerUp = false;
this.death(); //death with no power up or body this.death(); //death with no power up or body
}, },

View File

@@ -415,9 +415,6 @@ const mech = {
}, },
defaultFPSCycle: 0, //tracks when to return to normal fps defaultFPSCycle: 0, //tracks when to return to normal fps
damage(dmg) { damage(dmg) {
if (dmg * player.mass > 0.35) {
this.drop(); //drop block if holding
}
this.health -= dmg; this.health -= dmg;
if (this.health < 0) { if (this.health < 0) {
this.health = 0; this.health = 0;
@@ -425,6 +422,13 @@ const mech = {
return; return;
} }
this.displayHealth(); this.displayHealth();
document.getElementById("dmg").style.transition = "opacity 0s";
document.getElementById("dmg").style.opacity = 0.1 + Math.min(0.6, dmg * 4);
//drop block if holding
if (dmg > 0.07) {
this.drop();
}
// freeze game and display a full screen red color // freeze game and display a full screen red color
if (dmg > 0.05) { if (dmg > 0.05) {
@@ -434,9 +438,8 @@ const mech = {
game.fpsCap = 72 game.fpsCap = 72
game.fpsInterval = 1000 / game.fpsCap; game.fpsInterval = 1000 / game.fpsCap;
} }
document.getElementById("dmg").style.transition = "opacity 0s";
document.getElementById("dmg").style.opacity = 0.1 + Math.min(0.6, dmg * 4);
mech.defaultFPSCycle = game.cycle mech.defaultFPSCycle = game.cycle
const normalFPS = function () { const normalFPS = function () {
if (mech.defaultFPSCycle < game.cycle) { //back to default values if (mech.defaultFPSCycle < game.cycle) { //back to default values
game.fpsCap = 72 game.fpsCap = 72

View File

@@ -66,9 +66,14 @@ const powerUps = {
if (b.inventory.length > 0) { if (b.inventory.length > 0) {
//add ammo to a gun in inventory //add ammo to a gun in inventory
target = b.guns[b.inventory[Math.floor(Math.random() * (b.inventory.length))]]; target = b.guns[b.inventory[Math.floor(Math.random() * (b.inventory.length))]];
//try twice to give ammo to a gun with ammo, not Infinity //try 3 more times to give ammo to a gun with ammo, not Infinity
if (target.ammo === Infinity) target = b.guns[Math.floor(Math.random() * b.guns.length)]; if (target.ammo === Infinity) {
if (target.ammo === Infinity) target = b.guns[Math.floor(Math.random() * b.guns.length)]; target = b.guns[b.inventory[Math.floor(Math.random() * (b.inventory.length))]]
if (target.ammo === Infinity) {
target = b.guns[b.inventory[Math.floor(Math.random() * (b.inventory.length))]]
if (target.ammo === Infinity) target = b.guns[b.inventory[Math.floor(Math.random() * (b.inventory.length))]]
}
}
} else { } else {
//if you don't have any guns just add ammo to a random gun you don't have yet //if you don't have any guns just add ammo to a random gun you don't have yet
target = b.guns[Math.floor(Math.random() * b.guns.length)]; target = b.guns[Math.floor(Math.random() * b.guns.length)];
@@ -78,12 +83,11 @@ const powerUps = {
game.makeTextLog("+energy", 180); game.makeTextLog("+energy", 180);
} else { } else {
//ammo given scales as mobs take more hits to kill //ammo given scales as mobs take more hits to kill
const ammo = Math.ceil((target.ammoPack * (0.60 + 0.5 * Math.random())) / b.dmgScale); const ammo = Math.ceil((target.ammoPack * (0.70 + 0.2 * Math.random())) / b.dmgScale);
target.ammo += ammo; target.ammo += ammo;
game.updateGunHUD(); game.updateGunHUD();
game.makeTextLog("+" + ammo + " ammo: " + target.name, 180); game.makeTextLog("+" + ammo + " ammo: " + target.name, 180);
} }
} }
}, },
gun: { gun: {

View File

@@ -858,9 +858,10 @@ const spawn = {
let me = mob[mob.length - 1]; let me = mob[mob.length - 1];
me.stroke = "transparent"; me.stroke = "transparent";
me.onHit = function () { me.onHit = function () {
console.log(this.mass)
this.explode(); this.explode();
}; };
Matter.Body.setDensity(me, 0.002); //normal is 0.001 Matter.Body.setDensity(me, 0.001); //normal is 0.001
me.timeLeft = 240; me.timeLeft = 240;
me.g = 0.001; //required if using 'gravity' me.g = 0.001; //required if using 'gravity'
me.frictionAir = 0; me.frictionAir = 0;