/
circles.html
90 lines (77 loc) · 1.87 KB
/
circles.html
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!doctype html>
<html>
<head>
<title>maga</title>
<script src="/exposed.js"></script>
<script src="/jquery.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
$(function() {
var config = require('config')
, socket = new io.Socket(config.host)
// maga
var Maga = require('maga')
, playerManager = require('middleware/playerManager')
, Circles = require('circles')
// new game
var game = new Maga.Game('Circles')
, room = game.createRoom()
, players = playerManager(room, Circles)
, me
// socket.io
socket.on('connect', function() {
// add our own player to the game
var me = players.createMyself(parseInt(socket.transport.sessionid, 10).toString(32))
room.addObject(me)
room.watch(me, function(str) {
socket.send(str)
})
// send mouse input to our player
$('body').mousemove(function(ev) {
me.move(ev.pageX, ev.pageY)
})
// main loop
room.loop(function() {
$('#console').text(this.state.frame)
})
})
socket.on('message', function(message) {
room.parse(message, function(state) {
players.set(state)
room.applyState(state)
})
})
socket.on('disconnect', function() {
players.remove(me)
})
socket.connect()
})
</script>
<style>
html, body {
width:100%;
height:100%;
overflow:hidden;
background:#070707;
}
.circle {
position:absolute;
border-radius:1000px;
}
#console {
position:fixed;
top:0;
left:0;
z-index:10000;
color:#BBB;
font-family:Courier;
width:300px;
height:200px;
}
</style>
</head>
<body>
<div id="console"></div>
<a href="http://github.com/stagas/maga" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0; z-index:10000;" src="https://d3nwyuy0nl342s.cloudfront.net/img/4c7dc970b89fd04b81c8e221ba88ff99a06c6b61/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67" alt="Fork me on GitHub"></a>
</body>
</html>