-
Notifications
You must be signed in to change notification settings - Fork 0
/
qwerty3.js
181 lines (157 loc) · 4.93 KB
/
qwerty3.js
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
let button1 = document.querySelector(".button-1")
let button2 = document.querySelector(".button-2")
let button3 = document.querySelector(".button-3")
let leftButton = document.querySelector(".left-button")
let upButton = document.querySelector(".up-button")
let downButton = document.querySelector(".down-button")
let rightButton = document.querySelector(".right-button")
let message = document.querySelector(".message")
let button = document.querySelector("button")
let red_square = document.querySelector(".red_square")
let blue_square = document.querySelector(".blue_square")
let green_square = document.querySelector(".green_square")
let that_choose_thing = document.querySelector(".that_choose_thing")
function set_position(x, y, element){
element.style.left = x
element.style.top = y
}
function send_position(element){
let elementName
if (element == red_square){
elementName = "red_square"
}else if(element == blue_square){
elementName = "blue_square"
}else if(element == green_square){
elementName = "green_square"
}
holler.appInstance.notifyClients(JSON.stringify({
Y: parseInt(element.style.top),
X: parseInt(element.style.left),
EString: elementName
}))
}
function teleport(x, y, element){
element.style.left = x
element.style.top = y
send_position(element)
}
function move_position(x, y, element){
element.style.left = parseInt(element.style.left) + x
element.style.top = parseInt(element.style.top) + y
send_position(element)
}
function choose_and_controll_square(used_button, color_message, square){
used_button.onclick = function(){
message.textContent = color_message
console.log(message.textContent)
button1.remove()
button2.remove()
button3.remove()
that_choose_thing.textContent =""
leftButton.textContent = "left"
upButton.textContent = "up"
downButton.textContent = "down"
rightButton.textContent = "right"
let mouseState = ("up")
let squareVelocity = (x, y)=>{
move_position(x, y, square)
if (mouseState == "down"){
setTimeout(()=>{squareVelocity(x, y)}, 100)
}
}
leftButton.onmousedown = ()=>{
mouseState = "down"
squareVelocity(-10, 0)
}
upButton.onmousedown = ()=>{
mouseState = "down"
squareVelocity(0, -10)
}
downButton.onmousedown = ()=>{
mouseState = "down"
squareVelocity(0, 10)
}
rightButton.onmousedown = ()=>{
mouseState = "down"
squareVelocity(10, 0)
}
leftButton.onmouseup = ()=>{
mouseState = "up"
squareVelocity(0, 0)
}
upButton.onmouseup = ()=>{
mouseState = "up"
squareVelocity(0, 0)
}
downButton.onmouseup = ()=>{
mouseState = "up"
squareVelocity(0, 0)
}
rightButton.onmouseup = ()=>{
mouseState = "up"
squareVelocity(0, 0)
}
document.onkeydown = function(event){
switch(event.key){
case "t" :
teleport(100, 100, square)
break
case "w" :
move_position(0, -10, square)
break
case "a" :
move_position(-10, 0, square)
break
case "s" :
move_position(0, 10, square)
break
case "d" :
move_position(10, 0, square)
break
case "x" :
move_position(10, 10, square)
break
case "e" :
move_position(10, -10, square)
break
case "z" :
move_position(-10, 10, square)
break
case "q" :
move_position(-10, -10, square)
break
case "l" :
teleport(1, 1, square)
break
case "1" :
teleport(400, 300, square)
break
case "2" :
teleport(400, 440, square)
break
case "3" :
teleport(400, 580, square)
break
}
}
}
}
holler.onLoad(()=>{
holler.me((user)=>{
choose_and_controll_square(button1, "you are red", red_square)
choose_and_controll_square(button2, "you are blue", blue_square)
choose_and_controll_square(button3, "you are green", green_square)
})
holler.onClientEvent(event=>{
console.log(event)
console.log(JSON.parse(event))
let incomingData = JSON.parse(event)
if(incomingData.EString == "red_square"){
set_position(incomingData.X, incomingData.Y, red_square)
}else if(incomingData.EString == "blue_square"){
set_position(incomingData.X, incomingData.Y, blue_square)
}else if(incomingData.EString == "green_square"){
set_position(incomingData.X, incomingData.Y, green_square)
}
})
})