Files
  • index.js
  • monsters
  • node_modules
  • objects
  • gm.html
  • gm_init.js
  • index.html
  • listeners.js
  • package-lock.json
  • player_init.js
  • rot.min.js
  • state.js
  • utilities.js
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
var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs')
app.listen(process.argv[2] || 8080);
io.set('log level', 1);
function handler (req, res) {
    var path;
    var allowedURLs = ["/index.html", "/gm.html", "/rot.min.js"];
    if(allowedURLs.indexOf(req.url)) { path = req.url; }
    if(req.url == "/") { path = "/index.html"; }

    fs.readFile(__dirname + path,
		function (err, data) {
		    if (err) {
			res.writeHead(500);
			return res.end('Error loading');
		    }
		    
		    res.writeHead(200);
		    res.end(data);
		});
}

var ROT = require("rot");

ROT.DEFAULT_WIDTH = 80;
ROT.DEFAULT_HEIGHT = 30;

var state = require("./state");
var listeners = require("./listeners");

var utilities = require("./utilities");

// import entity constructors
var construct = require("./objects/entity_objects");
var creatures = require("./monsters/entity_creatures");

// generate level 1 map
utilities.generateMapLevel(1);

io.sockets.on('connection', function(socket) {
    socket.on("player", function() { require("./player_init")(socket) });
    socket.on("gm", function() { require("./gm_init")(socket) });
});

// make active entities act (shots, monsters, time bombs, etc.)
var worldPeriod = 200;
setInterval(function() {
    for(var i in state.activeEntities) {
        var e = state.activeEntities[i];
        e.timeToNext -= worldPeriod;
        if(e.timeToNext <= 0) {
            e.timeToNext = Math.max(0, e.intervalTime + e.timeToNext);
            if(e.act) { e.act(); }
        }
    }
}, worldPeriod);
node v9.7.1 linux/amd64