-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
211 lines (192 loc) · 6.46 KB
/
Copy pathindex.html
File metadata and controls
211 lines (192 loc) · 6.46 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<html>
<head>
<meta charset="utf-8">
<title>Hello Square</title>
<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>
</head>
<body onunload="disconnect()">
<h1 id="title"></h1>
<h1 id="test"></h1>
<canvas id="field" width="1000" height="1000" ></canvas>
<div id="infobox">
<p>press 'h' for help</p>
</div>
<div id="divbutton1">
<button type="button" id="m1" class="butt">
left click
</button>
<select name="actions" id='_m1' class='buttt'>
<option value="axe">axe</option>
<option value="beam">beam</option>
<option value="bounce">bounce</option>
<option value="explode">explode</option>
<option value="freeze">freeze</option>
<option value="gatling">gatling</option>
<option value="hulk">hulk</option>
<option value="invisible">invisible</option>
<option value="kamehameha">kamehameha</option>
<option value="lazer">lazer</option>
<option value="lion">lion</option>
<option value="mine">mine</option>
<option value="nuke">nuke</option>
<option value="portal">portal</option>
<option value="rock">rock</option>
<option value="shield">shield</option>
<option value="shoot" selected="selected">shoot</option>
<option value="sprint">sprint</option>
<option value="sword">sword</option>
<option value="zombie">zombie</option>
</select>
</div>
<div id="divbutton2">
<button type="button" id="m2" class="butt">
right click
</button>
<select name="actions" id='_m2' class="buttt">
<option value="axe">axe</option>
<option value="beam">beam</option>
<option value="bounce">bounce</option>
<option value="explode">explode</option>
<option value="freeze">freeze</option>
<option value="gatling">gatling</option>
<option value="hulk">hulk</option>
<option value="invisible">invisible</option>
<option value="kamehameha">kamehameha</option>
<option value="lazer">lazer</option>
<option value="lion">lion</option>
<option value="mine">mine</option>
<option value="nuke">nuke</option>
<option value="portal">portal</option>
<option value="rock">rock</option>
<option value="shield">shield</option>
<option value="shoot">shoot</option>
<option value="sprint">sprint</option>
<option value="sword" selected="selected">sword</option>
<option value="zombie">zombie</option>
</select>
</div>
<div id="divbutton3">
<button type="button" id="space" class="butt">
space
</button>
<select name="actions" id='_space' class="buttt">
<option value="axe">axe</option>
<option value="beam">beam</option>
<option value="bounce">bounce</option>
<option value="explode">explode</option>
<option value="freeze">freeze</option>
<option value="gatling">gatling</option>
<option value="hulk">hulk</option>
<option value="invisible">invisible</option>
<option value="kamehameha">kamehameha</option>
<option value="lazer">lazer</option>
<option value="lion">lion</option>
<option value="mine">mine</option>
<option value="nuke">nuke</option>
<option value="portal">portal</option>
<option value="rock">rock</option>
<option value="shield">shield</option>
<option value="shoot">shoot</option>
<option value="sprint" selected="selected">sprint</option>
<option value="sword">sword</option>
<option value="zombie">zombie</option>
</select>
</div>
<script>
//document.body.style.zoom="50%"
var canvas = document.getElementById("field")
var ctx = canvas.getContext("2d")
var person = {}
var id
var things = {}
var socket = io()
socket.on('init', function(person){
person = person
id = person.id
})
socket.on('draw', function(things){ //things = _things })
//function draw(){
//setTimeout(function(){
//requestAnimationFrame(draw)
ctx.clearRect(0, 0, 1000, 1000)
for(var x in things){
size = things[x].size
_size = things[x].size/2
ctx.fillStyle = things[x].color
ctx.fillRect(things[x].x - _size,things[x].y - _size,size,size)
if(things[x].isperson){
__size = _size/2
if(x == id){
ctx.beginPath()
ctx.rect(things[x].x - __size - 5, things[x].y - __size - 5, things[x].size + 5, things[x].size + 5)
ctx.stroke()
ctx.closePath()
}
if(things[x].invisible){
console.log('test')
continue }
if(things[x].energy > 6){
ctx.fillStyle="#00FF00"
ctx.fillRect(things[x].x - __size,things[x].y - __size,_size,_size)
continue
}
if(things[x].energy > 3){
ctx.fillStyle="#FFFF00"
ctx.fillRect(things[x].x - __size,things[x].y - __size,_size,_size)
continue
}
if(things[x].energy > 0){
ctx.fillStyle="#FF0000"
ctx.fillRect(things[x].x - __size,things[x].y - __size,_size,_size)
continue
}
}
}
//}, 1000/60)
})
//draw()
//keys
document.addEventListener("keydown", keydown, false)
document.addEventListener("keyup", keyup, false)
document.addEventListener("keydown", function(){
socket.emit('keys', up, down, left, right)
}, false)
document.addEventListener("keyup", function(){
socket.emit('keys', up, down, left, right)
}, false)
//mouse
var mx = 0
var my = 0
document.addEventListener('contextmenu', function(c) { c.preventDefault() }, false)
canvas.addEventListener("mousedown", function(c){
coord = [(c.clientX - canvas.offsetLeft), (c.clientY - canvas.offsetTop)]
if(c.which == 1){ socket.emit('action', 'left', coord)}
if(c.which == 3){ socket.emit('action', 'right', coord)}
}, false)
canvas.addEventListener('mousemove',function(c){
mx = (c.clientX - canvas.offsetLeft)
my = (c.clientY - canvas.offsetTop)
//socket.emit('mouse', mx, my)
},false)
//buttons
var m1butt = document.getElementById('m1')
var _m1butt = document.getElementById('_m1')
m1butt.onclick = function(){
socket.emit('change',_m1butt.options[_m1butt.selectedIndex].value,'left')
}
var m2butt = document.getElementById('m2')
var _m2butt = document.getElementById('_m2')
m2butt.onclick = function(){
socket.emit('change',_m2butt.options[_m2butt.selectedIndex].value,'right')
}
var space = document.getElementById('space')
var _space = document.getElementById('_space')
space.onclick = function(){
socket.emit('change',_space.options[_space.selectedIndex].value,'space')
}
</script>
</body>
</html>