making mines snap to map when they stick
This commit is contained in:
@@ -104,24 +104,22 @@ const b = {
|
|||||||
count: 0,
|
count: 0,
|
||||||
effect() {
|
effect() {
|
||||||
b.isModFarAwayDmg = true; //used in mob.damage()
|
b.isModFarAwayDmg = true; //used in mob.damage()
|
||||||
|
// game.drawList.push({ //draw range
|
||||||
game.drawList.push({ //draw range
|
// //add dmg to draw queue
|
||||||
//add dmg to draw queue
|
// x: player.position.x,
|
||||||
x: player.position.x,
|
// y: player.position.y,
|
||||||
y: player.position.y,
|
// radius: 3000,
|
||||||
radius: 3000,
|
// color: "rgba(255,0,0,0.05)",
|
||||||
color: "rgba(255,0,0,0.05)",
|
// time: 120
|
||||||
time: 120
|
// });
|
||||||
});
|
// game.drawList.push({ //draw range
|
||||||
game.drawList.push({ //draw range
|
// //add dmg to draw queue
|
||||||
//add dmg to draw queue
|
// x: player.position.x,
|
||||||
x: player.position.x,
|
// y: player.position.y,
|
||||||
y: player.position.y,
|
// radius: 500,
|
||||||
radius: 500,
|
// color: "rgba(0,0,0,0.2)",
|
||||||
color: "rgba(0,0,0,0.2)",
|
// time: 120
|
||||||
time: 120
|
// });
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1734,7 +1732,7 @@ const b = {
|
|||||||
name: "mine", //10
|
name: "mine", //10
|
||||||
description: "drop a <strong>proximity</strong> mine that <strong>sticks</strong> to walls<br>fires <strong>nails</strong> at enemies within range",
|
description: "drop a <strong>proximity</strong> mine that <strong>sticks</strong> to walls<br>fires <strong>nails</strong> at enemies within range",
|
||||||
ammo: 0,
|
ammo: 0,
|
||||||
ammoPack: 6,
|
ammoPack: 4,
|
||||||
have: false,
|
have: false,
|
||||||
isStarterGun: false,
|
isStarterGun: false,
|
||||||
fire() {
|
fire() {
|
||||||
@@ -1783,20 +1781,20 @@ const b = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
World.add(engine.world, bullet[me]); //add bullet to world
|
World.add(engine.world, bullet[me]); //add bullet to world
|
||||||
bullet[me].endCycle = game.cycle + 1800 + 360 * Math.random();
|
bullet[me].endCycle = game.cycle + 2000 + 360 * Math.random();
|
||||||
bullet[me].seeFrom = null;
|
|
||||||
bullet[me].restitution = 0;
|
bullet[me].restitution = 0;
|
||||||
bullet[me].lookFrequency = 41 + Math.floor(23 * Math.random())
|
bullet[me].lookFrequency = 41 + Math.floor(23 * Math.random())
|
||||||
bullet[me].range = 700
|
bullet[me].range = 700
|
||||||
|
|
||||||
bullet[me].arm = function () {
|
bullet[me].arm = function () {
|
||||||
this.do = function () { //overwrite the do method for this bullet
|
this.do = function () { //overwrite the do method for this bullet
|
||||||
this.force.y += this.mass * 0.002; //extra gravity
|
this.force.y += this.mass * 0.002; //extra gravity
|
||||||
if (!(game.cycle % this.lookFrequency)) { //find mob targets
|
if (!(game.cycle % this.lookFrequency)) { //find mob targets
|
||||||
for (let i = 0, len = mob.length; i < len; ++i) {
|
for (let i = 0, len = mob.length; i < len; ++i) {
|
||||||
if (Vector.magnitudeSquared(Vector.sub(this.seeFrom, mob[i].position)) < 500000 &&
|
if (Vector.magnitudeSquared(Vector.sub(this.position, mob[i].position)) < 500000 &&
|
||||||
mob[i].dropPowerUp &&
|
mob[i].dropPowerUp &&
|
||||||
Matter.Query.ray(map, this.seeFrom, mob[i].position).length === 0 &&
|
Matter.Query.ray(map, this.position, mob[i].position).length === 0 &&
|
||||||
Matter.Query.ray(body, this.seeFrom, mob[i].position).length === 0) {
|
Matter.Query.ray(body, this.position, mob[i].position).length === 0) {
|
||||||
this.endCycle = 0 //end life if mob is near and visible
|
this.endCycle = 0 //end life if mob is near and visible
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1809,22 +1807,39 @@ const b = {
|
|||||||
if (collide.length > 0) {
|
if (collide.length > 0) {
|
||||||
for (let i = 0; i < collide.length; i++) {
|
for (let i = 0; i < collide.length; i++) {
|
||||||
if (collide[i].bodyA.collisionFilter.category === cat.map || collide[i].bodyB.collisionFilter.category === cat.map) {
|
if (collide[i].bodyA.collisionFilter.category === cat.map || collide[i].bodyB.collisionFilter.category === cat.map) {
|
||||||
this.seeFrom = Vector.add(this.position, Vector.mult(collide[i].normal, -20)) //find the location 20 pixels perpendicular to the map
|
// console.log(collide)
|
||||||
// console.log()
|
|
||||||
const angle = Matter.Vector.angle(collide[i].normal, {
|
const angle = Matter.Vector.angle(collide[i].normal, {
|
||||||
x: 1,
|
x: 1,
|
||||||
y: 0
|
y: 0
|
||||||
})
|
})
|
||||||
if (angle > -0.1) Matter.Body.setStatic(this, true)
|
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))
|
||||||
|
//move until touching map again after rotation
|
||||||
|
for (let j = 0; j < 10; j++) {
|
||||||
|
if (Matter.Query.collides(this, map).length > 0) {
|
||||||
|
Matter.Body.setStatic(this, true) //don't set to static if not touching map
|
||||||
|
this.arm();
|
||||||
|
|
||||||
|
//sometimes the mine can't attach to map and it just needs to explode
|
||||||
|
const who = this
|
||||||
|
setTimeout(function () {
|
||||||
|
if (Matter.Query.collides(who, map).length === 0) who.endCycle = 0 // if not touching map explode
|
||||||
|
}, 100, who);
|
||||||
|
break
|
||||||
|
}
|
||||||
|
//move until you are touching the wall
|
||||||
|
Matter.Body.setPosition(this, Vector.add(this.position, Vector.mult(collide[i].normal, 2)))
|
||||||
|
}
|
||||||
|
} else if (this.speed < 1) {
|
||||||
this.arm();
|
this.arm();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { //check if collides with a body
|
}
|
||||||
|
} else if (this.speed < 1) { //check if collides with a body
|
||||||
collide = Matter.Query.collides(this, body)
|
collide = Matter.Query.collides(this, body)
|
||||||
if (collide.length > 0) {
|
if (collide.length > 0) {
|
||||||
for (let i = 0; i < collide.length; i++) {
|
for (let i = 0; i < collide.length; i++) {
|
||||||
if (collide[i].bodyA.collisionFilter.category === cat.body || collide[i].bodyB.collisionFilter.category === cat.body) {
|
if (collide[i].bodyA.collisionFilter.category === cat.body || collide[i].bodyB.collisionFilter.category === cat.body) {
|
||||||
this.seeFrom = this.position
|
|
||||||
this.arm();
|
this.arm();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1832,20 +1847,19 @@ const b = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bullet[me].onEnd = function () {
|
bullet[me].onEnd = function () {
|
||||||
if (!this.seeFrom) this.seeFrom = this.position
|
|
||||||
const targets = [] //target nearby mobs
|
const targets = [] //target nearby mobs
|
||||||
for (let i = 0, len = mob.length; i < len; i++) {
|
for (let i = 0, len = mob.length; i < len; i++) {
|
||||||
if (mob[i].dropPowerUp) {
|
if (mob[i].dropPowerUp) {
|
||||||
const dist = Vector.magnitudeSquared(Vector.sub(this.seeFrom, mob[i].position));
|
const dist = Vector.magnitudeSquared(Vector.sub(this.position, mob[i].position));
|
||||||
if (dist < 1440000 && //1200*1200
|
if (dist < 1440000 && //1200*1200
|
||||||
Matter.Query.ray(map, this.seeFrom, mob[i].position).length === 0 &&
|
Matter.Query.ray(map, this.position, mob[i].position).length === 0 &&
|
||||||
Matter.Query.ray(body, this.seeFrom, mob[i].position).length === 0) {
|
Matter.Query.ray(body, this.position, mob[i].position).length === 0) {
|
||||||
targets.push(Vector.add(mob[i].position, Vector.mult(mob[i].velocity, Math.sqrt(dist) / 60))) //predict where the mob will be in a few cycles
|
targets.push(Vector.add(mob[i].position, Vector.mult(mob[i].velocity, Math.sqrt(dist) / 60))) //predict where the mob will be in a few cycles
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let i = 0; i < 14; i++) {
|
for (let i = 0; i < 16; i++) {
|
||||||
const speed = 55 + 10 * Math.random()
|
const speed = 53 + 10 * Math.random()
|
||||||
if (targets.length > 0) { // aim near a random target in array
|
if (targets.length > 0) { // aim near a random target in array
|
||||||
const index = Math.floor(Math.random() * targets.length)
|
const index = Math.floor(Math.random() * targets.length)
|
||||||
const SPREAD = 150 / targets.length
|
const SPREAD = 150 / targets.length
|
||||||
@@ -1853,10 +1867,10 @@ 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.seeFrom, Vector.mult(Vector.normalise(Vector.sub(WHERE, this.seeFrom)), speed), 0.5)
|
b.nail(this.position, Vector.mult(Vector.normalise(Vector.sub(WHERE, this.position)), speed), 0.8)
|
||||||
} 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.seeFrom, {
|
b.nail(this.position, {
|
||||||
x: speed * Math.cos(ANGLE),
|
x: speed * Math.cos(ANGLE),
|
||||||
y: speed * Math.sin(ANGLE)
|
y: speed * Math.sin(ANGLE)
|
||||||
})
|
})
|
||||||
|
|||||||
18
js/level.js
18
js/level.js
@@ -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(10)
|
||||||
// mech.setField(3)
|
// mech.setField(3)
|
||||||
// b.giveMod(3);
|
// b.giveMod(3);
|
||||||
|
|
||||||
@@ -49,10 +49,10 @@ const level = {
|
|||||||
// if (level.isBuildRun) num++
|
// if (level.isBuildRun) num++
|
||||||
for (let i = 0; i < num; i++) {
|
for (let i = 0; i < num; i++) {
|
||||||
game.difficulty++
|
game.difficulty++
|
||||||
game.dmgScale += 0.11; //damage done by mobs increases each level
|
game.dmgScale += 0.13; //damage done by mobs increases each level
|
||||||
b.dmgScale *= 0.94; //damage done by player decreases each level
|
b.dmgScale *= 0.93; //damage done by player decreases each level
|
||||||
game.accelScale *= 1.03 //mob acceleration increases each level
|
game.accelScale *= 1.02 //mob acceleration increases each level
|
||||||
game.lookFreqScale *= 0.97 //mob cycles between looks decreases each level
|
game.lookFreqScale *= 0.98 //mob cycles between looks decreases each level
|
||||||
game.CDScale *= 0.97 //mob CD time decreases each level
|
game.CDScale *= 0.97 //mob CD time decreases each level
|
||||||
}
|
}
|
||||||
game.healScale = 1 / (1 + game.difficulty * 0.065) //a higher denominator makes for lower heals // mech.health += heal * game.healScale;
|
game.healScale = 1 / (1 + game.difficulty * 0.065) //a higher denominator makes for lower heals // mech.health += heal * game.healScale;
|
||||||
@@ -60,11 +60,11 @@ const level = {
|
|||||||
difficultyDecrease(num = 1) { //used in easy mode for game.reset()
|
difficultyDecrease(num = 1) { //used in easy mode for game.reset()
|
||||||
for (let i = 0; i < num; i++) {
|
for (let i = 0; i < num; i++) {
|
||||||
game.difficulty--
|
game.difficulty--
|
||||||
game.dmgScale -= 0.11; //damage done by mobs increases each level
|
game.dmgScale -= 0.13; //damage done by mobs increases each level
|
||||||
if (game.dmgScale < 0.1) game.dmgScale = 0.1;
|
if (game.dmgScale < 0.1) game.dmgScale = 0.1;
|
||||||
b.dmgScale /= 0.94; //damage done by player decreases each level
|
b.dmgScale /= 0.93; //damage done by player decreases each level
|
||||||
game.accelScale /= 1.03 //mob acceleration increases each level
|
game.accelScale /= 1.02 //mob acceleration increases each level
|
||||||
game.lookFreqScale /= 0.97 //mob cycles between looks decreases each level
|
game.lookFreqScale /= 0.98 //mob cycles between looks decreases each level
|
||||||
game.CDScale /= 0.97 //mob CD time decreases each level
|
game.CDScale /= 0.97 //mob CD time decreases each level
|
||||||
}
|
}
|
||||||
if (game.difficulty < 1) game.difficulty = 1;
|
if (game.difficulty < 1) game.difficulty = 1;
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ const spawn = {
|
|||||||
hopper(x, y, radius = 30 + Math.ceil(Math.random() * 30)) {
|
hopper(x, y, radius = 30 + Math.ceil(Math.random() * 30)) {
|
||||||
mobs.spawn(x, y, 5, radius, "rgb(0,200,180)");
|
mobs.spawn(x, y, 5, radius, "rgb(0,200,180)");
|
||||||
let me = mob[mob.length - 1];
|
let me = mob[mob.length - 1];
|
||||||
me.accelMag = 0.04 * game.accelScale;
|
me.accelMag = 0.04;
|
||||||
me.g = 0.0015; //required if using 'gravity'
|
me.g = 0.0015; //required if using 'gravity'
|
||||||
me.frictionAir = 0.018;
|
me.frictionAir = 0.018;
|
||||||
me.restitution = 0;
|
me.restitution = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user