-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tetris.pde
50 lines (45 loc) · 1.24 KB
/
Tetris.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
Population pop;
int popsize = 100;
boolean PAUSED = false;
void setup() {
size(1000, 1200); //size of the window (processing makes width smaller) + space on right for scoring
frameRate(50);//increase this to make the blocks go faster
pop = new Population(popsize);
textSize(24);
}
void draw() {
background(0);
if (!pop.allGamesDone) {
if (!PAUSED) pop.update();
pop.show();
} else {
pop = pop.geneticAlgo();
}
}
void keyPressed() {
if (key == CODED) {
// manual gameplay
switch (keyCode) {
case (LEFT): pop.currGame.moveFallingPiece(0, -1); break;
case (RIGHT): pop.currGame.moveFallingPiece(0, 1); break;
case (DOWN): {
//HARD DROP
while (pop.currGame.moveFallingPiece(1, 0)) { //move down til it can't
continue; //moveFallingPiece is already called
}
pop.currGame.placeFallingPiece();
pop.currGame.newFallingPiece();
if (!pop.currGame.fallingPieceIsLegal()) {
pop.currGame.gameOver = true;
}
break;
}
case (UP): pop.currGame.rotateFallingPiece(true); break;
}
} else {
switch (key) {
case (' '): PAUSED = !PAUSED; break;
case ('r'): pop = new Population(popsize); break;
}
}
}