working on nail bomb
This commit is contained in:
121
js/bullets.js
121
js/bullets.js
@@ -1155,8 +1155,8 @@ const b = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nail bomb",
|
name: "magnetic nails",
|
||||||
description: "fire a <strong>bomb</strong> that ejects <strong class='color-m'>magnetized</strong> nails<br>nails are <strong class='color-m'>attracted</strong> to enemy targets<br>click left mouse <strong>again</strong> to detonate",
|
description: "fire a <strong>grenade</strong> that ejects <strong class='color-m'>magnetized</strong> nails<br>nails are <strong class='color-m'>attracted</strong> to enemy targets",
|
||||||
ammo: 0,
|
ammo: 0,
|
||||||
ammoPack: 6,
|
ammoPack: 6,
|
||||||
have: false,
|
have: false,
|
||||||
@@ -1169,95 +1169,62 @@ const b = {
|
|||||||
b.fireProps(10, mech.crouch ? 42 : 26, dir, me); //cd , speed
|
b.fireProps(10, mech.crouch ? 42 : 26, dir, me); //cd , speed
|
||||||
|
|
||||||
b.drawOneBullet(bullet[me].vertices);
|
b.drawOneBullet(bullet[me].vertices);
|
||||||
bullet[me].endCycle = Infinity
|
bullet[me].endCycle = game.cycle + Math.floor((mech.crouch ? 90 : 40) * b.modBulletsLastLonger);
|
||||||
bullet[me].endCycle = Infinity
|
|
||||||
// bullet[me].restitution = 0.3;
|
// bullet[me].restitution = 0.3;
|
||||||
// bullet[me].frictionAir = 0.01;
|
// bullet[me].frictionAir = 0.01;
|
||||||
// bullet[me].friction = 0.15;
|
// bullet[me].friction = 0.15;
|
||||||
// bullet[me].friction = 1;
|
// bullet[me].friction = 1;
|
||||||
bullet[me].inertia = Infinity; //prevents rotation
|
|
||||||
bullet[me].restitution = 0.5;
|
bullet[me].restitution = 0.5;
|
||||||
bullet[me].onEnd = () => {}
|
bullet[me].onEnd = () => {}
|
||||||
bullet[me].minDmgSpeed = 1;
|
bullet[me].minDmgSpeed = 1;
|
||||||
bullet[me].isArmed = false;
|
|
||||||
bullet[me].isTriggered = false;
|
|
||||||
bullet[me].do = function () {
|
bullet[me].do = function () {
|
||||||
//extra gravity for harder arcs
|
//extra gravity for harder arcs
|
||||||
this.force.y += this.mass * 0.002;
|
this.force.y += this.mass * 0.002;
|
||||||
mech.fireCDcycle = mech.cycle + 10 //can't fire until after the explosion
|
if (game.cycle > this.endCycle - 1) {
|
||||||
|
|
||||||
//set armed and sucking status
|
|
||||||
if (!this.isArmed && !game.mouseDown) {
|
|
||||||
this.isArmed = true
|
|
||||||
} else if (this.isArmed && game.mouseDown && !this.isTriggered) {
|
|
||||||
this.isTriggered = true;
|
|
||||||
this.endCycle = game.cycle + 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isTriggered) {
|
|
||||||
if (!mech.isBodiesAsleep) {
|
if (!mech.isBodiesAsleep) {
|
||||||
//target nearby mobs
|
for (let i = 0; i < 12; i++) {
|
||||||
const targets = []
|
//target nearby mobs
|
||||||
for (let i = 0, len = mob.length; i < len; i++) {
|
const targets = []
|
||||||
if (
|
for (let i = 0, len = mob.length; i < len; i++) {
|
||||||
Matter.Query.ray(map, this.position, mob[i].position).length === 0 &&
|
const sub = Matter.Vector.sub(this.position, mob[i].position);
|
||||||
Matter.Query.ray(body, this.position, mob[i].position).length === 0
|
const dist = Matter.Vector.magnitude(sub);
|
||||||
) {
|
if (dist < 1500 && Matter.Query.ray(map, this.position, mob[i].position).length === 0) {
|
||||||
targets.push(mob[i].position)
|
targets.push(mob[i].position)
|
||||||
}
|
|
||||||
}
|
|
||||||
for (let i = 0; i < 4; i++) {
|
|
||||||
const SPEED = 35 + 20 * Math.random()
|
|
||||||
if (Math.random() < 0.5 && targets.length > 0) { // aim near a random target
|
|
||||||
const SPREAD = 100
|
|
||||||
const INDEX = Math.floor(Math.random() * targets.length)
|
|
||||||
const WHERE = {
|
|
||||||
x: targets[INDEX].x + SPREAD * Math.random(),
|
|
||||||
y: targets[INDEX].y + SPREAD * Math.random()
|
|
||||||
}
|
}
|
||||||
needle(this.position, Matter.Vector.mult(Matter.Vector.normalise(Matter.Vector.sub(WHERE, this.position)), SPEED))
|
}
|
||||||
} else { // aim in random direction
|
for (let i = 0; i < 1; i++) {
|
||||||
const ANGLE = 2 * Math.PI * Math.random()
|
const SPEED = 35 + 20 * Math.random()
|
||||||
needle(this.position, {
|
if (targets.length > 0) { // aim near a random target
|
||||||
x: SPEED * Math.cos(ANGLE),
|
const SPREAD = 100
|
||||||
y: SPEED * Math.sin(ANGLE)
|
const INDEX = Math.floor(Math.random() * targets.length)
|
||||||
})
|
const WHERE = {
|
||||||
|
x: targets[INDEX].x + SPREAD * (Math.random() - 0.5),
|
||||||
|
y: targets[INDEX].y + SPREAD * (Math.random() - 0.5)
|
||||||
|
}
|
||||||
|
needle(this.position, Matter.Vector.mult(Matter.Vector.normalise(Matter.Vector.sub(WHERE, this.position)), SPEED))
|
||||||
|
} else { // aim in random direction
|
||||||
|
const ANGLE = 2 * Math.PI * Math.random()
|
||||||
|
needle(this.position, {
|
||||||
|
x: SPEED * Math.cos(ANGLE),
|
||||||
|
y: SPEED * Math.sin(ANGLE)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function needle(pos, velocity) {
|
||||||
|
const me = bullet.length;
|
||||||
|
bullet[me] = Bodies.rectangle(pos.x, pos.y, 23 * b.modBulletSize, 2 * b.modBulletSize, b.fireAttributes(dir));
|
||||||
|
Matter.Body.setVelocity(bullet[me], velocity);
|
||||||
|
|
||||||
|
Matter.Body.setAngle(bullet[me], Math.atan2(velocity.y, velocity.x))
|
||||||
|
World.add(engine.world, bullet[me]); //add bullet to world
|
||||||
|
bullet[me].endCycle = game.cycle + 45 + Math.floor(15 * Math.random());
|
||||||
|
bullet[me].dmg = 1.1;
|
||||||
|
bullet[me].category = 0x010000
|
||||||
|
bullet[me].mask = 0x011011
|
||||||
|
bullet[me].do = function () {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function needle(pos, velocity) {
|
|
||||||
const me = bullet.length;
|
|
||||||
bullet[me] = Bodies.rectangle(pos.x, pos.y, 23 * b.modBulletSize, 2 * b.modBulletSize, b.fireAttributes(dir));
|
|
||||||
Matter.Body.setVelocity(bullet[me], velocity);
|
|
||||||
|
|
||||||
Matter.Body.setAngle(bullet[me], Math.atan2(velocity.y, velocity.x))
|
|
||||||
World.add(engine.world, bullet[me]); //add bullet to world
|
|
||||||
bullet[me].endCycle = game.cycle + 45 + Math.floor(15 * Math.random());
|
|
||||||
bullet[me].dmg = 1.1;
|
|
||||||
bullet[me].category = 0x010000
|
|
||||||
bullet[me].mask = 0x011011
|
|
||||||
bullet[me].do = function () {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// flashing lights to show armed
|
|
||||||
if (!(game.cycle % 10)) {
|
|
||||||
if (this.isFlashOn) {
|
|
||||||
this.isFlashOn = false;
|
|
||||||
} else {
|
|
||||||
this.isFlashOn = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.isFlashOn) {
|
|
||||||
ctx.fillStyle = "#000";
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(this.position.x, this.position.y, this.radius, 0, 2 * Math.PI);
|
|
||||||
ctx.fill();
|
|
||||||
//draw clock on timer
|
|
||||||
ctx.fillStyle = "#83f";
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(this.position.x, this.position.y, this.radius * 0.3, 0, 2 * Math.PI);
|
|
||||||
ctx.fill();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user