-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmartArt.js
54 lines (44 loc) · 1.38 KB
/
SmartArt.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
class SmartArt {
constructor(art, x, y, mode, translateXOffset, translateYOffset, sound, playTime) {
this.art = art;
this.mode = mode;
this.x = x;
this.y = y;
if (validParameter(translateXOffset)) {
this.translateXOffset = translateXOffset;
this.translateYOffset = translateYOffset;
}
if (validParameter(sound)) {
this.sound = sound;
this.playTime = playTime;
}
}
draw() {
push();
if (validParameter(this.translateXOffset)) {
translate(cameraX*this.translateXOffset, cameraY*this.translateYOffset, 0);
}
if (this.mode == ANIMATION) {
this.drawAnimation();
} else {
this.drawImage();
}
pop();
if (validParameter(this.sound)) {
let distanceFactor = GAME_WIDTH;
let playerDistance = dist(player.x, player.y, this.x, this.y);
if ( playerDistance < distanceFactor) {
this.sound.setVolume(1-constrain(playerDistance/distanceFactor, 0, 1));
if (frameCount % this.playTime == 0) {
this.sound.play();
}
}
}
}
drawAnimation() {
this.art.draw(this.x, this.y);
}
drawImage() {
image(this.art, this.x, this.y);
}
}