-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
236 lines (213 loc) · 5.47 KB
/
index.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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<html>
<meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0" />
<head>
<title>Buttons</title>
<style>
.joystick {
border-radius: 15px;
display: inline-block;
height: 300px;
position: relative;
width: 250px;
}
.joystick:before {
border-radius: 50%;
box-shadow:
-105px -105px 50px 10px rgba(10, 10, 10, 1),
-95px -95px 0 50px rgba(20, 20, 20, 1),
-96px -96px 0 52px rgba(0, 0, 0, 1),
-95px -95px 0 70px rgba(30, 30, 30, 1),
-96px -96px 0 72px rgba(0, 0, 0, 1);
content: '';
display: block;
height: 50px;
left: 220px;
position: absolute;
top: 220px;
width: 50px;
}
.joystick.pressed:before {
-105px -105px 50px 10px rgba(10, 10, 10, .65),
-95px -95px 0 71px rgba(255, 255, 255, .07),
-95px -95px 0 50px rgba(20, 20, 20, .3),
-96px -96px 0 52px rgba(0, 0, 0, .4),
-95px -95px 0 70px rgba(30, 30, 30, .2),
-96px -96px 0 72px rgba(0, 0, 0, .4);
}
.joystick:after {
background: radial-gradient(ellipse at 32px 28px, rgb(255, 255, 255) 10%, rgb(55, 225, 55) 11%, rgb(0, 200, 0) 100%);
border-radius: 50%;
box-shadow: inset 3px 5px 25px rgba(9, 255, 0, .5),
inset 3px 5px 35px rgba(205, 255, 205, .75),
inset 0 0 5px rgba(205, 255, 205, .75),
inset -10px -15px 45px rgba(0, 0, 0, .25),
15px 30px 15px 0 rgba(0, 0, 0, .75);
content: '';
display: block;
height: 80px;
left: 110px;
position: absolute;
top: 110px;
transition: all .05s linear;
width: 80px;
}
.joystick.up:after {
top: 75px;
}
.joystick.down:after {
top: 145px;
}
.joystick.left:after {
left: 75px;
}
.joystick.right:after {
left: 145px;
}
.joystick.up.left:after {
left: 85px;
top: 85px;
}
.joystick.up.right:after {
left: 135px;
top: 85px;
}
.joystick.down.left:after {
left: 85px;
top: 135px;
}
.joystick.down.right:after {
left: 135px;
top: 135px;
}
.button {
border-radius: 15px;
display: inline-block;
height: 300px;
position: relative;
width: 60px;
}
.button:before {
background: radial-gradient(rgb(0, 175, 0), rgb(0, 200, 0));
border-radius: 50%;
box-shadow: inset -10px -15px 45px rgba(255, 255, 255, .25),
inset 0 0 0 2px rgb(55, 250, 55),
inset 2px 3px 0 0 rgb(255, 255, 255),
inset -2px -3px 0 0 rgb(255, 255, 255),
0 0 0 5px rgb(0, 150, 0),
-1px -1px 0 5px rgb(0, 255, 0);
content: '';
display: block;
height: 50px;
left: 15px;
position: absolute;
top: 65px;
width: 50px;
}
.button.pressed:before {
background: rgb(255, 255, 0);
box-shadow: inset -10px -15px 45px rgba(185, 255, 185, .25),
inset 1px 1px 4px 1px rgba(0, 0, 0, .85),
0 0 0 5px rgb(0, 150, 0),
inset -1px -1px 0 0 rgba(100, 250, 100, .75),
-1px -1px 0 5px rgb(0, 225, 0);
}
.button:after {
content: '';
display: block;
height: 80px;
position: absolute;
transition: all .02s linear;
width: 80px;
}
</style>
</head>
<body bgcolor="green">
<div class="joystick" id="joystick"></div>
<div class="button" style="top:30px;left:5px;" id="button1"></div>
<div class="button" id="button2"></div>
<div class="button" style="top:5px;" id="button3"></div>
<div class="button" style="left:-200px;top:100px;" id="button4"></div>
<script src="/socket.io/socket.io.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@mojs/core"></script>
<script>
var socket = io();
var joystickPosition = {};
var joystick = document.getElementById('joystick');
var button1 = document.getElementById('button1');
var button2 = document.getElementById('button2');
var button3 = document.getElementById('button3');
var button4 = document.getElementById('button4');
var clickHandler = function(val) {
socket.emit('clicked', {button: val});
};
var updateJoystick = function(switchName, val) {
if (val == "down") {
joystickPosition[switchName] = true;
} else {
joystickPosition[switchName] = false;
}
var classNames = ['joystick'];
Object.keys(joystickPosition).forEach(function (key) {
if (joystickPosition[key]) classNames.push(key);
});
joystick.className = classNames.join(' ');
}
var updateButton = function(button, val) {
if (val == "down") {
button.className = "button pressed"
pressEffect = new mojs.Shape({
parent: button,
shape: 'circle',
radius: 30,
isShowStart: false,
fill: 'transparent',
stroke: '#FFFF00',
strokeWidth: 5,
duration: 100,
y: -60,
x: 10
}).then({
strokeWidth: 20,
scale: { to: 2, easing: 'sin.in' },
}).then ({
strokeWidth: 0
});
pressEffect.play();
} else {
button.className = "button"
}
}
socket.on('right', function(data) {
updateJoystick("right", data.v);
});
socket.on('left', function(data) {
updateJoystick("left", data.v);
});
socket.on('up', function(data) {
updateJoystick("up", data.v);
});
socket.on('down', function(data) {
updateJoystick("down", data.v);
});
socket.on('b1', function(data) {
updateButton(button1, data.v);
});
socket.on('b2', function(data) {
updateButton(button2, data.v);
});
socket.on('b3', function(data) {
updateButton(button3, data.v);
});
socket.on('b4', function(data) {
updateButton(button4, data.v);
});
document.addEventListener("keydown", keyDownTextField, false);
function keyDownTextField(e) {
var keyCode = e.keyCode;
// If the user hits space, hit b2
if(keyCode==32) {
clickHandler('b2');
}
}
</script>
</html>