-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (31 loc) · 834 Bytes
/
index.js
File metadata and controls
43 lines (31 loc) · 834 Bytes
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
const express = require('express');
const http = require('http');
const socketIO = require('socket.io');
const Game = require('./lib/Game');
const PORT = 5000;
const FPS = 60;
let app = express();
let server = http.Server(app);
let io = socketIO(server);
app.set('port', PORT);
app.set('view engine', 'ejs');
app.use('/static', express.static(__dirname + '/static'));
app.get('/', (req, res) => {
res.render('index');
});
let game = new Game();
io.on('connection', (socket) => {
socket.on('join', (data) => {
game.addNewPlayer(socket, data);
});
socket.on('input', (data) => {
game.updateUserInput(socket, data);
})
});
setInterval(() => {
game.gameLoop();
game.updateClients();
}, 1000 / FPS);
server.listen(PORT, () => {
console.log(`Starting server on port ${PORT}`);
});