added mod powerUps and balance
This commit is contained in:
280
js/bullets.js
280
js/bullets.js
@@ -3,6 +3,86 @@ let bullet = [];
|
||||
const b = {
|
||||
dmgScale: null, //scales all gun damage from momentum, but not raw .dmg //this is reset in game.reset
|
||||
gravity: 0.0006, //most other bodies have gravity = 0.001
|
||||
//variables use for gun mod upgrades
|
||||
mod: null,
|
||||
modFireRate: null,
|
||||
modExplosionRadius: null,
|
||||
modBulletSize: null,
|
||||
modEnergySiphon: null,
|
||||
modHealthDrain: null,
|
||||
modNoAmmoChance: null,
|
||||
modBulletsLastLonger: null,
|
||||
setModDefaults() {
|
||||
b.modFireRate = 1;
|
||||
b.modExplosionRadius = 1;
|
||||
b.modBulletSize = 1;
|
||||
b.modEnergySiphon = 0;
|
||||
b.modHealthDrain = 0;
|
||||
b.modNoAmmoChance = 0;
|
||||
b.modBulletsLastLonger = 1;
|
||||
},
|
||||
mods: [
|
||||
() => {
|
||||
b.mod = 0;
|
||||
game.makeTextLog("<strong style='font-size:30px;'>Auto-Loading Heuristics</strong><br> (left click)<p>your <strong>rate of fire</strong> 20% is faster</p>", 1200);
|
||||
b.setModDefaults(); //good for guns with extra ammo: needles, M80, rapid fire, flak, super balls
|
||||
b.modFireRate = 0.8
|
||||
},
|
||||
() => {
|
||||
b.mod = 1;
|
||||
game.makeTextLog("<strong style='font-size:30px;'>Anti-Matter Cores</strong><br> (left click)<p>your <strong>explosions</strong> are 25% larger and do more damage</p>", 1200);
|
||||
b.setModDefaults(); //at 1.4 gives a flat 40% increase, and increased range, balanced by limited guns and self damage
|
||||
//testing at 1.3: grenade(+0.3), missiles, flak, M80
|
||||
b.modExplosionRadius = 1.25; //good for guns with explosions:
|
||||
},
|
||||
() => {
|
||||
b.mod = 2;
|
||||
game.makeTextLog("<strong style='font-size:30px;'>High Caliber Bullets</strong><br> (left click)<p>your bullets are 8% <strong>larger</strong> and do more physical damage</p>", 1200);
|
||||
b.setModDefaults(); //good for guns that do mostly projectile damage:
|
||||
//testing done at 1.15: one shot(+0.38), rapid fire(+0.25), spray, wave beam(+0.4 adds range and dmg), needles(+0.1)
|
||||
//testing at 1.08: spray(point blank)(+0.25), one shot(+0.16), wave beam(point blank)(+0.14)
|
||||
b.modBulletSize = 1.08;
|
||||
},
|
||||
() => {
|
||||
b.mod = 3;
|
||||
game.makeTextLog("<strong style='font-size:30px;'>Energy Siphon</strong><br> (left click)<p>regenerate <strong>energy</strong> proportional to your damage done</p>", 1200);
|
||||
b.setModDefaults(); //good with laser, Nano-Scale Manufacturing, Standing Wave Harmonics, Phase Decoherence Field
|
||||
b.modEnergySiphon = 0.3;
|
||||
},
|
||||
() => {
|
||||
b.mod = 4;
|
||||
game.makeTextLog("<strong style='font-size:30px;'>Entropy Transfer</strong><br> (left click)<p><strong>heal</strong> proportional to your damage done</p>", 1200);
|
||||
b.setModDefaults(); //good with guns that overkill: one shot, grenade
|
||||
b.modHealthDrain = 0.015;
|
||||
},
|
||||
() => {
|
||||
b.mod = 5;
|
||||
game.makeTextLog("<strong style='font-size:30px;'>Desublimated Ammunition</strong><br> (left click)<p>25% chance you will not consume <strong>ammo</strong> when firing</p>", 1200);
|
||||
b.setModDefaults(); //good with guns that have less ammo: one shot, grenades, missiles, super balls, spray
|
||||
b.modNoAmmoChance = 0.25
|
||||
},
|
||||
() => {
|
||||
b.mod = 6;
|
||||
game.makeTextLog("<strong style='font-size:30px;'>Anti-Decay Coating</strong><br> (left click)<p>your bullets <strong>last 30% longer</strong></p>", 1200);
|
||||
b.setModDefaults(); //good with: drones, super balls, spore, missiles, wave beam(range), rapid fire(range), flak(range)
|
||||
b.modBulletsLastLonger = 1.3
|
||||
},
|
||||
// () => {
|
||||
// b.mod = 7;
|
||||
// game.makeTextLog("<strong style='font-size:30px;'>Inertia Accumulator</strong><br> (left click)<p>your crouched shots have a higher <strong>velocity</strong><br>Your crouched shots reduce your health</p>", 1200);
|
||||
// b.setModDefaults(); //good with: one shot, rapid fire, spray, needles, super balls
|
||||
// },
|
||||
// () => {
|
||||
// b.mod = 8;
|
||||
// game.makeTextLog("<strong style='font-size:30px;'>Two Phase Processing</strong><br> (left click)<p>You can fire your gun while your <strong>field</strong> is active</p>", 1200);
|
||||
// b.setModDefaults(); //good with: default field, Time Dilation Field, Negative Mass Field, Phase Decoherence Field
|
||||
// },
|
||||
// () => {
|
||||
// b.mod = 9;
|
||||
// game.makeTextLog("<strong style='font-size:30px;'>Relativistic Velocity</strong><br> (left click)<p>Your bullets are effected extra by your own velocity</p>", 1200);
|
||||
// b.setModDefaults(); //good with: one shot, rapid fire, spray, super balls
|
||||
// },
|
||||
],
|
||||
activeGun: null, //current gun in use by player
|
||||
inventoryGun: 0,
|
||||
inventory: [0], //list of what guns player has // 0 starts with basic gun
|
||||
@@ -22,8 +102,56 @@ const b = {
|
||||
}
|
||||
game.makeGunHUD();
|
||||
},
|
||||
fire() {
|
||||
if (game.mouseDown && mech.fireCDcycle < mech.cycle && !(keys[32] || game.mouseDownRight) && b.inventory.length) {
|
||||
if (b.guns[this.activeGun].ammo > 0) {
|
||||
b.guns[this.activeGun].fire();
|
||||
|
||||
if (!(b.modNoAmmoChance && b.modNoAmmoChance > Math.random())) {
|
||||
b.guns[this.activeGun].ammo--;
|
||||
game.updateGunHUD();
|
||||
}
|
||||
} else {
|
||||
mech.fireCDcycle = mech.cycle + 30; //cooldown
|
||||
// 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);
|
||||
}
|
||||
if (mech.isHolding) {
|
||||
mech.drop();
|
||||
}
|
||||
}
|
||||
},
|
||||
draw() {
|
||||
ctx.beginPath();
|
||||
let i = bullet.length;
|
||||
while (i--) {
|
||||
//draw
|
||||
let vertices = bullet[i].vertices;
|
||||
ctx.moveTo(vertices[0].x, vertices[0].y);
|
||||
for (let j = 1; j < vertices.length; j += 1) {
|
||||
ctx.lineTo(vertices[j].x, vertices[j].y);
|
||||
}
|
||||
ctx.lineTo(vertices[0].x, vertices[0].y);
|
||||
//remove bullet if at end cycle for that bullet
|
||||
if (bullet[i].endCycle < game.cycle) {
|
||||
bullet[i].onEnd(i); //some bullets do stuff on end
|
||||
if (bullet[i]) {
|
||||
Matter.World.remove(engine.world, bullet[i]);
|
||||
bullet.splice(i, 1);
|
||||
} else {
|
||||
break; //if bullet[i] doesn't exist don't complete the for loop, because the game probably reset
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.fillStyle = "#000";
|
||||
ctx.fill();
|
||||
//do things
|
||||
for (let i = 0, len = bullet.length; i < len; i++) {
|
||||
bullet[i].do();
|
||||
}
|
||||
},
|
||||
fireProps(cd, speed, dir, me) {
|
||||
mech.fireCDcycle = mech.cycle + cd; // cool down
|
||||
mech.fireCDcycle = mech.cycle + Math.floor(cd * b.modFireRate); // cool down
|
||||
Matter.Body.setVelocity(bullet[me], {
|
||||
x: mech.Vx / 2 + speed * Math.cos(dir),
|
||||
y: mech.Vy / 2 + speed * Math.sin(dir)
|
||||
@@ -99,19 +227,19 @@ const b = {
|
||||
},
|
||||
explode(me) {
|
||||
// typically explode is used for some bullets with .onEnd
|
||||
|
||||
const radius = bullet[me].explodeRad * b.modExplosionRadius
|
||||
//add dmg to draw queue
|
||||
game.drawList.push({
|
||||
x: bullet[me].position.x,
|
||||
y: bullet[me].position.y,
|
||||
radius: bullet[me].explodeRad,
|
||||
radius: radius,
|
||||
color: "rgba(255,0,0,0.4)",
|
||||
time: game.drawTime
|
||||
});
|
||||
let dist, sub, knock;
|
||||
const dmg = b.dmgScale * bullet[me].explodeRad * 0.01;
|
||||
const dmg = b.dmgScale * radius * 0.01;
|
||||
|
||||
const alertRange = 100 + bullet[me].explodeRad * 2; //alert range
|
||||
const alertRange = 100 + radius * 2; //alert range
|
||||
//add alert to draw queue
|
||||
game.drawList.push({
|
||||
x: bullet[me].position.x,
|
||||
@@ -124,8 +252,8 @@ const b = {
|
||||
//player damage and knock back
|
||||
sub = Matter.Vector.sub(bullet[me].position, player.position);
|
||||
dist = Matter.Vector.magnitude(sub);
|
||||
if (dist < bullet[me].explodeRad) {
|
||||
mech.damage(bullet[me].explodeRad * 0.00035);
|
||||
if (dist < radius) {
|
||||
mech.damage(radius * 0.00035);
|
||||
knock = Matter.Vector.mult(Matter.Vector.normalise(sub), -Math.sqrt(dmg) * player.mass / 30);
|
||||
player.force.x += knock.x;
|
||||
player.force.y += knock.y;
|
||||
@@ -141,7 +269,7 @@ const b = {
|
||||
for (let i = 0, len = body.length; i < len; ++i) {
|
||||
sub = Matter.Vector.sub(bullet[me].position, body[i].position);
|
||||
dist = Matter.Vector.magnitude(sub);
|
||||
if (dist < bullet[me].explodeRad) {
|
||||
if (dist < radius) {
|
||||
knock = Matter.Vector.mult(Matter.Vector.normalise(sub), (-Math.sqrt(dmg) * body[i].mass) / 18);
|
||||
body[i].force.x += knock.x;
|
||||
body[i].force.y += knock.y;
|
||||
@@ -156,7 +284,7 @@ const b = {
|
||||
for (let i = 0, len = powerUp.length; i < len; ++i) {
|
||||
sub = Matter.Vector.sub(bullet[me].position, powerUp[i].position);
|
||||
dist = Matter.Vector.magnitude(sub);
|
||||
if (dist < bullet[me].explodeRad) {
|
||||
if (dist < radius) {
|
||||
knock = Matter.Vector.mult(Matter.Vector.normalise(sub), (-Math.sqrt(dmg) * powerUp[i].mass) / 26);
|
||||
powerUp[i].force.x += knock.x;
|
||||
powerUp[i].force.y += knock.y;
|
||||
@@ -172,7 +300,7 @@ const b = {
|
||||
// if (me !== i) {
|
||||
// sub = Matter.Vector.sub(bullet[me].position, bullet[i].position);
|
||||
// dist = Matter.Vector.magnitude(sub);
|
||||
// if (dist < bullet[me].explodeRad) {
|
||||
// if (dist < radius) {
|
||||
// knock = Matter.Vector.mult(Matter.Vector.normalise(sub), (-Math.sqrt(dmg) * bullet[i].mass) / 10);
|
||||
// bullet[i].force.x += knock.x;
|
||||
// bullet[i].force.y += knock.y;
|
||||
@@ -190,7 +318,7 @@ const b = {
|
||||
// if (me != i) {
|
||||
// sub = Matter.Vector.sub(bullet[me].position, bullet[i].position);
|
||||
// dist = Matter.Vector.magnitude(sub);
|
||||
// if (dist < bullet[me].explodeRad) {
|
||||
// if (dist < radius) {
|
||||
// bullet[i].endCycle = mech.cycle;
|
||||
// }
|
||||
// }
|
||||
@@ -203,7 +331,7 @@ const b = {
|
||||
// for (let j = 0, len = vertices.length; j < len; j++) {
|
||||
// sub = Matter.Vector.sub(bullet[me].position, vertices[j]);
|
||||
// dist = Matter.Vector.magnitude(sub);
|
||||
// if (dist < bullet[me].explodeRad) {
|
||||
// if (dist < radius) {
|
||||
// mob[i].damage(dmg);
|
||||
// mob[i].locatePlayer();
|
||||
// knock = Matter.Vector.mult(Matter.Vector.normalise(sub), -Math.sqrt(dmg) * mob[i].mass / 18);
|
||||
@@ -221,7 +349,7 @@ const b = {
|
||||
if (mob[i].alive) {
|
||||
sub = Matter.Vector.sub(bullet[me].position, mob[i].position);
|
||||
dist = Matter.Vector.magnitude(sub);
|
||||
if (dist < bullet[me].explodeRad) {
|
||||
if (dist < radius) {
|
||||
mob[i].damage(dmg * damageScale);
|
||||
mob[i].locatePlayer();
|
||||
knock = Matter.Vector.mult(Matter.Vector.normalise(sub), (-Math.sqrt(dmg * damageScale) * mob[i].mass) / 18);
|
||||
@@ -532,15 +660,15 @@ const b = {
|
||||
// mobs.alert(800);
|
||||
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));
|
||||
bullet[me] = Bodies.rectangle(mech.pos.x + 50 * Math.cos(mech.angle), mech.pos.y + 50 * Math.sin(mech.angle), 70 * b.modBulletSize, 30 * b.modBulletSize, b.fireAttributes(dir));
|
||||
b.fireProps(mech.crouch ? 55 : 40, 50, dir, me); //cd , speed
|
||||
bullet[me].endCycle = game.cycle + 180;
|
||||
bullet[me].endCycle = game.cycle + Math.floor(180 * b.modBulletsLastLonger);
|
||||
bullet[me].do = function () {
|
||||
this.force.y += this.mass * 0.0005;
|
||||
};
|
||||
|
||||
//knock back
|
||||
const KNOCK = (mech.crouch) ? 0.025 : 0.25
|
||||
const KNOCK = ((mech.crouch) ? 0.025 : 0.25) * b.modBulletSize * b.modBulletSize
|
||||
player.force.x -= KNOCK * Math.cos(dir)
|
||||
player.force.y -= KNOCK * Math.sin(dir) * 0.5 //reduce knock back in vertical direction to stop super jumps
|
||||
}
|
||||
@@ -556,9 +684,9 @@ const b = {
|
||||
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));
|
||||
bullet[me] = Bodies.rectangle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 17 * b.modBulletSize, 5 * b.modBulletSize, 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].endCycle = game.cycle + Math.floor(65 * b.modBulletsLastLonger);
|
||||
bullet[me].frictionAir = 0.01;
|
||||
bullet[me].do = function () {
|
||||
this.force.y += this.mass * 0.0005;
|
||||
@@ -574,12 +702,12 @@ const b = {
|
||||
fire() {
|
||||
const me = bullet.length;
|
||||
const DIR = mech.angle
|
||||
const SCALE = mech.crouch ? 0.963 : 0.95
|
||||
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, {
|
||||
bullet[me] = Bodies.circle(mech.pos.x + 25 * Math.cos(DIR), mech.pos.y + 25 * Math.sin(DIR), 10 * b.modBulletSize, {
|
||||
angle: DIR,
|
||||
cycle: -0.43, //adjust this number until the bullets line up with the cross hairs
|
||||
endCycle: game.cycle + (mech.crouch ? 155 : 120),
|
||||
endCycle: game.cycle + Math.floor((mech.crouch ? 155 : 120) * b.modBulletsLastLonger),
|
||||
inertia: Infinity,
|
||||
frictionAir: 0,
|
||||
minDmgSpeed: 0,
|
||||
@@ -602,7 +730,7 @@ const b = {
|
||||
}
|
||||
});
|
||||
World.add(engine.world, bullet[me]); //add bullet to world
|
||||
mech.fireCDcycle = mech.cycle + (mech.crouch ? 8 : 4); // cool down
|
||||
mech.fireCDcycle = mech.cycle + Math.floor((mech.crouch ? 8 : 4) * b.modFireRate); // cool down
|
||||
const SPEED = mech.crouch ? 5.2 : 4.5;
|
||||
Matter.Body.setVelocity(bullet[me], {
|
||||
x: SPEED * Math.cos(DIR),
|
||||
@@ -631,10 +759,10 @@ const b = {
|
||||
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, false));
|
||||
bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 7 * b.modBulletSize, b.fireAttributes(dir, false));
|
||||
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].endCycle = game.cycle + Math.floor(360 * b.modBulletsLastLonger);
|
||||
bullet[me].dmg = 0.5;
|
||||
bullet[me].minDmgSpeed = 0;
|
||||
bullet[me].restitution = 0.96;
|
||||
@@ -655,12 +783,13 @@ const b = {
|
||||
fire() {
|
||||
b.muzzleFlash(35);
|
||||
// mobs.alert(650);
|
||||
const side = 11 * b.modBulletSize
|
||||
for (let i = 0; i < 9; i++) {
|
||||
const me = bullet.length;
|
||||
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));
|
||||
bullet[me] = Bodies.rectangle(mech.pos.x + 35 * Math.cos(mech.angle) + 15 * (Math.random() - 0.5), mech.pos.y + 35 * Math.sin(mech.angle) + 15 * (Math.random() - 0.5), side, side, b.fireAttributes(dir));
|
||||
b.fireProps(mech.crouch ? 60 : 30, 36 + Math.random() * 11, dir, me); //cd , speed
|
||||
bullet[me].endCycle = game.cycle + 60;
|
||||
bullet[me].endCycle = game.cycle + Math.floor(60 * b.modBulletsLastLonger);
|
||||
bullet[me].frictionAir = 0.02;
|
||||
bullet[me].do = function () {
|
||||
this.force.y += this.mass * 0.001;
|
||||
@@ -668,7 +797,7 @@ const b = {
|
||||
}
|
||||
|
||||
//knock back
|
||||
const KNOCK = (mech.crouch) ? 0.015 : 0.15
|
||||
const KNOCK = ((mech.crouch) ? 0.015 : 0.15) * b.modBulletSize * b.modBulletSize
|
||||
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
|
||||
}
|
||||
@@ -683,12 +812,12 @@ const b = {
|
||||
const me = bullet.length;
|
||||
const dir = mech.angle;
|
||||
if (mech.crouch) {
|
||||
bullet[me] = Bodies.rectangle(mech.pos.x + 40 * Math.cos(mech.angle), mech.pos.y + 40 * Math.sin(mech.angle), 40, 3, b.fireAttributes(dir));
|
||||
bullet[me] = Bodies.rectangle(mech.pos.x + 40 * Math.cos(mech.angle), mech.pos.y + 40 * Math.sin(mech.angle), 40 * b.modBulletSize, 3 * b.modBulletSize, b.fireAttributes(dir));
|
||||
} else {
|
||||
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 * b.modBulletSize, 2 * b.modBulletSize, b.fireAttributes(dir));
|
||||
}
|
||||
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 + Math.floor(180 * b.modBulletsLastLonger);
|
||||
bullet[me].dmg = mech.crouch ? 1.4 : 1;
|
||||
b.drawOneBullet(bullet[me].vertices);
|
||||
bullet[me].do = function () {
|
||||
@@ -709,13 +838,13 @@ const b = {
|
||||
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));
|
||||
bullet[me] = Bodies.rectangle(mech.pos.x + 40 * Math.cos(mech.angle), mech.pos.y + 40 * Math.sin(mech.angle) - 3, 30 * b.modBulletSize, 4 * b.modBulletSize, 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].endCycle = game.cycle + Math.floor((265 + Math.random() * 20) * b.modBulletsLastLonger);
|
||||
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
|
||||
@@ -813,12 +942,14 @@ const b = {
|
||||
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
|
||||
const END = Math.floor((mech.crouch ? 27 : 18) * b.modBulletsLastLonger);
|
||||
let dir = mech.angle - angleStep * totalBullets / 2;
|
||||
const side1 = 17 * b.modBulletSize
|
||||
const side2 = 4 * b.modBulletSize
|
||||
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));
|
||||
bullet[me] = Bodies.rectangle(mech.pos.x + 50 * Math.cos(mech.angle), mech.pos.y + 50 * Math.sin(mech.angle), side1, side2, b.fireAttributes(dir));
|
||||
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 + END
|
||||
@@ -849,12 +980,12 @@ const b = {
|
||||
fire() {
|
||||
const me = bullet.length;
|
||||
const dir = mech.angle; // + Math.random() * 0.05;
|
||||
bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 10, b.fireAttributes(dir, false));
|
||||
bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 10 * b.modBulletSize, b.fireAttributes(dir, false));
|
||||
b.fireProps(mech.crouch ? 15 : 8, mech.crouch ? 32 : 24, dir, me); //cd , speed
|
||||
b.drawOneBullet(bullet[me].vertices);
|
||||
Matter.Body.setDensity(bullet[me], 0.000001);
|
||||
bullet[me].totalCycles = 120;
|
||||
bullet[me].endCycle = game.cycle + bullet[me].totalCycles;
|
||||
bullet[me].endCycle = game.cycle + Math.floor(120 * b.modBulletsLastLonger);
|
||||
bullet[me].restitution = 0.6;
|
||||
bullet[me].explodeRad = 130;
|
||||
bullet[me].onEnd = b.explode; //makes bullet do explosive damage before despawn
|
||||
@@ -878,12 +1009,13 @@ const b = {
|
||||
fire() {
|
||||
const me = bullet.length;
|
||||
const dir = mech.angle;
|
||||
bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 22, b.fireAttributes(dir, false));
|
||||
bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 22 * b.modBulletSize, b.fireAttributes(dir, false));
|
||||
bullet[me].radius = 22; //used from drawing timer
|
||||
b.fireProps(mech.crouch ? 60 : 40, mech.crouch ? 38 : 30, dir, me); //cd , speed
|
||||
b.drawOneBullet(bullet[me].vertices);
|
||||
Matter.Body.setDensity(bullet[me], 0.000001);
|
||||
bullet[me].endCycle = game.cycle + 140;
|
||||
bullet[me].endCycle = game.cycle + Math.floor(140 * b.modBulletsLastLonger);
|
||||
bullet[me].endCycleLength = Math.floor(140 * b.modBulletsLastLonger);
|
||||
// bullet[me].restitution = 0.3;
|
||||
// bullet[me].frictionAir = 0.01;
|
||||
// bullet[me].friction = 0.15;
|
||||
@@ -916,7 +1048,7 @@ const b = {
|
||||
//draw clock on timer
|
||||
ctx.fillStyle = "#f12";
|
||||
ctx.beginPath();
|
||||
ctx.arc(this.position.x, this.position.y, this.radius * (1 - (this.endCycle - game.cycle) / 140), 0, 2 * Math.PI);
|
||||
ctx.arc(this.position.x, this.position.y, this.radius * (1 - (this.endCycle - game.cycle) / this.endCycleLength), 0, 2 * Math.PI);
|
||||
ctx.fill();
|
||||
}
|
||||
};
|
||||
@@ -962,7 +1094,7 @@ const b = {
|
||||
const NUM = 9;
|
||||
for (let i = 0; i < NUM; i++) {
|
||||
const bIndex = bullet.length;
|
||||
const RADIUS = 4 + 2 * Math.random();
|
||||
const RADIUS = (4 + 2 * Math.random()) * b.modBulletSize;
|
||||
bullet[bIndex] = Bodies.circle(this.position.x, this.position.y, RADIUS, {
|
||||
// density: 0.0015, //frictionAir: 0.01,
|
||||
inertia: Infinity,
|
||||
@@ -976,7 +1108,7 @@ const b = {
|
||||
category: 0x000100,
|
||||
mask: 0x000011 //no collide with body
|
||||
},
|
||||
endCycle: game.cycle + 300 + Math.floor(Math.random() * 240),
|
||||
endCycle: game.cycle + Math.floor((300 + Math.floor(Math.random() * 240)) * b.modBulletsLastLonger),
|
||||
minDmgSpeed: 0,
|
||||
onDmg() {
|
||||
this.endCycle = 0; //bullet ends cycle after doing damage
|
||||
@@ -1035,7 +1167,7 @@ const b = {
|
||||
const THRUST = 0.0015
|
||||
const dir = mech.angle + (Math.random() - 0.5) * 0.7;
|
||||
const me = bullet.length;
|
||||
const RADIUS = 4 + 4 * Math.random()
|
||||
const RADIUS = (4 + 4 * Math.random()) * b.modBulletSize
|
||||
bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), RADIUS, {
|
||||
angle: dir,
|
||||
inertia: Infinity,
|
||||
@@ -1044,7 +1176,7 @@ const b = {
|
||||
restitution: 1,
|
||||
dmg: 0.14, //damage done in addition to the damage from momentum
|
||||
lookFrequency: 79 + Math.floor(37 * Math.random()),
|
||||
endCycle: game.cycle + 780 + 360 * Math.random(),
|
||||
endCycle: game.cycle + Math.floor((780 + 360 * Math.random()) * b.modBulletsLastLonger),
|
||||
classType: "bullet",
|
||||
collisionFilter: {
|
||||
category: 0x000100,
|
||||
@@ -1090,7 +1222,8 @@ const b = {
|
||||
if (DIST < closeDist) {
|
||||
if (DIST < 50) { //eat the power up if close enough
|
||||
powerUp[i].effect();
|
||||
powerUp.splice(i, 1)
|
||||
Matter.World.remove(engine.world, powerUp[i]);
|
||||
powerUp.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
closeDist = DIST;
|
||||
@@ -1118,62 +1251,5 @@ const b = {
|
||||
b.drawOneBullet(bullet[me].vertices);
|
||||
}
|
||||
},
|
||||
],
|
||||
fire() {
|
||||
if (game.mouseDown && mech.fireCDcycle < mech.cycle && !(keys[32] || game.mouseDownRight) && b.inventory.length) {
|
||||
if (b.guns[this.activeGun].ammo > 0) {
|
||||
b.guns[this.activeGun].fire();
|
||||
b.guns[this.activeGun].ammo--;
|
||||
game.updateGunHUD();
|
||||
} else {
|
||||
mech.fireCDcycle = mech.cycle + 30; //cooldown
|
||||
// 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);
|
||||
}
|
||||
if (mech.isHolding) {
|
||||
mech.drop();
|
||||
}
|
||||
}
|
||||
},
|
||||
gamepadFire() {
|
||||
if (game.gamepad.rightTrigger && mech.fireCDcycle < mech.cycle && !(keys[32] || game.gamepad.leftTrigger) && !mech.isHolding && b.inventory.length) {
|
||||
if (b.guns[this.activeGun].ammo > 0) {
|
||||
b.guns[this.activeGun].fire();
|
||||
b.guns[this.activeGun].ammo--;
|
||||
game.updateGunHUD();
|
||||
} else {
|
||||
mech.fireCDcycle = mech.cycle + 30; //cooldown
|
||||
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);
|
||||
}
|
||||
}
|
||||
},
|
||||
draw() {
|
||||
ctx.beginPath();
|
||||
let i = bullet.length;
|
||||
while (i--) {
|
||||
//draw
|
||||
let vertices = bullet[i].vertices;
|
||||
ctx.moveTo(vertices[0].x, vertices[0].y);
|
||||
for (let j = 1; j < vertices.length; j += 1) {
|
||||
ctx.lineTo(vertices[j].x, vertices[j].y);
|
||||
}
|
||||
ctx.lineTo(vertices[0].x, vertices[0].y);
|
||||
//remove bullet if at endcycle for that bullet
|
||||
if (bullet[i].endCycle < game.cycle) {
|
||||
bullet[i].onEnd(i); //some bullets do stuff on end
|
||||
if (bullet[i]) {
|
||||
Matter.World.remove(engine.world, bullet[i]);
|
||||
bullet.splice(i, 1);
|
||||
} else {
|
||||
break; //if bullet[i] doesn't exist don't complete the for loop, because the game probably reset
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.fillStyle = "#000";
|
||||
ctx.fill();
|
||||
//do things
|
||||
for (let i = 0, len = bullet.length; i < len; i++) {
|
||||
bullet[i].do();
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -122,6 +122,7 @@ function mobCollisionChecks(event) {
|
||||
if (obj.classType === "bullet" && obj.speed > obj.minDmgSpeed) {
|
||||
mob[k].foundPlayer();
|
||||
const dmg = b.dmgScale * (obj.dmg + 0.15 * obj.mass * Matter.Vector.magnitude(Matter.Vector.sub(mob[k].velocity, obj.velocity)));
|
||||
// console.log(dmg)
|
||||
mob[k].damage(dmg);
|
||||
obj.onDmg(); //some bullets do actions when they hits things, like despawn
|
||||
game.drawList.push({
|
||||
|
||||
233
js/game.js
233
js/game.js
@@ -1,8 +1,7 @@
|
||||
// game Object ********************************************************
|
||||
//*********************************************************************
|
||||
const game = {
|
||||
loop() {},
|
||||
mouseLoop() {
|
||||
loop() {
|
||||
game.cycle++; //tracks game cycles
|
||||
mech.cycle++; //tracks player cycles //used to alow time to stop for everything, but the player
|
||||
if (game.clearNow) {
|
||||
@@ -51,164 +50,6 @@ const game = {
|
||||
}
|
||||
game.drawCursor();
|
||||
},
|
||||
gamepadLoop() {
|
||||
game.cycle++; //tracks game cycles
|
||||
mech.cycle++; //tracks player cycles //used to alow time to stop for everything, but the player
|
||||
// game.polGamepad();
|
||||
if (game.clearNow) {
|
||||
game.clearNow = false;
|
||||
game.clearMap();
|
||||
level.start();
|
||||
}
|
||||
game.gravity();
|
||||
Engine.update(engine, game.delta);
|
||||
game.wipe();
|
||||
game.textLog();
|
||||
mech.gamepadMove();
|
||||
level.checkZones();
|
||||
level.checkQuery();
|
||||
mech.move();
|
||||
mech.gamepadLook();
|
||||
game.fallChecks();
|
||||
ctx.save();
|
||||
game.gamepadCamera();
|
||||
if (game.testing) {
|
||||
mech.draw();
|
||||
game.draw.wireFrame();
|
||||
game.draw.cons();
|
||||
game.draw.testing();
|
||||
game.drawCircle();
|
||||
ctx.restore();
|
||||
game.getCoords.out();
|
||||
game.testingOutput();
|
||||
} else {
|
||||
level.drawFillBGs();
|
||||
level.exit.draw();
|
||||
level.enter.draw();
|
||||
game.draw.powerUp();
|
||||
mobs.draw();
|
||||
game.draw.cons();
|
||||
game.draw.body();
|
||||
mech.draw();
|
||||
mech.hold();
|
||||
level.drawFills();
|
||||
game.draw.drawMapPath();
|
||||
mobs.loop();
|
||||
b.draw();
|
||||
b.gamepadFire();
|
||||
game.drawCircle();
|
||||
ctx.restore();
|
||||
}
|
||||
// game.drawCursor();
|
||||
},
|
||||
gamepad: {
|
||||
connected: false,
|
||||
cycle: 0,
|
||||
leftTrigger: false,
|
||||
rightTrigger: false,
|
||||
leftAxisThreshold: 0.6,
|
||||
leftAxis: {
|
||||
x: 0,
|
||||
y: 0
|
||||
},
|
||||
rightAxis: {
|
||||
x: 0,
|
||||
y: 0
|
||||
},
|
||||
cycleWeaponCD: 0
|
||||
},
|
||||
polGamepad: function () {
|
||||
const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads : []);
|
||||
if (!gamepads) return;
|
||||
gp = gamepads[0];
|
||||
// console.log(gp)
|
||||
|
||||
if (game.onTitlePage) {
|
||||
if (gp.buttons[6].pressed || gp.buttons[7].pressed) game.startGame(); //triggers start of game
|
||||
} else {
|
||||
//left d-pad
|
||||
if (gp.axes[0] > game.gamepad.leftAxisThreshold) {
|
||||
game.gamepad.leftAxis.x = 1
|
||||
} else if (gp.axes[0] < -game.gamepad.leftAxisThreshold) {
|
||||
game.gamepad.leftAxis.x = -1
|
||||
} else {
|
||||
game.gamepad.leftAxis.x = 0
|
||||
}
|
||||
if (gp.axes[1] > game.gamepad.leftAxisThreshold) {
|
||||
game.gamepad.leftAxis.y = -1
|
||||
} else if (gp.axes[1] < -game.gamepad.leftAxisThreshold) {
|
||||
game.gamepad.leftAxis.y = 1
|
||||
} else {
|
||||
game.gamepad.leftAxis.y = 0
|
||||
}
|
||||
//right d-pad
|
||||
const limit = 0.08
|
||||
if (Math.abs(gp.axes[2]) > limit) game.gamepad.rightAxis.x = gp.axes[2] * 0.08 + game.gamepad.rightAxis.x * 0.92 //smoothing the input
|
||||
if (Math.abs(gp.axes[3]) > limit) game.gamepad.rightAxis.y = gp.axes[3] * 0.08 + game.gamepad.rightAxis.y * 0.92 //smoothing the input
|
||||
// if (Math.abs(gp.axes[0]) > limit) game.gamepad.rightAxis.x = gp.axes[0] * 0.2 + game.gamepad.rightAxis.x * 0.8 //smoothing the input
|
||||
// if (Math.abs(gp.axes[1]) > limit) game.gamepad.rightAxis.y = gp.axes[1] * 0.2 + game.gamepad.rightAxis.y * 0.8 //smoothing the input
|
||||
// if (Math.abs(gp.axes[2]) > limit) game.gamepad.rightAxis.x = gp.axes[2]
|
||||
// if (Math.abs(gp.axes[3]) > limit) game.gamepad.rightAxis.y = gp.axes[3]
|
||||
|
||||
// left and right trigger
|
||||
if (gp.buttons[6].pressed) {
|
||||
game.gamepad.leftTrigger = true;
|
||||
game.mouseDownRight = true
|
||||
} else {
|
||||
game.gamepad.leftTrigger = false;
|
||||
game.mouseDownRight = false
|
||||
}
|
||||
if (gp.buttons[7].pressed) {
|
||||
game.gamepad.rightTrigger = true;
|
||||
game.mouseDown = true
|
||||
} else {
|
||||
game.gamepad.rightTrigger = false;
|
||||
game.mouseDown = false
|
||||
}
|
||||
//jump
|
||||
if (gp.buttons[0].pressed) { //gp.axes[1] < -0.8 ||
|
||||
game.gamepad.jump = true;
|
||||
} else {
|
||||
game.gamepad.jump = false;
|
||||
}
|
||||
//buttons that trigger a button CD
|
||||
if (game.gamepad.cycleWeaponCD < game.gamepad.cycle) {
|
||||
if (gp.buttons[4].pressed || gp.buttons[12].pressed) {
|
||||
game.gamepad.cycleWeaponCD = game.gamepad.cycle + 15
|
||||
game.previousGun();
|
||||
}
|
||||
if (gp.buttons[5].pressed || gp.buttons[13].pressed) {
|
||||
game.gamepad.cycleWeaponCD = game.gamepad.cycle + 15
|
||||
game.nextGun();
|
||||
}
|
||||
|
||||
if (gp.buttons[9].pressed) {
|
||||
game.gamepad.cycleWeaponCD = game.gamepad.cycle + 60
|
||||
if (game.paused) {
|
||||
game.paused = false;
|
||||
requestAnimationFrame(cycle);
|
||||
} else {
|
||||
game.paused = true;
|
||||
game.makeTextLog("<h1>PAUSED</h1>", 1);
|
||||
}
|
||||
}
|
||||
// if (gp.buttons[14].pressed) {
|
||||
// game.zoomScale /= 0.995;
|
||||
// game.setZoom();
|
||||
// } else if (gp.buttons[15].pressed) {
|
||||
// game.zoomScale *= 0.995;
|
||||
// game.setZoom();
|
||||
// }
|
||||
}
|
||||
}
|
||||
// // logs button numbers
|
||||
// for (let i = 0, len = gp.buttons.length; i < len; i++) {
|
||||
// if (gp.buttons[i].pressed) {
|
||||
// console.log(i)
|
||||
// // console.log(game.gamepad)
|
||||
// }
|
||||
// }
|
||||
},
|
||||
mouse: {
|
||||
x: canvas.width / 2,
|
||||
y: canvas.height / 2
|
||||
@@ -366,50 +207,6 @@ const game = {
|
||||
// "Crouching while firing makes bullets go faster, but slows the rate of fire.",
|
||||
// ]
|
||||
keyPress() {
|
||||
//runs on key press event
|
||||
// if (keys[49]) {
|
||||
// // press 1
|
||||
// b.inventoryGun = 0;
|
||||
// game.switchGun();
|
||||
// } else if (keys[50]) {
|
||||
// // press 2
|
||||
// b.inventoryGun = 1;
|
||||
// game.switchGun();
|
||||
// } else if (keys[51]) {
|
||||
// // press 3
|
||||
// b.inventoryGun = 2;
|
||||
// game.switchGun();
|
||||
// } else if (keys[52]) {
|
||||
// // press 4
|
||||
// b.inventoryGun = 3;
|
||||
// game.switchGun();
|
||||
// } else if (keys[53]) {
|
||||
// // press 5
|
||||
// b.inventoryGun = 4;
|
||||
// game.switchGun();
|
||||
// } else if (keys[54]) {
|
||||
// // press 6
|
||||
// b.inventoryGun = 5;
|
||||
// game.switchGun();
|
||||
// } else if (keys[55]) {
|
||||
// // press 7
|
||||
// b.inventoryGun = 6;
|
||||
// game.switchGun();
|
||||
// } else if (keys[56]) {
|
||||
// // press 8
|
||||
// b.inventoryGun = 7;
|
||||
// game.switchGun();
|
||||
// } else if (keys[57]) {
|
||||
// // press 9
|
||||
// b.inventoryGun = 8;
|
||||
// game.switchGun();
|
||||
// } else if (keys[48]) {
|
||||
// // press 0
|
||||
// b.inventoryGun = 9;
|
||||
// game.switchGun();
|
||||
// }
|
||||
|
||||
|
||||
if (keys[189]) {
|
||||
// - key
|
||||
game.zoomScale /= 0.9;
|
||||
@@ -453,7 +250,10 @@ const game = {
|
||||
requestAnimationFrame(cycle);
|
||||
} else {
|
||||
game.paused = true;
|
||||
game.makeTextLog("<h1>PAUSED</h1>", 1);
|
||||
let text = "<h1>PAUSED</h1>"
|
||||
// if (b.mod !== null) text+=
|
||||
//output current mod, field, and gun info when paused
|
||||
game.makeTextLog(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,12 +282,18 @@ const game = {
|
||||
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "gun");
|
||||
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "gun");
|
||||
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "gun");
|
||||
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "gun");
|
||||
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "field");
|
||||
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "mod");
|
||||
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "heal");
|
||||
powerUps.spawn(game.mouseInGame.x, game.mouseInGame.y, "heal");
|
||||
}
|
||||
|
||||
if (keys[89]) { //cycle fields with F
|
||||
if (b.mod === b.mods.length - 1) {
|
||||
b.mods[0]()
|
||||
} else {
|
||||
b.mods[b.mod + 1]()
|
||||
}
|
||||
}
|
||||
if (keys[82]) { // teleport to mouse with R
|
||||
Matter.Body.setPosition(player, this.mouseInGame);
|
||||
Matter.Body.setVelocity(player, {
|
||||
@@ -537,14 +343,6 @@ const game = {
|
||||
game.mouseInGame.x = (game.mouse.x - canvas.width2) / game.zoom + canvas.width2 - mech.transX;
|
||||
game.mouseInGame.y = (game.mouse.y - canvas.height2) / game.zoom + canvas.height2 - mech.transY;
|
||||
},
|
||||
gamepadCamera() {
|
||||
ctx.translate(canvas.width2, canvas.height2); //center
|
||||
ctx.scale(game.zoom, game.zoom); //zoom in once centered
|
||||
ctx.translate(-canvas.width2 + mech.transX, -canvas.height2 + mech.transY); //translate
|
||||
//calculate in game mouse position by undoing the zoom and translations
|
||||
game.mouseInGame.x = (game.gamepad.rightAxis.x * canvas.width2) / game.zoom + canvas.width2 - mech.transX;
|
||||
game.mouseInGame.y = (game.gamepad.rightAxis.y * canvas.height2) / game.zoom + canvas.height2 - mech.transY;
|
||||
},
|
||||
zoomInFactor: 0,
|
||||
startZoomIn(time = 180) {
|
||||
game.zoom = 0;
|
||||
@@ -627,10 +425,6 @@ const game = {
|
||||
},
|
||||
fpsInterval: 0, //set in startGame
|
||||
then: null,
|
||||
startGameWithMouse() {
|
||||
disconnectGamepad();
|
||||
game.startGame();
|
||||
},
|
||||
startGame() {
|
||||
game.onTitlePage = false;
|
||||
document.getElementById("controls").style.display = "none";
|
||||
@@ -660,6 +454,7 @@ const game = {
|
||||
document.body.style.cursor = "none";
|
||||
if (this.firstRun) {
|
||||
mech.spawn(); //spawns the player
|
||||
b.setModDefaults(); //doesn't run on reset so that gun mods carry over to new runs
|
||||
level.levels = shuffle(level.levels); //shuffles order of maps
|
||||
level.levels.unshift("bosses"); //add bosses level to the end of the randomized levels list
|
||||
}
|
||||
|
||||
79
js/index.js
79
js/index.js
@@ -6,10 +6,6 @@ field power up effects
|
||||
field produces a whirlpool effect of force around player
|
||||
field allows player to hold and throw living mobs
|
||||
|
||||
other power up ideas
|
||||
killing a mob triggers: a spore bullet
|
||||
maybe you could replace the power method with a new one to get this to work
|
||||
|
||||
give mobs more animal-like behaviors
|
||||
like rainworld
|
||||
give mobs something to do when they don't see player
|
||||
@@ -40,30 +36,23 @@ game mechanics
|
||||
|
||||
track foot positions with velocity better as the player walks/crouch/runs
|
||||
|
||||
add bullet on damage effects
|
||||
effects could:
|
||||
add to the array mob.do new mob behaviors
|
||||
add a damage over time
|
||||
add a freeze
|
||||
change mob traits
|
||||
mass
|
||||
friction
|
||||
damage done
|
||||
change things about the bullet
|
||||
bounce the bullet again in a new direction
|
||||
fire several bullets as shrapnel
|
||||
increase the bullet size to do AOE dmg?? (how)
|
||||
just run a for loop over all mobs, and do damage to the one that are close
|
||||
bullets return to player
|
||||
use a constraint? does bullet just start with a constraint or is it added on damage?
|
||||
change the player
|
||||
vampire bullets heal for the damage done
|
||||
or give the player a shield??
|
||||
or only heal if the mob dies (might be tricky)
|
||||
remove standing on player actions
|
||||
replace with check if player feet are in an area.
|
||||
|
||||
|
||||
gun mod power ups
|
||||
higher damage when crouched
|
||||
can fire while field is active
|
||||
bullet on mob damage effects
|
||||
add to the array mob.do new mob behaviors
|
||||
add a damage over time
|
||||
add a freeze
|
||||
fire a few smaller bullets
|
||||
killing a mob triggers: a spore bullet
|
||||
maybe you could replace the power method with a new one to get this to work
|
||||
negative mods for balancing
|
||||
self damage on fire
|
||||
knock back
|
||||
lower fire rate
|
||||
smaller bullets
|
||||
smaller explosions
|
||||
shorter lasting bullets
|
||||
|
||||
|
||||
|
||||
@@ -158,40 +147,6 @@ document.body.addEventListener("wheel", (e) => {
|
||||
});
|
||||
|
||||
|
||||
// window.addEventListener("gamepadconnected", function (e) {
|
||||
// console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.",
|
||||
// e.gamepad.index, e.gamepad.id,
|
||||
// e.gamepad.buttons.length, e.gamepad.axes.length);
|
||||
|
||||
// });
|
||||
|
||||
game.loop = game.mouseLoop;
|
||||
window.addEventListener("gamepadconnected", function (e) {
|
||||
console.log('gamepad connected')
|
||||
document.getElementById("gamepad").style.display = "inline";
|
||||
game.gamepad.connected = true;
|
||||
polGamepadCycle();
|
||||
game.loop = game.gamepadLoop;
|
||||
});
|
||||
window.addEventListener("gamepaddisconnected", function (e) {
|
||||
disconnectGamepad()
|
||||
});
|
||||
|
||||
function disconnectGamepad() {
|
||||
console.log('gamepad disconnected')
|
||||
document.getElementById("gamepad").style.display = "none";
|
||||
game.gamepad.connected = false;
|
||||
game.loop = game.mouseLoop;
|
||||
}
|
||||
|
||||
//this runs to get gamepad data even when paused
|
||||
function polGamepadCycle() {
|
||||
game.gamepad.cycle++
|
||||
if (game.gamepad.connected) requestAnimationFrame(polGamepadCycle);
|
||||
game.polGamepad()
|
||||
}
|
||||
|
||||
|
||||
// function playSound(id) {
|
||||
// //play sound
|
||||
// if (false) {
|
||||
|
||||
@@ -918,6 +918,8 @@ const mobs = {
|
||||
//this.fill = this.color + this.health + ')';
|
||||
if (this.health < 0.1) this.death();
|
||||
this.onDamage(this); //custom damage effects
|
||||
if (b.modEnergySiphon) mech.fieldMeter += dmg * b.modEnergySiphon
|
||||
if (b.modHealthDrain) mech.addHealth(dmg * b.modHealthDrain)
|
||||
},
|
||||
onDamage() {
|
||||
// a placeholder for custom effects on mob damage
|
||||
|
||||
21
js/player.js
21
js/player.js
@@ -412,7 +412,6 @@ const mech = {
|
||||
addHealth(heal) {
|
||||
this.health += heal;
|
||||
if (this.health > 1) this.health = 1;
|
||||
// document.getElementById("health").setAttribute("width", 225 * this.health);
|
||||
this.displayHealth();
|
||||
},
|
||||
defaultFPSCycle: 0, //tracks when to return to normal fps
|
||||
@@ -495,7 +494,7 @@ const mech = {
|
||||
},
|
||||
setHoldDefaults() {
|
||||
this.fieldMeter = 1;
|
||||
this.fieldRegen = 0.0015;
|
||||
this.fieldRegen = 0.001;
|
||||
this.fieldCDcycle = 0;
|
||||
this.isStealth = false;
|
||||
player.collisionFilter.mask = 0x010011 //0x010011 is normal
|
||||
@@ -889,7 +888,7 @@ const mech = {
|
||||
mech.holding();
|
||||
mech.throw();
|
||||
} else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) {
|
||||
const DRAIN = 0.0015 //mech.fieldRegen = 0.0015
|
||||
const DRAIN = 0.0015
|
||||
if (mech.fieldMeter > DRAIN) {
|
||||
mech.fieldMeter -= DRAIN;
|
||||
|
||||
@@ -1010,7 +1009,7 @@ const mech = {
|
||||
mech.holding();
|
||||
mech.throw();
|
||||
} else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) { //push away
|
||||
const DRAIN = 0.001 //mech.fieldRegen = 0.0015
|
||||
const DRAIN = 0.001
|
||||
if (mech.fieldMeter > DRAIN) {
|
||||
mech.fieldMeter -= DRAIN;
|
||||
mech.pushMobs360(170);
|
||||
@@ -1084,9 +1083,7 @@ const mech = {
|
||||
game.makeTextLog("<strong style='font-size:30px;'>Standing Wave Harmonics</strong><br> (right mouse or space bar) <p>oscillating shields always surround player<br> <span style='color:#a00;'>decreased</span> field regeneration</p>", 1200);
|
||||
mech.setHoldDefaults();
|
||||
// mech.fieldShieldingScale = 0.5;
|
||||
mech.fieldRegen = 0.0008; //0.0015
|
||||
// mech.fieldArc = 0.1; //field covers full 360 degrees
|
||||
// mech.calculateFieldThreshold(); //run after setting fieldArc, used for powerUp grab and mobPush with lookingAt(mob)
|
||||
mech.fieldRegen *= 0.33;
|
||||
|
||||
mech.hold = function () {
|
||||
if (mech.isHolding) {
|
||||
@@ -1102,9 +1099,9 @@ const mech = {
|
||||
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)
|
||||
}
|
||||
if (mech.fieldMeter > 0.1) {
|
||||
const grabRange1 = 80 + 80 * Math.sin(mech.cycle / 23)
|
||||
const grabRange2 = 80 + 80 * Math.sin(mech.cycle / 37)
|
||||
const grabRange3 = 80 + 80 * Math.sin(mech.cycle / 47)
|
||||
const grabRange1 = 85 + 60 * Math.sin(mech.cycle / 23)
|
||||
const grabRange2 = 80 + 70 * Math.sin(mech.cycle / 37)
|
||||
const grabRange3 = 70 + 70 * Math.sin(mech.cycle / 47)
|
||||
const netGrabRange = Math.max(grabRange1, grabRange2, grabRange3)
|
||||
ctx.fillStyle = "rgba(110,170,200," + (0.15 + 0.15 * Math.random()) + ")";
|
||||
ctx.beginPath();
|
||||
@@ -1165,7 +1162,7 @@ const mech = {
|
||||
mech.holding();
|
||||
mech.throw();
|
||||
} else if ((keys[32] || game.mouseDownRight) && mech.fieldCDcycle < mech.cycle) {
|
||||
const DRAIN = 0.0035 //mech.fieldRegen = 0.0015
|
||||
const DRAIN = 0.0035
|
||||
if (mech.fieldMeter > DRAIN) {
|
||||
mech.fieldMeter -= DRAIN;
|
||||
|
||||
@@ -1214,7 +1211,7 @@ const mech = {
|
||||
// mech.pushMobs360(140);
|
||||
|
||||
// if (mech.health > 0.1) {
|
||||
// const DRAIN = 0.0008 //mech.fieldRegen = 0.0015
|
||||
// const DRAIN = 0.0008
|
||||
// if (mech.fieldMeter > DRAIN) {
|
||||
// mech.fieldMeter -= DRAIN;
|
||||
// mech.damage(0.00005 + 0.00000012 * mech.grabRange)
|
||||
|
||||
@@ -32,12 +32,37 @@ const powerUps = {
|
||||
} else {
|
||||
mech.fieldUpgrades[this.mode](); //set a predetermined power up
|
||||
}
|
||||
if (previousMode !== 0) { //pop the old field out in case player wants to swap back
|
||||
//pop the old field out in case player wants to swap back
|
||||
if (previousMode !== 0) {
|
||||
mech.fieldCDcycle = mech.cycle + 40; //trigger fieldCD to stop power up grab automatic pick up of spawn
|
||||
powerUps.spawn(mech.pos.x, mech.pos.y - 15, "field", false, previousMode);
|
||||
}
|
||||
}
|
||||
},
|
||||
mod: {
|
||||
name: "mod",
|
||||
color: "#479",
|
||||
size() {
|
||||
return 42;
|
||||
},
|
||||
effect() {
|
||||
const previousMode = b.mod
|
||||
|
||||
if (this.mode === null) { //this.mode is set if the power up has been ejected from player
|
||||
mode = b.mod //start with current mob
|
||||
while (mode === b.mod) {
|
||||
mode = Math.floor(Math.random() * b.mods.length)
|
||||
}
|
||||
b.mods[mode](); //choose random upgrade that you don't already have
|
||||
} else {
|
||||
b.mods[this.mode](); //set a predetermined power up
|
||||
}
|
||||
if (previousMode != null) { //pop the old field out in case player wants to swap back
|
||||
mech.fieldCDcycle = mech.cycle + 40; //trigger fieldCD to stop power up grab automatic pick up of spawn
|
||||
powerUps.spawn(mech.pos.x, mech.pos.y - 15, "mod", false, previousMode);
|
||||
}
|
||||
}
|
||||
},
|
||||
ammo: {
|
||||
name: "ammo",
|
||||
color: "#467",
|
||||
@@ -68,7 +93,7 @@ const powerUps = {
|
||||
if (!game.lastLogTime) game.makeTextLog("+energy", 180);
|
||||
} else {
|
||||
//ammo given scales as mobs take more hits to kill
|
||||
const ammo = Math.ceil((target.ammoPack * (0.55 + 0.1 * Math.random())) / b.dmgScale);
|
||||
const ammo = Math.ceil((target.ammoPack * (0.6 + 0.05 * Math.random())) / b.dmgScale);
|
||||
target.ammo += ammo;
|
||||
game.updateGunHUD();
|
||||
if (!game.lastLogTime) game.makeTextLog("+" + ammo + " ammo: " + target.name, 180);
|
||||
@@ -127,7 +152,7 @@ const powerUps = {
|
||||
if (b.inventory.length > 0) powerUps.spawn(x, y, "ammo");
|
||||
return;
|
||||
}
|
||||
if (Math.random() < 0.005 * (6 - b.inventory.length)) { //a new gun has a low chance for each not acquired gun to drop
|
||||
if (Math.random() < 0.004 * (5 - b.inventory.length)) { //a new gun has a low chance for each not acquired gun to drop
|
||||
powerUps.spawn(x, y, "gun");
|
||||
return;
|
||||
}
|
||||
@@ -135,6 +160,27 @@ const powerUps = {
|
||||
powerUps.spawn(x, y, "field");
|
||||
return;
|
||||
}
|
||||
if (Math.random() < 0.005) {
|
||||
powerUps.spawn(x, y, "mod");
|
||||
return;
|
||||
}
|
||||
},
|
||||
spawnBossPowerUp(x, y) { //boss spawns field and gun mod upgrades
|
||||
if (mech.fieldMode === 0) {
|
||||
powerUps.spawn(x, y, "field")
|
||||
} else if (b.mod === null) {
|
||||
powerUps.spawn(x, y, "mod")
|
||||
} else if (Math.random() < 0.2) {
|
||||
powerUps.spawn(x, y, "mod")
|
||||
} else if (Math.random() < 0.2) {
|
||||
powerUps.spawn(x, y, "field");
|
||||
} else if (Math.random() < 0.15) {
|
||||
powerUps.spawn(x, y, "gun")
|
||||
} else if (mech.health < 0.5) {
|
||||
powerUps.spawn(x, y, "heal");
|
||||
} else {
|
||||
powerUps.spawn(x, y, "ammo");
|
||||
}
|
||||
},
|
||||
chooseRandomPowerUp(x, y) { //100% chance to drop a random power up //used in spawn.debris
|
||||
if (Math.random() < 0.5) {
|
||||
@@ -144,7 +190,7 @@ const powerUps = {
|
||||
}
|
||||
},
|
||||
spawnStartingPowerUps(x, y) {
|
||||
if (b.inventory.length < 3) {
|
||||
if (b.inventory.length < 2) {
|
||||
powerUps.spawn(x, y, "gun", false); //starting gun
|
||||
} else {
|
||||
powerUps.spawnRandomPowerUp(x, y);
|
||||
@@ -153,7 +199,7 @@ const powerUps = {
|
||||
powerUps.spawnRandomPowerUp(x, y);
|
||||
}
|
||||
},
|
||||
spawn(x, y, target, moving = true, mode) {
|
||||
spawn(x, y, target, moving = true, mode = null) {
|
||||
let i = powerUp.length;
|
||||
target = powerUps[target];
|
||||
size = target.size();
|
||||
@@ -161,6 +207,7 @@ const powerUps = {
|
||||
density: 0.001,
|
||||
frictionAir: 0.01,
|
||||
restitution: 0.8,
|
||||
inertia: Infinity, //prevents rotation
|
||||
collisionFilter: {
|
||||
group: 0,
|
||||
category: 0x100000,
|
||||
|
||||
Reference in New Issue
Block a user