working on falling dmg

This commit is contained in:
lilgreenland
2019-11-21 14:35:50 -08:00
parent 6ce17c9b39
commit 129fc555c3

View File

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