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++) {
//body + player collision
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) {
if (obj.classType === "body" && obj.speed > speedThreshold && obj.mass > 2) {
const v = Matter.Vector.magnitude(Matter.Vector.sub(player.velocity, obj.velocity));
if (v > speedThreshold && mech.damageImmune < mech.cycle) {
mech.damageImmune = mech.cycle + 30; //player is immune to collision damage for 30 cycles
let dmg = Math.sqrt(v * obj.mass) * 0.01;
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;
}
}
}
// 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++) {