added difficulty settings

This commit is contained in:
landgreen
2019-11-22 05:42:40 -08:00
parent 129fc555c3
commit 31d9ba7956
10 changed files with 203 additions and 138 deletions

View File

@@ -78,50 +78,51 @@ function mobCollisionChecks(event) {
for (let i = 0, j = pairs.length; i != j; i++) {
//body + player collision
// if (mech.damageImmune < mech.cycle) {
// if (pairs[i].bodyA === playerBody || pairs[i].bodyA === playerHead) {
// collidePlayer(pairs[i].bodyB)
// } else if (pairs[i].bodyB === playerBody || pairs[i].bodyB === playerHead) {
// collidePlayer(pairs[i].bodyA)
// }
// }
if (mech.damageImmune < mech.cycle) {
if (pairs[i].bodyA === playerBody || pairs[i].bodyA === playerHead) {
collidePlayer(pairs[i].bodyB)
} else if (pairs[i].bodyB === playerBody || pairs[i].bodyB === playerHead) {
collidePlayer(pairs[i].bodyA)
}
}
// function collidePlayer(obj, speedThreshold = 12, massThreshold = 2) {
// if (obj.classType === "body" && obj.speed > speedThreshold && obj.mass > massThreshold) { //dmg from hitting a body
// const v = Matter.Vector.magnitude(Matter.Vector.sub(player.velocity, obj.velocity));
// if (v > speedThreshold) {
// mech.damageImmune = mech.cycle + 30; //player is immune to collision damage for 30 cycles
// let dmg = Math.sqrt((v - speedThreshold + 0.1) * (obj.mass - massThreshold)) * 0.02;
// dmg = Math.min(Math.max(dmg, 0.02), 0.2);
// // console.log(`mass = ${obj.mass} \n`, `dmg = ${dmg}\n`, `v = ${v}\n`)
// // console.log(v, dmg)
// mech.damage(dmg);
// game.drawList.push({
// //add dmg to draw queue
// x: pairs[i].activeContacts[0].vertex.x,
// y: pairs[i].activeContacts[0].vertex.y,
// radius: dmg * 500,
// color: game.mobDmgColor,
// time: game.drawTime
// });
// return;
// }
// } else if (obj.isStatic && player.speed > speedThreshold * 2) { //falling dmg / hitting map dmg
// mech.damageImmune = mech.cycle + 30;
// console.log(player.speed)
// let dmg = Math.min(Math.max(player.speed * 0.001, 0.02), 0.2);
// mech.damage(dmg);
// game.drawList.push({
// //add dmg to draw queue
// x: pairs[i].activeContacts[0].vertex.x,
// y: pairs[i].activeContacts[0].vertex.y,
// radius: dmg * 500,
// color: game.mobDmgColor,
// time: game.drawTime
// });
// return;
// }
// }
function collidePlayer(obj, speedThreshold = 12, massThreshold = 2) {
if (obj.classType === "body" && obj.speed > speedThreshold && obj.mass > massThreshold) { //dmg from hitting a body
const v = Matter.Vector.magnitude(Matter.Vector.sub(player.velocity, obj.velocity));
if (v > speedThreshold) {
mech.damageImmune = mech.cycle + 30; //player is immune to collision damage for 30 cycles
let dmg = Math.sqrt((v - speedThreshold + 0.1) * (obj.mass - massThreshold)) * 0.02;
dmg = Math.min(Math.max(dmg, 0.02), 0.2);
// console.log(`mass = ${obj.mass} \n`, `dmg = ${dmg}\n`, `v = ${v}\n`)
// console.log(v, dmg)
mech.damage(dmg);
game.drawList.push({
//add dmg to draw queue
x: pairs[i].activeContacts[0].vertex.x,
y: pairs[i].activeContacts[0].vertex.y,
radius: dmg * 500,
color: game.mobDmgColor,
time: game.drawTime
});
return;
}
}
// else if (obj.isStatic && player.speed > speedThreshold * 2) { //falling dmg / hitting map dmg
// mech.damageImmune = mech.cycle + 30;
// console.log(player.speed)
// let dmg = Math.min(Math.max(player.speed * 0.001, 0.02), 0.2);
// mech.damage(dmg);
// game.drawList.push({
// //add dmg to draw queue
// x: pairs[i].activeContacts[0].vertex.x,
// y: pairs[i].activeContacts[0].vertex.y,
// radius: dmg * 500,
// color: game.mobDmgColor,
// time: game.drawTime
// });
// return;
// }
}
//mob + (player,bullet,body) collisions
for (let k = 0; k < mob.length; k++) {