wave beam gun rework
This commit is contained in:
240
js/bullets.js
240
js/bullets.js
@@ -818,7 +818,7 @@ const b = {
|
|||||||
{
|
{
|
||||||
name: "drones",
|
name: "drones",
|
||||||
ammo: 0,
|
ammo: 0,
|
||||||
ammoPack: 23,
|
ammoPack: 22,
|
||||||
have: false,
|
have: false,
|
||||||
fire() {
|
fire() {
|
||||||
const MAX_SPEED = 6
|
const MAX_SPEED = 6
|
||||||
@@ -897,151 +897,137 @@ const b = {
|
|||||||
// };
|
// };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// name: "flock", // shards
|
|
||||||
// ammo: 0,
|
|
||||||
// ammoPack: 1027,
|
|
||||||
// have: false,
|
|
||||||
// fire() {
|
|
||||||
// const me = bullet.length;
|
|
||||||
// const dir = mech.angle + 0.7 * (Math.random() - 0.5);
|
|
||||||
// const RADIUS = 6 + 2.5 * (Math.random() - 0.5)
|
|
||||||
// // 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.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), RADIUS, {
|
|
||||||
// bullet[me] = Bodies.rectangle(mech.pos.x + 40 * Math.cos(mech.angle), mech.pos.y + 40 * Math.sin(mech.angle), 31, 2, {
|
|
||||||
// angle: dir,
|
|
||||||
// friction: 0,
|
|
||||||
// frictionAir: 0.02,
|
|
||||||
// restitution: 0.2,
|
|
||||||
// dmg: 0.15, //damage done in addition to the damage from momentum
|
|
||||||
// lookFrequency: 67 + Math.floor(23 * Math.random()),
|
|
||||||
// endCycle: game.cycle + 540 + 120 * Math.random(),
|
|
||||||
// classType: "bullet",
|
|
||||||
// collisionFilter: {
|
|
||||||
// category: 0x000100,
|
|
||||||
// mask: 0x000111
|
|
||||||
// },
|
|
||||||
// minDmgSpeed: 0,
|
|
||||||
// onDmg() {
|
|
||||||
// this.endCycle = 0 //triggers despawn
|
|
||||||
// // this.explodeRad = this.speed * 10
|
|
||||||
// },
|
|
||||||
// // explodeRad: 10,
|
|
||||||
// // onEnd: b.explode,
|
|
||||||
// onEnd() {},
|
|
||||||
// do() {
|
|
||||||
// // drain ammo
|
|
||||||
// // if (!(game.cycle % this.lookFrequency)) {
|
|
||||||
// // if (b.guns[b.activeGun].ammo > 0) {
|
|
||||||
// // b.guns[b.activeGun].ammo--;
|
|
||||||
// // game.updateGunHUD();
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
|
|
||||||
|
|
||||||
// this.force.y += this.mass * 0.0002; //gravity
|
|
||||||
|
|
||||||
// //accelerate towards mouse
|
|
||||||
// const THRUST = 0.0015
|
|
||||||
// const UNIT_VECTOR = Matter.Vector.normalise(Matter.Vector.sub(this.position, game.mouseInGame))
|
|
||||||
// this.force = Matter.Vector.mult(UNIT_VECTOR, -this.mass * THRUST)
|
|
||||||
|
|
||||||
// // speed cap
|
|
||||||
// if (this.speed > 16) {
|
|
||||||
// Matter.Body.setVelocity(this, {
|
|
||||||
// x: this.velocity.x * 0.97,
|
|
||||||
// y: this.velocity.y * 0.97
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// // bullet[me].onEnd = b.explode; //makes bullet do explosive damage before despawn
|
|
||||||
// // b.fireAttributes(dir));
|
|
||||||
// b.fireProps(4, 4, dir, me); //cd , speed
|
|
||||||
// b.drawOneBullet(bullet[me].vertices);
|
|
||||||
// // Matter.Body.setDensity(bullet[me], 0.000001);
|
|
||||||
// // bullet[me].onDmg = function () {
|
|
||||||
// // this.endCycle = 0; //bullet ends cycle after doing damage
|
|
||||||
// // };
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
name: "wave beam",
|
name: "wave beam",
|
||||||
ammo: 0,
|
ammo: 0,
|
||||||
ammoPack: 120,
|
ammoPack: 70,
|
||||||
have: false,
|
have: false,
|
||||||
fire() {
|
fire() {
|
||||||
mech.fireCDcycle = game.cycle + 7; // cool down
|
const me = bullet.length;
|
||||||
const endCycle = game.cycle + 94
|
const DIR = mech.angle
|
||||||
const bulletRadius = 5;
|
const DIR_90 = mech.angle + Math.PI / 2
|
||||||
const speed = 35;
|
const MAG_90 = -26
|
||||||
const spread = Math.PI / 2 * 0.65 // smaller = faster speed, larger = faster rotation?
|
bullet[me] = Bodies.circle(mech.pos.x + MAG_90 * Math.cos(DIR_90), mech.pos.y + MAG_90 * Math.sin(DIR_90), 5, {
|
||||||
const dir = mech.angle
|
angle: DIR,
|
||||||
const pos = {
|
cycle: -0.45, //adjust this number until the bullets line up with the cross hairs
|
||||||
x: mech.pos.x + 20 * Math.cos(mech.angle),
|
endCycle: game.cycle + 300,
|
||||||
y: mech.pos.y + 20 * Math.sin(mech.angle)
|
|
||||||
}
|
|
||||||
const props = {
|
|
||||||
angle: dir,
|
|
||||||
endCycle: endCycle,
|
|
||||||
inertia: Infinity,
|
inertia: Infinity,
|
||||||
restitution: 1,
|
frictionAir: 0,
|
||||||
friction: 1,
|
|
||||||
frictionAir: -0.003,
|
|
||||||
minDmgSpeed: 0,
|
minDmgSpeed: 0,
|
||||||
isConstrained: true,
|
dmg: 0.09, //damage done in addition to the damage from momentum
|
||||||
dmg: 0, //damage done in addition to the damage from momentum
|
|
||||||
classType: "bullet",
|
classType: "bullet",
|
||||||
collisionFilter: {
|
collisionFilter: {
|
||||||
category: 0x000100,
|
category: 0x000100,
|
||||||
mask: 0x000010
|
mask: 0x000010
|
||||||
},
|
},
|
||||||
onDmg() {
|
onDmg() {
|
||||||
if (this.isConstrained) {
|
// this.endCycle = 0; //bullet ends cycle after doing damage
|
||||||
this.isConstrained = false
|
|
||||||
b.removeConsBB(this)
|
|
||||||
// this.endCycle = 0 //triggers despawn
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onEnd() {
|
|
||||||
if (this.isConstrained) {
|
|
||||||
this.isConstrained = false
|
|
||||||
b.removeConsBB(this)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
do() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
//first bullet
|
//recalculate the direction of wiggle
|
||||||
const me = bullet.length;
|
this.direction = Matter.Vector.perp(this.velocity)
|
||||||
bullet[me] = Bodies.circle(pos.x, pos.y, bulletRadius, props);
|
},
|
||||||
Matter.Body.setVelocity(bullet[me], {
|
onEnd() {},
|
||||||
x: speed * Math.cos(dir + spread),
|
do() {
|
||||||
y: speed * Math.sin(dir + spread)
|
//wiggle wiggle wiggle
|
||||||
|
this.cycle++
|
||||||
|
const THRUST = 0.003 * Math.cos(this.cycle * 0.3)
|
||||||
|
this.force = Matter.Vector.mult(Matter.Vector.normalise(this.direction), this.mass * THRUST)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
World.add(engine.world, bullet[me]); //add bullet to world
|
World.add(engine.world, bullet[me]); //add bullet to world
|
||||||
// Matter.Body.setDensity(bullet[me], 0.0005); //0.001 is normal
|
mech.fireCDcycle = game.cycle + 4; // cool down
|
||||||
|
const SPEED = 5;
|
||||||
//second bullet
|
Matter.Body.setVelocity(bullet[me], {
|
||||||
const me2 = bullet.length;
|
x: SPEED * Math.cos(DIR),
|
||||||
bullet[me2] = Bodies.circle(pos.x, pos.y, bulletRadius, props);
|
y: SPEED * Math.sin(DIR)
|
||||||
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
|
bullet[me].direction = Matter.Vector.perp(bullet[me].velocity)
|
||||||
// Matter.Body.setDensity(bullet[me2], 0.0005); //0.001 is normal
|
// 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)
|
||||||
|
// }
|
||||||
|
|
||||||
//constraint
|
World.add(engine.world, bullet[me]); //add bullet to world
|
||||||
const meCons = consBB.length
|
|
||||||
consBB[meCons] = Constraint.create({
|
|
||||||
bodyA: bullet[me],
|
|
||||||
bodyB: bullet[me2],
|
|
||||||
stiffness: 0.008
|
|
||||||
});
|
|
||||||
World.add(engine.world, consBB[meCons]);
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
// {
|
||||||
|
// 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) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ 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(10) // set a starting gun for testing
|
b.giveGuns(12) // set a starting gun for testing
|
||||||
// game.levelsCleared = 3; //for testing to simulate all possible mobs spawns
|
// game.levelsCleared = 3; //for testing to simulate all possible mobs spawns
|
||||||
// this.bosses();
|
// this.bosses();
|
||||||
// this.testingMap();
|
// this.testingMap();
|
||||||
|
|||||||
Reference in New Issue
Block a user