-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBubbles.js
110 lines (96 loc) · 2.56 KB
/
Bubbles.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
"use strict";
function Bubbles() {
this.bubbles = [];
this.namedBubbles = {};
}
Bubbles.prototype.draw = function (context) {
var i = null;
for (i = 0; i < this.bubbles.length; i += 1) {
this.bubbles[i].draw(context);
}
};
Bubbles.prototype.getFavd = function () {
return this.bubbles.filter(function (e) {
return e.getFav();
}).map(function (e) {
return e.getIndex();
});
};
Bubbles.prototype.getMastered = function () {
return this.bubbles.filter(function (e) {
return e.isMastered();
}).map(function (e) {
return e.getIndex();
});
};
Bubbles.prototype.setMastereds = function (list) {
var i, bubble;
for (i = 0; i < list.length; i += 1) {
bubble = this.namedBubbles[list[i]];
if (bubble !== undefined) {
bubble.flipMaster();
}
}
};
Bubbles.prototype.getNamed = function (name) {
return this.namedBubbles[name];
};
Bubbles.prototype.add = function (name, bubble) {
this.bubbles.push(bubble);
this.namedBubbles[name] = bubble;
};
Bubbles.prototype.getBubble = function (index) {
return this.bubbles[index];
};
Bubbles.prototype.length = function () {
return this.bubbles.length;
};
Bubbles.prototype.collide = function (pos) {
var i = null;
for (i = 0; i < this.length(); i += 1) {
if (this.getBubble(i).hitTest(pos)) {
return this.bubbles[i];
}
}
};
Bubbles.prototype.genUniqId = function () {
var randNum, i;
for (i = 0; i < 1000; i += 1) {
randNum = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
if (this.namedBubbles[randNum] === undefined) {
return randNum;
}
}
while (this.namedBubbles[i] !== undefined) {
i += 1;
}
return i;
};
Bubbles.prototype.hover = function (mousePos, sounds) {
var i = null;
for (i = 0; i < this.length(); i += 1) {
if (this.getBubble(i).hitTest(mousePos)) {
if (this.getBubble(i).getHL() === false) {
this.getBubble(i).setHighlighting(true);
sounds.hover();
}
} else {
this.getBubble(i).setHighlighting(false);
}
}
};
Bubbles.prototype.click = function (mousePos) {
var i = null;
for (i = 0; i < this.length(); i += 1) {
if (this.getBubble(i).hitTest(mousePos)) {
return {
hit: true,
facts: this.getBubble(i).getNameAndFacts(),
bubble: this.getBubble(i)
};
}
}
return {
hit: false
};
};