forked from wahoti/HelloCircle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
63 lines (58 loc) · 1.75 KB
/
Copy pathindex.html
File metadata and controls
63 lines (58 loc) · 1.75 KB
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
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<script src="js/socket-io.js"></script>
<script src="js/keys.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<title>G</title>
</head>
<body onunload="disconnect()">
<h1 id="title"></h1>
<canvas id="field" width="1000" height="1000" ></canvas>
<script>
var canvas = document.getElementById("field")
var ctx = canvas.getContext("2d")
var socket = io()
var id = "unknown"
var xy = [0,0]
socket.on("init", function(_id){
id = _id
})
socket.on('draw', function(things){
ctx.clearRect(0, 0, 1000, 1000)
for(var x in things){
if(x == id){
xy[0] = things[x].x
xy[1] = things[x].y
ctx.beginPath()
ctx.arc(500, 500, things[x].size, 0, 2*Math.PI)
ctx.fillStyle = things[x].color
ctx.fill()
ctx.stroke()
continue
}
if(things[x].x <= xy[0] + 500 && things[x].x >= xy[0] - 500 && things[x].y <= xy[1] + 500 && things[x].y >= xy[1] - 500){
//var _x = 500 - (xy[0] - things[x].x)
//var _y = 500 - (xy[1] - things[x].y)
ctx.beginPath()
ctx.arc(500 - (xy[0] - things[x].x), 500 - (xy[1] - things[x].y), things[x].size, 0, 2*Math.PI)
ctx.fillStyle = things[x].color
ctx.fill()
ctx.stroke()
}
}
})
//keys//////////////////////////////////////////////
document.addEventListener("keydown", keydown, false)
document.addEventListener("keyup", keyup, false)
document.addEventListener("keydown", function(){
socket.emit('keys', up, left, right)
}, false)
document.addEventListener("keyup", function(){
socket.emit('keys', up, left, right)
}, false)
////////////////////////////////////////////////////
</script>
</body>
</html>