trying a new approach to calculating damager

This commit is contained in:
logsol 2015-04-02 19:35:10 +02:00
parent 16826b174a
commit f9d97c5a47
4 changed files with 64 additions and 20 deletions

View file

@ -47,31 +47,32 @@ function (Parent, Item, Box2D, Nc, Assert) {
var item = otherBody.GetUserData();
if(item instanceof Item) {
var itemVelocity = item.body.GetLinearVelocity();
var itemMass = item.body.GetMass();
//var itemMass = item.body.GetMass();
var ownVelocity = this.body.GetLinearVelocity();
var b2Math = Box2D.Common.Math.b2Math;
var absItemVelocity = b2Math.AbsV(itemVelocity);
var max = 1;
var min = 1;
if(absItemVelocity.x > max || absItemVelocity.y > max) {
if(absItemVelocity.x > min || absItemVelocity.y > min) {
if(item.lastMoved && item.lastMoved.player != this.player) {
var damageVector = b2Math.SubtractVV(itemVelocity, ownVelocity);
damageVector.Abs();
var velocity = damageVector.Length();
damageVector.Multiply(itemMass / 3.6);
var damage = damageVector.Length();
if(item.options.danger) {
damage += item.options.danger * 90 * (velocity / 128) * (itemMass + 1);
}
var collision = b2Math.SubtractVV(itemVelocity, ownVelocity);
var player = item.lastMoved.player;
// Tested max velocity banana: 50
var velocityDamage = collision.Length() / 50;
// Max weight of piano: 15
var weightDamage = item.options.weight / 15;
// Max danger of knife: 3
var dangerDamage = item.options.danger / 3;
var damage = velocityDamage * (weightDamage * 180 + dangerDamage * 80);
var callback = function() {
self.player.addDamage(damage, player, item);
self.player.addDamage(damage, item.lastMoved.player, item);
};
Nc.trigger(Nc.ns.channel.engine.worldQueue.add, callback);

View file

@ -60,17 +60,29 @@ function (Parent, Nc) {
}
};
Player.prototype.addDamage = function(damage, enemy, byItem) {
Player.prototype.addDamage = function(damage, enemy, byItem, reheal) {
this.stats.health -= damage;
if(this.stats.health > 100) this.stats.health = 100;
if(this.stats.health < 0) this.stats.health = 0;
/*
if(this.stats.health <= 0) {
if(enemy != this) enemy.score();
this.kill(enemy, byItem);
} else {
this.broadcastStats();
}
*/
this.broadcastStats();
if (!reheal) {
// reheal hack after 1 second
var self = this;
setTimeout(function(){
self.addDamage(-100, enemy, byItem, true);
}, 2500);
}
};
Player.prototype.spawn = function(x, y) {

View file

@ -186,7 +186,7 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
setTimeout(function(){self.ping.innerHTML = "Reload in 3...".replace(/ /g, '&nbsp;');}, 6000);
setTimeout(function(){self.ping.innerHTML = "Reload in 2...".replace(/ /g, '&nbsp;');}, 7000);
setTimeout(function(){self.ping.innerHTML = "Reload in 1...".replace(/ /g, '&nbsp;');}, 8000);
setTimeout(function(){self.ping.innerHTML = "Reload now. ".replace(/ /g, '&nbsp;'); location.reload(); }, 9000);
setTimeout(function(){self.ping.innerHTML = "Reload now. ".replace(/ /g, '&nbsp;'); location.reload(); }, 1000);
}
};