-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitems.js
214 lines (181 loc) · 4.47 KB
/
items.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
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
//0: short paddle, 1: long paddle, 2: increase speed, 3: reverse dir, 4: blind, 5: upsidedown
var itemImg = ["img/minus.png","https://img.icons8.com/cotton/64/000000/plus--v1.png","img/speedup.png", "img/skeleton.png", "img/torch.png", "img/upsidedown.png"];
//Item 0
function shortPaddle(minLen) {
console.log("shortPaddle");
addScore(50);
if(minLen <= mp.with*0){
return;
}
var beforePWidth = mp.width;
var id = setInterval(frame, 5);
function frame() {
if (mp.width <= minLen) {
clearInterval(id);
} else {
mp.width--;
updateDOMFromGO(mp);
}
}
return beforePWidth;
}
//Item 1
function longPaddle(maxLen) {
console.log("longPaddle");
if(maxLen >= mp.with*2){
return;
}
var beforePWidth = mp.width;
var id = setInterval(frame, 5);
function frame() {
if (mp.width >= maxLen) {
clearInterval(id);
} else {
mp.width++;
updateDOMFromGO(mp);
}
}
return beforePWidth;
}
//Item 2
function increaseSpeed() {
console.log("increaseSpeed");
addScore(50);
if(!itemSet[2]){
itemSet[2] = true;
var beforeBallSpeed = ballSpeed;
ballSpeed = ballSpeed*2;
setTimeout(function(){ ballSpeed = beforeBallSpeed; itemSet[2] = false; }, itemLastSec);
}
}
//Item 3
function reverseDir() {
console.log("reverseDir");
addScore(70);
if(!itemSet[3]){
itemSet[3] = true;
setTimeout(function(){ itemSet[3] = false; }, 6000);
}
}
//Item 4
function blind() {
addScore(150);
if(!itemSet[4]){
itemSet[4] = true;
setTimeout(function(){
itemSet[4] = false;
document.getElementsByTagName("html")[0].id = ""; //remove the blind mode
}, 6000);
}
}
function updateLight(e) {
//var x = e.clientX || e.touches[0].clientX; //when the reverseDir work->it couldn't be work
var y = e.clientY || e.touches[0].clientY;
document.getElementsByTagName("html")[0].id = "light"; //question?
document.documentElement.style.setProperty('--cusorX', mouseCorX + 'px');
document.documentElement.style.setProperty('--cusorY', y + 'px');
}
//Item 5
function upsidedown() {
addScore(100);
if(!itemSet[5]){
itemSet[5] = true;
//move brick
var ogBrickYs;
ogBrickYs = new Array(brickRow);
for (var i = 0; i < ogBrickYs.length; i++) {
ogBrickYs[i] = new Array(brickCol);
}
for(var i=0;i<brickCol;i++){
for(var j=0;j<brickRow;j++){
ogBrickYs[j][i] = bricks[j][i].y;
bricks[j][i].y *= -1;
bricks[j][i].y += playArea.height - bricks[j][i].height;
updateDOMFromGO(bricks[j][i]);
}
}
//move paddle
var ogPaddleY = mp.y;
mp.y *= -1;
mp.y += playArea.height - mp.height;
updateDOMFromGO(mp);
setTimeout(function(){
for(var i=0;i<brickCol;i++){
for(var j=0;j<brickRow;j++){
bricks[j][i].y = ogBrickYs[j][i];
updateDOMFromGO(bricks[j][i]);
}
}
mp.y = ogPaddleY;
updateDOMFromGO(mp);
itemSet[5] = false;
}, itemLastSec);
}
}
function itemDrop(go) {
// var exitItem = Math.random();
// if(exitItem > itemRate){ //No Item
// return;
// }
var index = -1;
for (var i = 0; i < iMaxNum; i++) {
if(currentItems[i] == undefined){
index = i;
break;
}
}
if(index == -1) return; //currentItems is full
var item = {};
item.dom = document.createElement("div");
item.dom.classList.add("item");
item.width = itemSize;
item.height = itemSize;
item.x = go.x + go.width/2 - item.width/2;
item.y = go.y + go.height;
item.num = Math.floor(Math.random() * itemCount);
item.dom.style.backgroundImage = "url('"+itemImg[item.num]+"')";
playArea.dom.appendChild(item.dom);
currentItems[index] = item;
updateDOMFromGO(item);
var id = setInterval(frame, 5);
function frame() {
if (playArea.height < item.y) {
item.dom.style.display = "none";
clearInterval(id);
} else {
//upsidedown
if(itemSet[5]){
item.y--;
}else{
item.y++;
}
updateDOMFromGO(item);
}
}
}
function eatItem(citem) {
citem.dom.style.display = "none";
// citem.num=4;
switch(citem.num){
case 0:
var beforePWidth = shortPaddle(mp.width*0.5);
setTimeout(function(){ longPaddle(beforePWidth); }, itemLastSec);
break;
case 1:
var beforePWidth = longPaddle(mp.width*1.5);
setTimeout(function(){ shortPaddle(beforePWidth); }, itemLastSec);
break;
case 2:
increaseSpeed();
break;
case 3:
reverseDir();
break;
case 4:
blind();
break;
case 5:
upsidedown();
break;
}
}