-
Notifications
You must be signed in to change notification settings - Fork 0
/
LunarLander.pde
49 lines (38 loc) · 930 Bytes
/
LunarLander.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
//https://processing.org/reference/
//lines inntersecting formula
Population test = new Population(100);
PVector line = new PVector(0, 700);
boolean keys[] = new boolean[3];
void setup() {
size(1200, 800);
background(255);
frameRate(120);
smooth();
}
void draw() {
background(0);
if(test.allDotsDead()) {
//Genetic algorithm
test.calculateFitness();
test.naturalSelection();
test.mutate();
}
else {
test.update();
}
fill(255);
line(line.x, line.y, line.x + 1200, line.y);
/*(if(keys[0]) player.thrust();
if(keys[1]) player.turnLeft();
if(keys[2]) player.turnRight();*/
}
void keyPressed() {
if (keyCode == UP) keys[0] = true;
if (keyCode == LEFT) keys[1] = true;
if (keyCode == RIGHT) keys[2] = true;
}
void keyReleased() {
if (keyCode == UP) keys[0] = false;
if (keyCode == LEFT) keys[1] = false;
if (keyCode == RIGHT) keys[2] = false;
}