mines stop velocity on map floor
This commit is contained in:
@@ -748,31 +748,36 @@ const b = {
|
|||||||
x: 1,
|
x: 1,
|
||||||
y: 0
|
y: 0
|
||||||
})
|
})
|
||||||
if (angle > -0.2 || angle < -1.5) { //don't stick to level ground
|
Matter.Body.setAngle(this, Math.atan2(collide[i].tangent.y, collide[i].tangent.x))
|
||||||
Matter.Body.setAngle(this, Math.atan2(collide[i].tangent.y, collide[i].tangent.x))
|
//move until touching map again after rotation
|
||||||
//move until touching map again after rotation
|
for (let j = 0; j < 10; j++) {
|
||||||
for (let j = 0; j < 10; j++) {
|
if (Matter.Query.collides(this, map).length > 0) {
|
||||||
if (Matter.Query.collides(this, map).length > 0) {
|
if (angle > -0.2 || angle < -1.5) { //don't stick to level ground
|
||||||
Matter.Body.setStatic(this, true) //don't set to static if not touching map
|
Matter.Body.setStatic(this, true) //don't set to static if not touching map
|
||||||
this.arm();
|
} else {
|
||||||
|
Matter.Body.setVelocity(this, {
|
||||||
//sometimes the mine can't attach to map and it just needs to explode
|
x: 0,
|
||||||
const that = this
|
y: 0
|
||||||
setTimeout(function () {
|
});
|
||||||
if (Matter.Query.collides(that, map).length === 0) {
|
Matter.Body.setAngularVelocity(this, 0)
|
||||||
that.endCycle = 0 // if not touching map explode
|
|
||||||
that.isArmed = false
|
|
||||||
b.mine(that.position, that.velocity, that.angle)
|
|
||||||
}
|
|
||||||
}, 100, that);
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
//move until you are touching the wall
|
this.arm();
|
||||||
Matter.Body.setPosition(this, Vector.add(this.position, Vector.mult(collide[i].normal, 2)))
|
|
||||||
|
//sometimes the mine can't attach to map and it just needs to be reset
|
||||||
|
const that = this
|
||||||
|
setTimeout(function () {
|
||||||
|
if (Matter.Query.collides(that, map).length === 0) {
|
||||||
|
that.endCycle = 0 // if not touching map explode
|
||||||
|
that.isArmed = false
|
||||||
|
b.mine(that.position, that.velocity, that.angle)
|
||||||
|
}
|
||||||
|
}, 100, that);
|
||||||
|
break
|
||||||
}
|
}
|
||||||
} else if (this.speed < 1 && this.angularSpeed < 0.01 && !mech.isBodiesAsleep) {
|
//move until you are touching the wall
|
||||||
this.stillCount += 2
|
Matter.Body.setPosition(this, Vector.add(this.position, Vector.mult(collide[i].normal, 2)))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -780,7 +785,7 @@ const b = {
|
|||||||
this.stillCount++
|
this.stillCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.stillCount > 35) this.arm();
|
if (this.stillCount > 25) this.arm();
|
||||||
},
|
},
|
||||||
arm() {
|
arm() {
|
||||||
this.isArmed = true
|
this.isArmed = true
|
||||||
@@ -829,7 +834,7 @@ const b = {
|
|||||||
x: targets[index].x + SPREAD * (Math.random() - 0.5),
|
x: targets[index].x + SPREAD * (Math.random() - 0.5),
|
||||||
y: targets[index].y + SPREAD * (Math.random() - 0.5)
|
y: targets[index].y + SPREAD * (Math.random() - 0.5)
|
||||||
}
|
}
|
||||||
b.nail(this.position, Vector.mult(Vector.normalise(Vector.sub(WHERE, this.position)), speed), 1)
|
b.nail(this.position, Vector.mult(Vector.normalise(Vector.sub(WHERE, this.position)), speed), 1.1)
|
||||||
} else { // aim in random direction
|
} else { // aim in random direction
|
||||||
const ANGLE = 2 * Math.PI * Math.random()
|
const ANGLE = 2 * Math.PI * Math.random()
|
||||||
b.nail(this.position, {
|
b.nail(this.position, {
|
||||||
@@ -1758,23 +1763,18 @@ const b = {
|
|||||||
const me = bullet.length;
|
const me = bullet.length;
|
||||||
const dir = mech.angle;
|
const dir = mech.angle;
|
||||||
bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 35 * b.modBulletSize, b.fireAttributes(dir, false));
|
bullet[me] = Bodies.circle(mech.pos.x + 30 * Math.cos(mech.angle), mech.pos.y + 30 * Math.sin(mech.angle), 35 * b.modBulletSize, b.fireAttributes(dir, false));
|
||||||
bullet[me].radius = 22; //used from drawing timer
|
|
||||||
b.fireProps(10, mech.crouch ? 42 : 26, dir, me); //cd , speed
|
b.fireProps(10, mech.crouch ? 42 : 26, dir, me); //cd , speed
|
||||||
|
|
||||||
bullet[me].endCycle = Infinity
|
|
||||||
// bullet[me].restitution = 0.3;
|
|
||||||
// bullet[me].frictionAir = 0.01;
|
|
||||||
// bullet[me].friction = 0.15;
|
|
||||||
bullet[me].inertia = Infinity; //prevents rotation
|
|
||||||
bullet[me].restitution = 0;
|
|
||||||
bullet[me].friction = 1;
|
|
||||||
Matter.Body.setDensity(bullet[me], 0.0002);
|
Matter.Body.setDensity(bullet[me], 0.0002);
|
||||||
|
bullet[me].restitution = 0.2;
|
||||||
|
bullet[me].friction = 0.3;
|
||||||
|
bullet[me].endCycle = Infinity
|
||||||
bullet[me].explodeRad = 380 + Math.floor(Math.random() * 60);
|
bullet[me].explodeRad = 380 + Math.floor(Math.random() * 60);
|
||||||
bullet[me].onEnd = b.explode; //makes bullet do explosive damage before despawn
|
bullet[me].onEnd = b.explode; //makes bullet do explosive damage before despawn
|
||||||
bullet[me].onDmg = function () {
|
bullet[me].onDmg = function () {
|
||||||
// this.endCycle = 0; //bullet ends cycle after doing damage //this triggers explosion
|
// this.endCycle = 0; //bullet ends cycle after doing damage //this triggers explosion
|
||||||
};
|
};
|
||||||
|
bullet[me].radius = 22; //used from drawing timer
|
||||||
bullet[me].isArmed = false;
|
bullet[me].isArmed = false;
|
||||||
bullet[me].isSucking = false;
|
bullet[me].isSucking = false;
|
||||||
bullet[me].do = function () {
|
bullet[me].do = function () {
|
||||||
@@ -1864,7 +1864,7 @@ const b = {
|
|||||||
have: false,
|
have: false,
|
||||||
isStarterGun: false,
|
isStarterGun: false,
|
||||||
fire() {
|
fire() {
|
||||||
const speed = mech.crouch ? 34 : 20
|
const speed = mech.crouch ? 36 : 22
|
||||||
b.mine({
|
b.mine({
|
||||||
x: mech.pos.x + 30 * Math.cos(mech.angle),
|
x: mech.pos.x + 30 * Math.cos(mech.angle),
|
||||||
y: mech.pos.y + 30 * Math.sin(mech.angle)
|
y: mech.pos.y + 30 * Math.sin(mech.angle)
|
||||||
@@ -1872,7 +1872,7 @@ const b = {
|
|||||||
x: speed * Math.cos(mech.angle),
|
x: speed * Math.cos(mech.angle),
|
||||||
y: speed * Math.sin(mech.angle)
|
y: speed * Math.sin(mech.angle)
|
||||||
})
|
})
|
||||||
mech.fireCDcycle = mech.cycle + Math.floor((mech.crouch ? 60 : 40) * b.modFireRate); // cool down
|
mech.fireCDcycle = mech.cycle + Math.floor((mech.crouch ? 70 : 45) * b.modFireRate); // cool down
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const level = {
|
|||||||
start() {
|
start() {
|
||||||
if (level.levelsCleared === 0) {
|
if (level.levelsCleared === 0) {
|
||||||
// game.difficulty = 6; //for testing to simulate possible mobs spawns
|
// game.difficulty = 6; //for testing to simulate possible mobs spawns
|
||||||
// b.giveGuns(10)
|
// b.giveGuns(9)
|
||||||
// mech.setField(3)
|
// mech.setField(3)
|
||||||
// b.giveMod(3);
|
// b.giveMod(3);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user