-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsword.html
More file actions
66 lines (59 loc) · 1.94 KB
/
Copy pathsword.html
File metadata and controls
66 lines (59 loc) · 1.94 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
64
65
66
<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()">
<canvas id="field" width="2000" height="1000" ></canvas>
<h1 id="title">pew pew</h1>
<script>
var canvas = document.getElementById("field")
var ctx = canvas.getContext("2d")
var socket = io()
var id = "unknown"
var xy = [0,0]
var height = 1000
width = 2000
socket.on("init", function(_id){ id = _id })
socket.on('draw', function(things){
ctx.clearRect(0, 0, width, height)
for(var x in things){
if(x == id){
xy[0] = things[x].x
xy[1] = things[x].y
ctx.beginPath()
ctx.arc(width/2, height/2, things[x].size, 0, 2*Math.PI)
ctx.fillStyle = things[x].color
ctx.fill()
ctx.stroke()
continue
}
if(things[x].x - things[x].size <= xy[0] + width/2 && things[x].x + things[x].size >= xy[0] - width/2 && things[x].y - things[x].size <= xy[1] + height/2 && things[x].y + things[x].size >= xy[1] - height/2){
ctx.beginPath()
ctx.arc(width/2 - (xy[0] - things[x].x), height/2 - (xy[1] - things[x].y), things[x].size, 0, 2*Math.PI)
ctx.fillStyle = things[x].color
ctx.fill()
ctx.stroke()
}
}
})
socket.on('action_change', function(name){
document.getElementById('title').innerHTML = name
})
//keys//////////////////////////////////////////////
document.addEventListener("keydown", keydown, false)
document.addEventListener("keyup", keyup, false)
document.addEventListener("keydown", function(){
socket.emit('keys', up, left, right, down, a, s)
}, false)
document.addEventListener("keyup", function(){
socket.emit('keys', up, left, right, down, a, s)
}, false)
////////////////////////////////////////////////////
</script>
</body>
</html>