<commit_before>var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);

app.get('/resume-game/start/[a-z]-[0-3]', function(req, res){
	res.sendfile('public/play.html');
});

app.use(express.static('public'));

var roomMap = {};
var makeTicker = function(roomId){
	return function(){
		//console.log(roomId, 'tick');
		var room = roomMap[roomId];
		room.players.forEach(function(player){
			var xDiff = player.x - player.xLast;
			var yDiff = player.y - player.yLast;
			player.angle = Math.atan2(yDiff, xDiff);
		});
		io.to(roomId).emit('tick', room);
	}
};
var initialRoomState = function(roomId){
	var room = {
		players: [
			{id: '0', x: -0.5, y: -0.5, xLast: 0, yLast: 0, angle: 0},
			{id: '1', x:  0.5, y: -0.5, xLast: 0, yLast: 0, angle: 0},
			{id: '2', x:  0.5, y:  0.5, xLast: 0, yLast: 0, angle: 0},
			{id: '3', x: -0.5, y:  0.5, xLast: 0, yLast: 0, angle: 0}
		]
	};
	roomMap[roomId] = room;
	setInterval(makeTicker(roomId), 1000/40);
	return room;
};

initialRoomState('a');
initialRoomState('b');
initialRoomState('c');
initialRoomState('d');


var asteroidsWrap = function(n){
	var x = n;
	if(Math.abs(n) > 1){
		var inverseSign = (Math.abs(n) / n) * -1;
		x += inverseSign * 2;
	}
	return x;
};

var handleConnection = function(socket){
	try {
		console.log('a user connected');
		var ident;
		var room;
		var player;
		socket.on('init', function(p){
			ident = p;
			var playerIndex = parseInt(ident.id, 10);
			room = roomMap[ident.room];
			player = room.players[playerIndex];
			socket.join(ident.room);
		});

		socket.on('cursor', function(cursor){
			if(player){
				var xWrapped = asteroidsWrap(cursor.x);
				var yWrapped = asteroidsWrap(cursor.y);
				if(
					xWrapped !== player.x &&
					yWrapped !== player.y
				){
					player.xLast = player.x;
					player.yLast = player.y;
					player.x = xWrapped;
					player.y = yWrapped;
				}
			}
		});

		socket.on('disconnect', function(){
			console.log('user disconnected');
		});
	} catch (e){
		console.log(e);
	}
};

io.on('connection', handleConnection);

http.listen(1027, function(){
	console.log('listening on *:1027');
});<commit_msg>Adding some hyper preliminary relative motion and velocity / drag type stuff<commit_after>var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);

app.get('/resume-game/start/[a-z]-[0-3]', function(req, res){
	res.sendfile('public/play.html');
});

app.use(express.static('public'));

var roomMap = {};
var makeTicker = function(roomId){
	return function(){
		//console.log(roomId, 'tick');
		var room = roomMap[roomId];
		var drag = 0.95;
		var cursorMultiplier = 0.05;
		room.players.forEach(function(player){
			player.xVel *= drag;
			player.yVel *= drag;
			player.xLast = player.x;
			player.yLast = player.y;
			player.x = asteroidsWrap(player.x + (player.xVel * cursorMultiplier));
			player.y = asteroidsWrap(player.y + (player.yVel * cursorMultiplier));
			var xDiff = player.x - player.xLast;
			var yDiff = player.y - player.yLast;
			player.angle = Math.atan2(yDiff, xDiff);
		});
		io.to(roomId).emit('tick', room);
	}
};
var initialRoomState = function(roomId){
	var room = {
		players: [
			{id: '0', x: -0.5, y: -0.5, xLast: 0, yLast: 0, angle: 0, xVel: 0, yVel: 0},
			{id: '1', x:  0.5, y: -0.5, xLast: 0, yLast: 0, angle: 0, xVel: 0, yVel: 0},
			{id: '2', x:  0.5, y:  0.5, xLast: 0, yLast: 0, angle: 0, xVel: 0, yVel: 0},
			{id: '3', x: -0.5, y:  0.5, xLast: 0, yLast: 0, angle: 0, xVel: 0, yVel: 0}
		]
	};
	roomMap[roomId] = room;
	setInterval(makeTicker(roomId), 1000/40);
	return room;
};

initialRoomState('a');
initialRoomState('b');
initialRoomState('c');
initialRoomState('d');


var asteroidsWrap = function(n){
	var x = n;
	if(Math.abs(n) > 1){
		var inverseSign = (Math.abs(n) / n) * -1;
		x += inverseSign * 2;
	}
	return x;
};

var handleConnection = function(socket){
	try {
		console.log('a user connected');
		var ident;
		var room;
		var player;
		socket.on('init', function(p){
			ident = p;
			var playerIndex = parseInt(ident.id, 10);
			room = roomMap[ident.room];
			player = room.players[playerIndex];
			socket.join(ident.room);
		});

		socket.on('cursor', function(cursor){
			if(player){
				if(
					player.xVel !== cursor.x &&
					player.yVel !== cursor.y
				){
					player.xVel = cursor.x;
					player.yVel = cursor.y;
				}
			}
		});

		socket.on('disconnect', function(){
			console.log('user disconnected');
		});
	} catch (e){
		console.log(e);
	}
};

io.on('connection', handleConnection);

http.listen(1027, function(){
	console.log('listening on *:1027');
});
{'fraction_non_alphanumeric': 0.19659211927582534, 'fraction_numerical': 0.025985090521831736, 'mean_word_length': 3.5548011639185257, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1703700', 'n_tokens_mistral': 2066, 'n_tokens_neox': 1818, 'n_words': 412}