Skip to content

Commit

Permalink
Merge pull request #231 from abalabahaha/testing
Browse files Browse the repository at this point in the history
#224, #225, and a misc. tweak or two
  • Loading branch information
igorantun committed Jun 24, 2015
2 parents 9c0fb94 + f75a9e7 commit cccf0a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
6 changes: 4 additions & 2 deletions server/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
"gameWidth": 5000,
"gameHeight": 5000,
"adminPass": "DEFAULT",
"gameMass": 2000,
"gameMass": 20000,
"maxFood": 1000,
"slowBase": 4,
"logChat": 0,
"networkUpdateFactor": 40,
"maxHeartbeatInterval": 5000,
"foodUniformDisposition": true,
"newPlayerInitialPosition": "farthest"
"newPlayerInitialPosition": "farthest",
"massLossRate": 10
}
24 changes: 13 additions & 11 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,16 @@ function balanceMass() {
.map(function(u) {return u.mass; })
.reduce(function(pu,cu) { return pu+cu;}, 0);

if (totalMass < c.gameMass) {
var missingMass = c.gameMass - totalMass;
console.log('adding ' + missingMass + ' mass to level');
addFood(parseInt(missingMass / c.foodMass));
if (food.length < c.maxFood && totalMass + (c.maxFood - food.length) * c.foodMass < c.gameMass) {
var missingFood = c.maxFood - food.length;
console.log('adding ' + missingFood + ' food to level');
addFood(c.maxFood - food.length);
console.log('mass rebalanced');
}
else if (totalMass > c.gameMass) {
var excessMass = totalMass - c.gameMass;
console.log('removing ' + excessMass + ' mass from level');
removeFood(parseInt(excessMass / c.foodMass));
var excessFood = parseInt((totalMass - c.gameMass) / food.length);
console.log('removing ' + excessFood + ' food from level');
removeFood(excessFood);
console.log('mass rebalanced');
}
}
Expand Down Expand Up @@ -452,9 +452,11 @@ function gameloop() {
}
}

// rebalance mass
balanceMass();
for (i = 0; i < users.length; i++) {
users[i].mass = users[i].mass * (1 - (c.massLossRate / 1000));
}
}
balanceMass();
}


Expand Down Expand Up @@ -482,7 +484,7 @@ function sendUpdates() {
id: f.id,
x: f.x,
y: f.y,
mass: f.mass,
mass: Math.round(f.mass),
hue: f.hue,
name: f.name
};
Expand All @@ -493,7 +495,7 @@ function sendUpdates() {
sockets[u.id].emit('serverTellPlayerMove', {
x: u.x,
y: u.y,
mass: u.mass
mass: Math.round(u.mass)
}, visibleEnemies, visibleFood);
if (leaderboardChanged) {
sockets[u.id].emit('leaderboard', {
Expand Down

0 comments on commit cccf0a2

Please sign in to comment.