forked from ethanjurman/shoot-it
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (54 loc) · 1.86 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var path = require('path');
var browserify = require('browserify-middleware');
var to5ify = require("6to5ify");
app.get('/', function(req, res){
res.sendFile(__dirname + '/host/index.html');
});
app.get('/asteroidDrive.gif', function(req, res){
res.sendFile(__dirname + '/host/asteroidDrive.gif');
});
app.get('/control', function(req, res){
res.sendFile(__dirname + '/control/index.html');
});
app.get('/config', function(req, res){
res.sendFile(__dirname + '/control/config.html');
});
app.get('/main.css', function(req, res){
res.sendFile(__dirname + '/host/main.css');
});
app.get('/control/main.css', function(req, res){
res.sendFile(__dirname + '/control/main.css');
});
app.get('/host.js', browserify('./host/index.js', {transforms: [to5ify]}));
app.get('/index.js', browserify('./control/index.js', {transforms: [to5ify]}));
app.get('/config.js', browserify('./control/config.js', {transforms: [to5ify]}));
app.get('/manifest.json', function(req, res){
res.sendFile(__dirname + '/manifest.json');
});
app.use(express.static(path.join(__dirname, 'static')));
var playerCount = 0;
io.on('connection', function(socket){
var playerId = ++playerCount;
socket.on('add plane', function(color, initials){
console.log(playerId + " joined");
var player = {playerId:playerId,color:color,initials:initials};
io.emit('add plane',player);
});
socket.on('disconnect', function(){
console.log(playerId + " left");
io.emit('remove plane',playerId);
});
socket.on('fire', function(){
io.emit('fire',playerId);
});
socket.on('update plane', function(motion){
io.emit('update plane',[playerId,motion]); // this goes to index.js on host
});
});
http.listen(80, function(){
console.log('listening on *:80');
});