Skip to content

Commit

Permalink
Upgraded to 0.0.5b1
Browse files Browse the repository at this point in the history
  • Loading branch information
RowanHarley authored Jun 27, 2016
1 parent 482ddcc commit b6dd6e0
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 38 deletions.
55 changes: 27 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,12 @@ function handleConnection(conn) {

function close(id) {
console.log("[DEBUG] Connection closed.");
//clearInterval(conn.snake.update);
clearInterval(conn.snake.update);
delete clients[id];
}
conn.on('message', handleMessage.bind(this, conn));
//conn.on('error', close.bind(conn.id));
conn.on('error', function(e){
console.log(e);
close(conn.id);
delete clients[conn.id];
});

conn.on('close', close.bind(conn.id));
conn.on('error', close.bind(conn.id));
conn.on('close', close.bind(conn.id));
send(conn.id, messages.initial);
}
function handleMessage(conn, data) {
Expand Down Expand Up @@ -119,16 +113,17 @@ function handleMessage(conn, data) {
conn.snake.update = setInterval((function() {
conn.snake.body.x += Math.round(Math.cos(conn.snake.direction.angle * 1.44 * Math.PI / 180) * 170);
conn.snake.body.y += Math.round(Math.sin(conn.snake.direction.angle * 1.44 * Math.PI / 180) * 170);
/*


var R = config["gameRadius"];
var r = Math.pow((conn.snake.body.x - 0), 2) + Math.pow((conn.snake.body.y - 0), 2);
if (r < R^2){
messages.end.build();
var r = (Math.pow((conn.snake.body.x - 0), 2)) + (Math.pow((conn.snake.body.y - 0), 2));
if (r < Math.pow(R, 2)){
//console.log("[TEST] " + r + " < " + R^2);
console.log("[DEBUG] Outside of Radius");
messages.end.build(0);
conn.close();
}
broadcast(messages.position.build(conn.snake.id, conn.snake.body.x, conn.snake.body.y));
*/
//broadcast(messages.position.build(conn.id, conn.snake.body.x, conn.snake.body.y));
broadcast(messages.direction.build(conn.id, conn.snake.direction));
broadcast(messages.movement.build(conn.id, conn.snake.direction.x, conn.snake.direction.y));
}), 230);
Expand Down Expand Up @@ -198,19 +193,23 @@ function broadcast(data){
}
}
}
/* function setMscps(b) {
var mscps = b;
fmlts = [];
fpsls = [];
for (b = 0; b <= mscps; b++) b >= mscps ? fmlts.push(fmlts[b - 1]) : fmlts.push(Math.pow(1 - b / mscps, 2.25)),
0 == b ? fpsls.push(0) : fpsls.push(fpsls[b - 1] + 1 / fmlts[b - 1]);
var f = fmlts[fmlts.length - 1],
c = fpsls[fpsls.length - 1];
for (b = 0; 2048 > b; b++){
fmlts.push(f);
fpsls.push(c);
function setMscps(mscps) {
fmlts = [mscps + 1 + 2048];
fpsls = [mscps + 1 + 2048];

for (var i = 0; i <= mscps; i++) {
fmlts[i] = (i >= mscps ? fmlts[i - 1] : Math.pow(1 - 1.0 * i / mscps, 2.25));
fpsls[i] = (i == 0 ? 0 : fpsls[i - 1] + 1.0 / fmlts[i - 1]);
}
} */

var fmltsFiller = fmlts[mscps];
var fpslsFiller = fpsls[mscps];

for (var i = 0; i < 2048; i++) {
fmlts[mscps + 1 + i] = fmltsFiller;
fpsls[mscps + 1 + i] = fpslsFiller;
}
}

function close(){
console.log("[SERVER] Server Closed");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Slither-Server",
"description": "A Server for Slither.io",
"version": "0.0.3",
"version": "0.0.5b1",
"repository": {
"type": "git",
"url": "https://github.com/RowanHarley/Slither-Server/"
Expand Down
4 changes: 2 additions & 2 deletions src/entities/snake.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module.exports = Snake = (function() {
this.sct = 2;
this.fam = 0 * 16777215;
this.direction = {
x: 0.1,
y: 0.1,
x: 1,
y: 1,
angle: 0
};
this.parts = [];
Expand Down
6 changes: 3 additions & 3 deletions src/messages/end.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var message = require('../utils/message');

exports.build = function(){
exports.build = function(endNum){
var arr = new Uint8Array(4);

var b = 0;
Expand All @@ -10,7 +10,7 @@ exports.build = function(){
b += message.writeInt8(b, arr, 0);

b += message.writeInt8(b, arr, 'v'.charCodeAt(0));

b += message.writeInt8(b, arr, 1);
// 0-2; 0 is normal death, 1 is new highscore of the day, 2 is unknown
b += message.writeInt8(b, arr, endNum);
};

2 changes: 1 addition & 1 deletion src/messages/movement.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var message = require('../utils/message');
var type = 'G'.charCodeAt(0);

exports.build = function(id, x, y) {
var arr = new Uint8Array(9);
var arr = new Uint8Array(7);
var b = 0;
b += message.writeInt8(b, arr, 0);
b += message.writeInt8(b, arr, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/messages/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var message = require('../utils/message');
var type = 'g'.charCodeAt(0);

exports.build = function(id, x, y) {
var arr = new Uint8Array(10);
var arr = new Uint8Array(9);
var b = 0;
b += message.writeInt8(b, arr, 0);
b += message.writeInt8(b, arr, 0);
Expand Down
6 changes: 4 additions & 2 deletions src/utils/math.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
var config = require("../../config/config.js");

exports.randomInt = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};

exports.randomSpawnPoint = function() {
return {
x: exports.randomInt(5000 * 5, 30000 * 5),
y: exports.randomInt(5000 * 5, 30000 * 5)
x: exports.randomInt(5000 * 5, config["gameRadius"] * 5),
y: exports.randomInt(5000 * 5, config["gameRadius"] * 5)
};
};

Expand Down

0 comments on commit b6dd6e0

Please sign in to comment.