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);
}
};

View file

@ -13,14 +13,14 @@
"type":"imagelayer",
"visible":false,
"width":0,
"x":0,
"y":0
},
"x":-25,
"y":-68
},
{
"height":0,
"image":"..\/..\/img\/Backgrounds\/clouds.png",
"name":"clouds",
"opacity":0.3,
"opacity":0.300000011920929,
"properties":
{
"parallaxSpeed":"-0.3"
@ -50,6 +50,7 @@
{
"ellipse":true,
"height":0,
"id":1,
"name":"",
"properties":
{
@ -65,6 +66,7 @@
{
"ellipse":true,
"height":0,
"id":2,
"name":"",
"properties":
{
@ -80,6 +82,7 @@
{
"ellipse":true,
"height":0,
"id":3,
"name":"",
"properties":
{
@ -95,6 +98,7 @@
{
"ellipse":true,
"height":0,
"id":4,
"name":"",
"properties":
{
@ -110,6 +114,7 @@
{
"ellipse":true,
"height":0,
"id":5,
"name":"",
"properties":
{
@ -125,6 +130,7 @@
{
"ellipse":true,
"height":0,
"id":6,
"name":"",
"properties":
{
@ -140,6 +146,7 @@
{
"ellipse":true,
"height":0,
"id":7,
"name":"",
"properties":
{
@ -177,6 +184,7 @@
"objects":[
{
"height":0,
"id":8,
"name":"Large Cleaver",
"properties":
{
@ -191,6 +199,7 @@
},
{
"height":0,
"id":9,
"name":"Small Cleaver",
"properties":
{
@ -205,6 +214,7 @@
},
{
"height":0,
"id":10,
"name":"Rube",
"properties":
{
@ -219,6 +229,7 @@
},
{
"height":0,
"id":11,
"name":"Knife",
"properties":
{
@ -233,6 +244,7 @@
},
{
"height":0,
"id":12,
"name":"Large Cleaver",
"properties":
{
@ -247,6 +259,7 @@
},
{
"height":0,
"id":13,
"name":"Small Cleaver",
"properties":
{
@ -261,6 +274,7 @@
},
{
"height":0,
"id":14,
"name":"Knife",
"properties":
{
@ -272,6 +286,21 @@
"width":0,
"x":464,
"y":357
},
{
"height":0,
"id":15,
"name":"Piano",
"properties":
{
},
"rotation":0,
"type":"",
"visible":true,
"width":0,
"x":206,
"y":183
}],
"opacity":1,
"type":"objectgroup",
@ -280,11 +309,13 @@
"x":0,
"y":0
}],
"nextobjectid":16,
"orientation":"orthogonal",
"properties":
{
},
"renderorder":"right-down",
"tileheight":25,
"tilesets":[
{