general balancing around crouch alt fire
This commit is contained in:
461
js/bullets.js
461
js/bullets.js
@@ -207,7 +207,7 @@ const b = {
|
||||
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.y += knock.y;
|
||||
damageScale *= 0.85
|
||||
damageScale *= 0.7 //reduced damage for each additional explosion target
|
||||
} else if (!mob[i].seePlayer.recall && dist < alertRange) {
|
||||
mob[i].locatePlayer();
|
||||
knock = Matter.Vector.mult(Matter.Vector.normalise(sub), (-Math.sqrt(dmg * damageScale) * mob[i].mass) / 35);
|
||||
@@ -236,7 +236,7 @@ const b = {
|
||||
fire() {
|
||||
// mech.fireCDcycle = game.cycle + 1
|
||||
//laser drains energy as well as bullets
|
||||
const FIELD_DRAIN = 0.006
|
||||
const FIELD_DRAIN = 0.004
|
||||
if (mech.fieldMeter < FIELD_DRAIN) {
|
||||
mech.fireCDcycle = game.cycle + 100; // cool down if out of energy
|
||||
} else {
|
||||
@@ -308,7 +308,7 @@ const b = {
|
||||
};
|
||||
const laserHitMob = function (dmg) {
|
||||
if (best.who.alive) {
|
||||
dmg *= b.dmgScale * 0.05;
|
||||
dmg *= b.dmgScale * 0.045;
|
||||
best.who.damage(dmg);
|
||||
best.who.locatePlayer();
|
||||
//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",
|
||||
ammo: 0,
|
||||
ammoPack: 4,
|
||||
ammoPack: 5,
|
||||
have: false,
|
||||
fire() {
|
||||
b.muzzleFlash(45);
|
||||
@@ -416,16 +397,89 @@ const b = {
|
||||
const me = bullet.length;
|
||||
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));
|
||||
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].do = function () {
|
||||
this.force.y += this.mass * 0.0005;
|
||||
};
|
||||
|
||||
//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.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() {
|
||||
b.muzzleFlash(20);
|
||||
// mobs.alert(450);
|
||||
const SPREAD = mech.crouch ? 0.03 : 0.14
|
||||
const SPREAD = mech.crouch ? 0.04 : 0.14
|
||||
let dir = mech.angle - SPREAD;
|
||||
for (let i = 0; i < 3; i++) {
|
||||
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));
|
||||
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);
|
||||
bullet[me].endCycle = game.cycle + 360;
|
||||
bullet[me].dmg = 0.5;
|
||||
@@ -465,21 +519,20 @@ const b = {
|
||||
// mobs.alert(650);
|
||||
for (let i = 0; i < 9; i++) {
|
||||
const me = bullet.length;
|
||||
const dir = mech.angle + (Math.random() - 0.5) * (mech.crouch ? 0.1 : 0.6)
|
||||
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)
|
||||
);
|
||||
b.fireProps(mech.crouch ? 40 : 30, 36 + Math.random() * 11, dir, me); //cd , speed
|
||||
const dir = mech.angle + (Math.random() - 0.5) * (mech.crouch ? 0.2 : 0.6)
|
||||
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));
|
||||
b.fireProps(mech.crouch ? 60 : 30, 36 + Math.random() * 11, dir, me); //cd , speed
|
||||
bullet[me].endCycle = game.cycle + 60;
|
||||
bullet[me].frictionAir = 0.02;
|
||||
bullet[me].do = function () {
|
||||
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 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));
|
||||
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].dmg = 1;
|
||||
bullet[me].dmg = mech.crouch ? 1.35 : 1;
|
||||
b.drawOneBullet(bullet[me].vertices);
|
||||
bullet[me].do = function () {
|
||||
//low gravity
|
||||
@@ -509,103 +562,88 @@ const b = {
|
||||
fireCycle: 0,
|
||||
ammoLoaded: 0,
|
||||
fire() {
|
||||
//calculate how many new missiles have loaded since the last time fired
|
||||
const ammoLoadTime = 36
|
||||
const maxLoaded = 6
|
||||
this.ammoLoaded += Math.floor(Math.abs(game.cycle - this.fireCycle) / ammoLoadTime)
|
||||
this.ammoLoaded = Math.min(maxLoaded, this.ammoLoaded)
|
||||
|
||||
if (this.ammoLoaded < 1) {
|
||||
mech.fireCDcycle = game.cycle + ammoLoadTime; // cool down if no ammo loaded
|
||||
this.ammo++; //counteract the normal ammo reduction by adding back one if not firing
|
||||
} else {
|
||||
this.fireCycle = game.cycle //keep track of last time fired to calculate ammo loaded
|
||||
this.ammoLoaded--
|
||||
|
||||
const thrust = 0.0003;
|
||||
let dir = mech.angle + (0.5 - Math.random()) * (mech.crouch ? 0 : 0.1);
|
||||
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));
|
||||
b.fireProps(mech.crouch ? 25 : 6, -3 * (0.5 - Math.random()) + (mech.crouch ? 15 : -8), dir, me); //cd , speed
|
||||
b.drawOneBullet(bullet[me].vertices);
|
||||
// Matter.Body.setDensity(bullet[me], 0.01) //doesn't help with reducing explosion knock backs
|
||||
bullet[me].force.y += 0.00045; //a small push down at first to make it seem like the missile is briefly falling
|
||||
bullet[me].frictionAir = 0
|
||||
bullet[me].endCycle = game.cycle + Math.floor(265 + Math.random() * 20);
|
||||
bullet[me].explodeRad = 145 + 40 * Math.random();
|
||||
bullet[me].lookFrequency = Math.floor(8 + Math.random() * 7);
|
||||
bullet[me].onEnd = b.explode; //makes bullet do explosive damage at end
|
||||
bullet[me].onDmg = function () {
|
||||
this.endCycle = 0; //bullet ends cycle after doing damage // also triggers explosion
|
||||
};
|
||||
bullet[me].lockedOn = null;
|
||||
bullet[me].do = function () {
|
||||
if (!(game.cycle % this.lookFrequency)) {
|
||||
this.close = null;
|
||||
this.lockedOn = null;
|
||||
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);
|
||||
const thrust = 0.0003;
|
||||
let dir = mech.angle + (0.5 - Math.random()) * (mech.crouch ? 0 : 0.2);
|
||||
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));
|
||||
b.fireProps(mech.crouch ? 70 : 30, -3 * (0.5 - Math.random()) + (mech.crouch ? 25 : -8), dir, me); //cd , speed
|
||||
b.drawOneBullet(bullet[me].vertices);
|
||||
// Matter.Body.setDensity(bullet[me], 0.01) //doesn't help with reducing explosion knock backs
|
||||
bullet[me].force.y += 0.00045; //a small push down at first to make it seem like the missile is briefly falling
|
||||
bullet[me].frictionAir = 0
|
||||
bullet[me].endCycle = game.cycle + Math.floor(265 + Math.random() * 20);
|
||||
bullet[me].explodeRad = 150 + 40 * Math.random();
|
||||
bullet[me].lookFrequency = Math.floor(8 + Math.random() * 7);
|
||||
bullet[me].onEnd = b.explode; //makes bullet do explosive damage at end
|
||||
bullet[me].onDmg = function () {
|
||||
this.endCycle = 0; //bullet ends cycle after doing damage // also triggers explosion
|
||||
};
|
||||
bullet[me].lockedOn = null;
|
||||
bullet[me].do = function () {
|
||||
if (!(game.cycle % this.lookFrequency)) {
|
||||
this.close = null;
|
||||
this.lockedOn = null;
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
//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;
|
||||
//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
|
||||
}
|
||||
|
||||
//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();
|
||||
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
|
||||
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() {
|
||||
b.muzzleFlash(30);
|
||||
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;
|
||||
for (let i = 0; i < totalBullets; i++) { //5 -> 7
|
||||
dir += angleStep
|
||||
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));
|
||||
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);
|
||||
bullet[me].endCycle = i + game.cycle + (mech.crouch ? 29 : 18)
|
||||
bullet[me].endCycle = i + game.cycle + END
|
||||
bullet[me].restitution = 0;
|
||||
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].onDmg = function () {
|
||||
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].endCycle = game.cycle + bullet[me].totalCycles;
|
||||
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].minDmgSpeed = 1;
|
||||
bullet[me].dmg = 0.25;
|
||||
@@ -675,7 +716,7 @@ const b = {
|
||||
{
|
||||
name: "grenades",
|
||||
ammo: 0,
|
||||
ammoPack: 4,
|
||||
ammoPack: 5,
|
||||
have: false,
|
||||
fire() {
|
||||
const me = bullet.length;
|
||||
@@ -692,7 +733,7 @@ const b = {
|
||||
bullet[me].restitution = 0;
|
||||
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].minDmgSpeed = 1;
|
||||
bullet[me].onDmg = function () {
|
||||
@@ -732,7 +773,7 @@ const b = {
|
||||
const me = bullet.length;
|
||||
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));
|
||||
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);
|
||||
Matter.Body.setDensity(bullet[me], 0.000001);
|
||||
bullet[me].endCycle = game.cycle + 100;
|
||||
@@ -757,7 +798,7 @@ const b = {
|
||||
|
||||
//spawn bullets on end
|
||||
bullet[me].onEnd = function () {
|
||||
const NUM = 11;
|
||||
const NUM = 12;
|
||||
for (let i = 0; i < NUM; i++) {
|
||||
const bIndex = bullet.length;
|
||||
const RADIUS = 4 + 2 * Math.random();
|
||||
@@ -767,7 +808,7 @@ const b = {
|
||||
angle: dir,
|
||||
friction: 0,
|
||||
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",
|
||||
collisionFilter: {
|
||||
category: 0x000100,
|
||||
@@ -829,7 +870,7 @@ const b = {
|
||||
{
|
||||
name: "drones",
|
||||
ammo: 0,
|
||||
ammoPack: 25,
|
||||
ammoPack: 27,
|
||||
have: false,
|
||||
fire() {
|
||||
const THRUST = 0.0015
|
||||
@@ -841,7 +882,7 @@ const b = {
|
||||
friction: 0,
|
||||
frictionAir: 0.0005,
|
||||
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()),
|
||||
endCycle: game.cycle + 720 + 300 * Math.random(),
|
||||
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() {
|
||||
if (game.mouseDown && mech.fireCDcycle < game.cycle && !(keys[32] || game.mouseDownRight) && !mech.isHolding && b.inventory.length) {
|
||||
|
||||
@@ -44,9 +44,6 @@ specific gun power ups
|
||||
drones: last longer
|
||||
wave beam: longer range
|
||||
|
||||
down key to modify gun
|
||||
needles: +dmg, slower fire rate
|
||||
|
||||
game mechanics
|
||||
mechanics that support the physics engine
|
||||
add rope/constraint
|
||||
|
||||
19
js/level.js
19
js/level.js
@@ -13,8 +13,8 @@ const level = {
|
||||
// game.zoomScale = 1400 //1400
|
||||
if (game.levelsCleared === 0) {
|
||||
this.intro(); //starting level
|
||||
// b.giveGuns(11) // set a starting gun for testing
|
||||
// game.levelsCleared = 3; //for testing to simulate all possible mobs spawns
|
||||
// b.giveGuns(0) // set a starting gun for testing
|
||||
// game.levelsCleared = 3; //for testing to simulate possible mobs spawns
|
||||
// this.bosses();
|
||||
// this.testingMap();
|
||||
// this.skyscrapers();
|
||||
@@ -37,8 +37,8 @@ const level = {
|
||||
game.zoomScale = 1400 //1400 is normal
|
||||
game.zoomTransition(1400)
|
||||
spawn.setSpawnList();
|
||||
game.levelsCleared = 7; //for testing to simulate all possible mobs spawns
|
||||
for (let i = 0; i < 7; i++) {
|
||||
game.levelsCleared = 3; //for testing to simulate all possible mobs spawns
|
||||
for (let i = 0; i < game.levelsCleared; i++) {
|
||||
game.dmgScale += 0.4; //damage done by mobs increases 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(400, -150, 140, 160);
|
||||
// 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);
|
||||
// spawn.bodyRect(-45, -100, 40, 50);
|
||||
// spawn.starter(800, -1150);
|
||||
// spawn.groupBoss(-600, -550);
|
||||
// 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++) {
|
||||
// spawn.randomBoss(-100, -1470);
|
||||
// }
|
||||
@@ -497,13 +497,14 @@ const level = {
|
||||
spawn.boost(1800, -1000, 1200);
|
||||
spawn.bodyRect(1625, -1100, 100, 75);
|
||||
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(370, -1200, 100, 100, 0.8);
|
||||
spawn.bodyRect(360, -1300, 100, 100, 0.8);
|
||||
spawn.bodyRect(950, -1050, 300, 50, 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(2700, -1125, 125, 125, 0.8);
|
||||
spawn.bodyRect(2710, -1250, 125, 125, 0.8);
|
||||
|
||||
@@ -884,7 +884,7 @@ const mobs = {
|
||||
Matter.Body.setAngle(this, angle - Math.PI);
|
||||
},
|
||||
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.death(); //death with no power up or body
|
||||
},
|
||||
|
||||
13
js/player.js
13
js/player.js
@@ -415,9 +415,6 @@ const mech = {
|
||||
},
|
||||
defaultFPSCycle: 0, //tracks when to return to normal fps
|
||||
damage(dmg) {
|
||||
if (dmg * player.mass > 0.35) {
|
||||
this.drop(); //drop block if holding
|
||||
}
|
||||
this.health -= dmg;
|
||||
if (this.health < 0) {
|
||||
this.health = 0;
|
||||
@@ -425,6 +422,13 @@ const mech = {
|
||||
return;
|
||||
}
|
||||
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
|
||||
if (dmg > 0.05) {
|
||||
@@ -434,9 +438,8 @@ const mech = {
|
||||
game.fpsCap = 72
|
||||
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
|
||||
|
||||
const normalFPS = function () {
|
||||
if (mech.defaultFPSCycle < game.cycle) { //back to default values
|
||||
game.fpsCap = 72
|
||||
|
||||
@@ -66,9 +66,14 @@ const powerUps = {
|
||||
if (b.inventory.length > 0) {
|
||||
//add ammo to a gun in inventory
|
||||
target = b.guns[b.inventory[Math.floor(Math.random() * (b.inventory.length))]];
|
||||
//try twice 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) target = b.guns[Math.floor(Math.random() * b.guns.length)];
|
||||
//try 3 more times to give ammo to a gun with ammo, not Infinity
|
||||
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))]]
|
||||
if (target.ammo === Infinity) target = b.guns[b.inventory[Math.floor(Math.random() * (b.inventory.length))]]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//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)];
|
||||
@@ -78,12 +83,11 @@ const powerUps = {
|
||||
game.makeTextLog("+energy", 180);
|
||||
} else {
|
||||
//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;
|
||||
game.updateGunHUD();
|
||||
game.makeTextLog("+" + ammo + " ammo: " + target.name, 180);
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
gun: {
|
||||
|
||||
@@ -858,9 +858,10 @@ const spawn = {
|
||||
let me = mob[mob.length - 1];
|
||||
me.stroke = "transparent";
|
||||
me.onHit = function () {
|
||||
console.log(this.mass)
|
||||
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.g = 0.001; //required if using 'gravity'
|
||||
me.frictionAir = 0;
|
||||
|
||||
Reference in New Issue
Block a user