-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntities.pde
More file actions
103 lines (84 loc) · 2.41 KB
/
Copy pathEntities.pde
File metadata and controls
103 lines (84 loc) · 2.41 KB
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
class Entities{
ArrayList <Food> foods;
int foodWidth = 10;
ArrayList <MakeBird> birds;
int [] y;
int numberOfBirds;
AudioContext ac;
UGen microphoneIn;
float volumeLimit;
Entities(){
audio = false;
volumeLimit = 0.07;
numberOfBirds = 15;
y = new int[numberOfBirds];
for (int i = 0; i < numberOfBirds; ++i) {
y[i] = (int)random(300, 640);
}
y = sort(y);
birds = new ArrayList<MakeBird>();
for (int i = 0; i < numberOfBirds; ++i) {
birds.add(new MakeBird(y[i]));
}
ac = new AudioContext();
microphoneIn = ac.getAudioInput();
Gain g = new Gain(ac, 1, 0);
g.addInput(microphoneIn);
ac.out.addInput(g);
ac.start();
foods = new ArrayList<Food>();
}
//Draw entities
void drawEntities(){
microphoneIn.update();
checkAudio();
try {
for (int j = foods.size()-1; j >= 0; j--) {
Food food = foods.get(j);
food.display();
food.move();
// food.birdMove();
if (food.finished()) {
foods.remove(j);
}
}
} catch (Exception e) {
println("foods.size is null");
}
for (int i = 0; i < numberOfBirds; ++i) {
birds.get(i).use();
for(int k = 0; k< foods.size(); k++){
birds.get(i).checkFoodPosition(foods.get(k).getFoodXPosition(),foods.get(k).getFoodYPosition(), foods.get(k).getFoodLife());
}
}
}
void addEntity(){
foods.add(new Food(mouseX, mouseY, foodWidth));
}
void checkAudio() {
if (microphoneIn.getOutBuffer(0)[0] > volumeLimit) {
audio = true;
}
}
void setVolumeLimit(float volume){
volumeLimit = volumeLimit + volume;
}
//MakeBird has a bird within its class. make a method that allows entities to read those birds and pass relevant
//information to food within this class.`
//Check if the point p is anywhere within a circle with point c and radius r.
boolean isOverCircle(float px, float py, float cx, float cy, float r) {
float distX = px - cx;
float distY = py - cy;
float distance = sqrt( (distX*distX) + (distY*distY) );
if (distance <= r) {
return true;
}
return false;
}
//Return distance between point 1 and point 2
float distanceBetweenPoints(float x1, float y1, float x2, float y2){
float distX = x1 - x2;
float distY = y1 - y2;
return sqrt( (distX*distX) + (distY*distY) );
}
}