-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBird.pde
39 lines (35 loc) · 841 Bytes
/
Bird.pde
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
class Bird extends Agent
{
float posx, posy, speed;
void fall() {posy+=speed; speed+=0.4;}
void flap() {speed = -8;}
void display() {if(alive) ellipse(posx,posy,50,50);}
Bird(int[] NNStruct)
{
super(NNStruct);
reset();
}
@Override
float[] getInput()
{
return new float[] {
pillars.pillarList.get(0).posx - posx, //Distance to the next pillar
speed, //Bird velocity
height - pillars.pillarList.get(0).h - posy, //Distance to the bottom pillar
height - pillars.pillarList.get(0).h - pillars.pillarList.get(0).a - posy
};
}
@Override
void Do()
{
float[] output = think();
if (output[0] > output[1]) flap();
}
@Override
void reset()
{
speed = 0;
posx = width/5.0;
posy = height/4.0;
}
}