-
Notifications
You must be signed in to change notification settings - Fork 0
/
moveBall_bonus.html
206 lines (168 loc) · 3.87 KB
/
moveBall_bonus.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
<div id="ball" style="
z-index:5;
position:absolute;
left:0px;
top:0px;
width:50px;
height:50px;
border-radius:50%;
background:green">
</div>
<div id="ball2" style="
z-index:10;
position:absolute;
left:0px;
top:0px;
width:25px;
height:25px;
border-radius:50%;
background:rgb(189, 7, 16)">
</div>
<div id="ball3" style="
z-index:10;
position:absolute;
left:0px;
top:0px;
width:25px;
height:25px;
border-radius:50%;
background:rgb(8, 180, 223)">
</div>
<div id="ball4" style="
z-index:3;
position:absolute;
left:0px;
top:0px;
width:100px;
height:100px;
border-radius:50%;
background:rgb(123, 29, 211)">
</div>
<script>
var velocityX = 5;
var velocityY = 3;
var positionX = 0;
var positionY = 0;
var ball = document.getElementById('ball');
var ball2 = document.getElementById('ball2');
var ball3 = document.getElementById('ball3');
var ball4 = document.getElementById('ball4');
var reverse = false;
var Xmin = 0;
var Xmax = 400;
var Ymin = 0;
var Ymax = 400;
// Ball
// ----------------
function moveBall(){
positionX = positionX + velocityX;
ball.style.left = positionX + 'px';
positionY = positionY + velocityY;
ball.style.top = positionY + 'px';
if(positionX > Xmax){
velocityX = -velocityX;
ball.style.background = 'grey';
}
if(positionX === Xmin){
velocityX = -velocityX;
ball.style.background = 'green';
}
if(positionY > Ymax){
velocityY = -velocityY;
ball.style.background = 'red';
}
if(positionY === Ymin){
velocityY = -velocityY
ball.style.background = 'blue';
}
}
setInterval(moveBall, 50);
// Ball 2
// ----------------
var velocityX2 = 10;
var velocityY2 = 1;
var positionX2 = 0;
var positionY2 = 100;
function moveBall2(){
positionX2 = positionX2 + velocityX2;
ball2.style.left = positionX2 + 'px';
positionY2 = positionY2 + velocityY2;
ball2.style.top = positionY2 + 'px';
if(positionX2 > Xmax){
velocityX2 = -velocityX2;
ball2.style.background = '#A5E1AD';
}
if(positionX2 === Xmin){
velocityX2 = -velocityX2;
ball2.style.background = '#511281';
}
if(positionY2 > Ymax){
velocityY2 = -velocityY2;
ball2.style.background = '#4CA1A3';
}
if(positionY2 === Ymin){
velocityY2 = -velocityY2;
ball2.style.background = '#A5E1AD';
}
}
setInterval(moveBall2, 50);
// Ball 3
// ----------------
var velocityX3 = 4;
var velocityY3 = 7;
var positionX3 = 0;
var positionY3 = 200;
function moveBall3(){
positionX3 = positionX3 + velocityX3;
ball3.style.left = positionX3 + 'px';
positionY3 = positionY3 + velocityY3;
ball3.style.top = positionY3 + 'px';
if(positionX3 > Xmax){
velocityX3 = -velocityX3;
ball3.style.background = '#053742';
}
if(positionX3 === Xmin){
velocityX3 = -velocityX3;
ball3.style.background = '#39A2DB';
}
if(positionY3 > Ymax){
velocityY3 = -velocityY3;
ball3.style.background = "#A2DBFA";
}
if(positionY3 <= Ymin){
velocityY3 = -velocityY3;
ball3.style.background = "#E8F0F2";
}
}
setInterval(moveBall3, 50);
setInterval(moveBall2, 50);
// Ball 4
// ----------------
var velocityX4 = 7;
var velocityY4 = 10;
var positionX4 = 0;
var positionY4 = 300;
function moveBall4(){
positionX4 = positionX4 + velocityX4;
ball4.style.left = positionX4 + 'px';
positionY4 = positionY4 + velocityY4;
ball4.style.top = positionY4 + 'px';
if(positionX4 > Xmax){
velocityX4 = -velocityX4;
ball4.style.background = '#52006A';
}
if(positionX4 === Xmin){
velocityX4 = -velocityX4;
ball4.style.background = '#CD113B';
}
if(positionY4 > Ymax){
velocityY4 = -velocityY4;
ball4.style.background = '#FF7600';
}
if(positionY4 <= Ymin){
velocityY4 = -velocityY4;
ball4.style.background = '#FFA900';
}
}
setInterval(moveBall4, 50);
</script>