-
Notifications
You must be signed in to change notification settings - Fork 1
/
orangeBall.js
72 lines (63 loc) · 1.91 KB
/
orangeBall.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
import * as Tone from 'https://cdn.skypack.dev/[email protected]';
import Ball from './ball.js';
class OrangeBall extends Ball {
constructor(x, y, vx, vy, pool) {
const color = 'orange';
super(x, y, vx, vy, color, pool)
this.core = new Tone.PolySynth().toMaster();
this.patch = {
frequency: "G4",
detune: 10,
oscillator: {
type: "triangle"
},
filter: {
Q: 2,
type: "lowpass",
rolloff: -24
},
envelope: {
attack: 0.8,
decay: 0.1,
release: 1.2
},
filterEnvelope: {
attack: 0.6,
decay: 0.1,
release: 1.2,
baseFrequency: 400,
octaves: 2
}
}
this.core.set(this.patch);
}
playCollisonSound() {
// Logic to play collision sound based on information in BlueBall class
console.log('Playing collision sound for Orange Ball');
if(this.vibrato_check){
this.core.connect(this.vibrato);
}
else{
this.core = new Tone.PolySynth().toMaster();
this.core.set(this.patch);
}
// ...
this.core.triggerAttackRelease(["C5", "E5"], "12n");
}
checkCollisionWithBalls() {
this.pool.forEach(ball => {
if (ball !== this && this.isCollidingWith(ball)) {
// Perform collision handling logic here
// console.log('rewrote!');
this.bounce(ball);
this.playCollisonSound();
}
});
}
set_filter(slidervalue, filtertype){
this.patch.filter.frequency = slidervalue;
this.patch.filter.type = filtertype;
this.core.set(this.patch);
}
}
export default OrangeBall;