-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.pde
72 lines (61 loc) · 1.53 KB
/
scene.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
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
class Scene { //<>//
ArrayList<Entity> enemies = new ArrayList<Entity>();
Population population = new Population();
long steps = 0;
int level = 1;
void init() {
randomSeed(0);
population.init(50);
enemies.add(new Bird(width));
}
void update() {
if (population.isAlive()) {
ArrayList<Entity> survivedEnemies = new ArrayList<Entity>();
for (Entity enemy : enemies) {
enemy.update();
Vision.addEntity(enemy);
for (Player player : population.players) {
if (!player.killed && player.rect.intersect(enemy.rect)) {
player.killed = true;
}
}
if (enemy.rect.x >= 0) {
survivedEnemies.add(enemy);
}
}
population.update();
enemies = survivedEnemies;
checkLevel();
steps++;
}
else {
println("Max steps : ", steps);
reset();
}
}
void reset() {
Evolution evolution = new Evolution(population);
population = evolution.evolve();
enemies = new ArrayList<Entity>();
steps = 0;
}
void checkLevel() {
if (enemies.isEmpty()) {
for (int i=0; i<level; i++) {
int enemySelector = int(random(0, 2));
if (enemySelector == 1) {
enemies.add(new Bird(width + random(width/2)));
}
else {
enemies.add(new Bush(width + random(width/2)));
}
}
}
}
void display() {
for (Entity enemy : enemies) {
enemy.display();
}
population.display();
}
};