mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
trying a new approach to calculating damager
This commit is contained in:
parent
16826b174a
commit
f9d97c5a47
4 changed files with 64 additions and 20 deletions
|
|
@ -47,31 +47,32 @@ function (Parent, Item, Box2D, Nc, Assert) {
|
||||||
var item = otherBody.GetUserData();
|
var item = otherBody.GetUserData();
|
||||||
if(item instanceof Item) {
|
if(item instanceof Item) {
|
||||||
var itemVelocity = item.body.GetLinearVelocity();
|
var itemVelocity = item.body.GetLinearVelocity();
|
||||||
var itemMass = item.body.GetMass();
|
//var itemMass = item.body.GetMass();
|
||||||
|
|
||||||
var ownVelocity = this.body.GetLinearVelocity();
|
var ownVelocity = this.body.GetLinearVelocity();
|
||||||
|
|
||||||
var b2Math = Box2D.Common.Math.b2Math;
|
var b2Math = Box2D.Common.Math.b2Math;
|
||||||
|
|
||||||
var absItemVelocity = b2Math.AbsV(itemVelocity);
|
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) {
|
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) {
|
var collision = b2Math.SubtractVV(itemVelocity, ownVelocity);
|
||||||
damage += item.options.danger * 90 * (velocity / 128) * (itemMass + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
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() {
|
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);
|
Nc.trigger(Nc.ns.channel.engine.worldQueue.add, callback);
|
||||||
|
|
|
||||||
|
|
@ -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;
|
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) this.stats.health = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
if(this.stats.health <= 0) {
|
if(this.stats.health <= 0) {
|
||||||
if(enemy != this) enemy.score();
|
if(enemy != this) enemy.score();
|
||||||
this.kill(enemy, byItem);
|
this.kill(enemy, byItem);
|
||||||
} else {
|
} else {
|
||||||
this.broadcastStats();
|
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) {
|
Player.prototype.spawn = function(x, y) {
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) {
|
||||||
setTimeout(function(){self.ping.innerHTML = "Reload in 3...".replace(/ /g, ' ');}, 6000);
|
setTimeout(function(){self.ping.innerHTML = "Reload in 3...".replace(/ /g, ' ');}, 6000);
|
||||||
setTimeout(function(){self.ping.innerHTML = "Reload in 2...".replace(/ /g, ' ');}, 7000);
|
setTimeout(function(){self.ping.innerHTML = "Reload in 2...".replace(/ /g, ' ');}, 7000);
|
||||||
setTimeout(function(){self.ping.innerHTML = "Reload in 1...".replace(/ /g, ' ');}, 8000);
|
setTimeout(function(){self.ping.innerHTML = "Reload in 1...".replace(/ /g, ' ');}, 8000);
|
||||||
setTimeout(function(){self.ping.innerHTML = "Reload now. ".replace(/ /g, ' '); location.reload(); }, 9000);
|
setTimeout(function(){self.ping.innerHTML = "Reload now. ".replace(/ /g, ' '); location.reload(); }, 1000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@
|
||||||
"type":"imagelayer",
|
"type":"imagelayer",
|
||||||
"visible":false,
|
"visible":false,
|
||||||
"width":0,
|
"width":0,
|
||||||
"x":0,
|
"x":-25,
|
||||||
"y":0
|
"y":-68
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"height":0,
|
"height":0,
|
||||||
"image":"..\/..\/img\/Backgrounds\/clouds.png",
|
"image":"..\/..\/img\/Backgrounds\/clouds.png",
|
||||||
"name":"clouds",
|
"name":"clouds",
|
||||||
"opacity":0.3,
|
"opacity":0.300000011920929,
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
"parallaxSpeed":"-0.3"
|
"parallaxSpeed":"-0.3"
|
||||||
|
|
@ -50,6 +50,7 @@
|
||||||
{
|
{
|
||||||
"ellipse":true,
|
"ellipse":true,
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":1,
|
||||||
"name":"",
|
"name":"",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -65,6 +66,7 @@
|
||||||
{
|
{
|
||||||
"ellipse":true,
|
"ellipse":true,
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":2,
|
||||||
"name":"",
|
"name":"",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -80,6 +82,7 @@
|
||||||
{
|
{
|
||||||
"ellipse":true,
|
"ellipse":true,
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":3,
|
||||||
"name":"",
|
"name":"",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -95,6 +98,7 @@
|
||||||
{
|
{
|
||||||
"ellipse":true,
|
"ellipse":true,
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":4,
|
||||||
"name":"",
|
"name":"",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -110,6 +114,7 @@
|
||||||
{
|
{
|
||||||
"ellipse":true,
|
"ellipse":true,
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":5,
|
||||||
"name":"",
|
"name":"",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -125,6 +130,7 @@
|
||||||
{
|
{
|
||||||
"ellipse":true,
|
"ellipse":true,
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":6,
|
||||||
"name":"",
|
"name":"",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -140,6 +146,7 @@
|
||||||
{
|
{
|
||||||
"ellipse":true,
|
"ellipse":true,
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":7,
|
||||||
"name":"",
|
"name":"",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -177,6 +184,7 @@
|
||||||
"objects":[
|
"objects":[
|
||||||
{
|
{
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":8,
|
||||||
"name":"Large Cleaver",
|
"name":"Large Cleaver",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -191,6 +199,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":9,
|
||||||
"name":"Small Cleaver",
|
"name":"Small Cleaver",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -205,6 +214,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":10,
|
||||||
"name":"Rube",
|
"name":"Rube",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -219,6 +229,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":11,
|
||||||
"name":"Knife",
|
"name":"Knife",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -233,6 +244,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":12,
|
||||||
"name":"Large Cleaver",
|
"name":"Large Cleaver",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -247,6 +259,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":13,
|
||||||
"name":"Small Cleaver",
|
"name":"Small Cleaver",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -261,6 +274,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"height":0,
|
"height":0,
|
||||||
|
"id":14,
|
||||||
"name":"Knife",
|
"name":"Knife",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
@ -272,6 +286,21 @@
|
||||||
"width":0,
|
"width":0,
|
||||||
"x":464,
|
"x":464,
|
||||||
"y":357
|
"y":357
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"height":0,
|
||||||
|
"id":15,
|
||||||
|
"name":"Piano",
|
||||||
|
"properties":
|
||||||
|
{
|
||||||
|
|
||||||
|
},
|
||||||
|
"rotation":0,
|
||||||
|
"type":"",
|
||||||
|
"visible":true,
|
||||||
|
"width":0,
|
||||||
|
"x":206,
|
||||||
|
"y":183
|
||||||
}],
|
}],
|
||||||
"opacity":1,
|
"opacity":1,
|
||||||
"type":"objectgroup",
|
"type":"objectgroup",
|
||||||
|
|
@ -280,11 +309,13 @@
|
||||||
"x":0,
|
"x":0,
|
||||||
"y":0
|
"y":0
|
||||||
}],
|
}],
|
||||||
|
"nextobjectid":16,
|
||||||
"orientation":"orthogonal",
|
"orientation":"orthogonal",
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
|
|
||||||
},
|
},
|
||||||
|
"renderorder":"right-down",
|
||||||
"tileheight":25,
|
"tileheight":25,
|
||||||
"tilesets":[
|
"tilesets":[
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue