-
Notifications
You must be signed in to change notification settings - Fork 0
/
TeeNE.pde
139 lines (124 loc) · 3.56 KB
/
TeeNE.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//float unit = 1; // length unit
boolean pause = false;
boolean debug = false;
Terrain terrain;
Tee tee1, tee2;
Tees tees;
Tournament tournament;
TableUtil tableUtil;
PFont FontSansSerif, FontConsolas, FontHNMI, FontMonoL;
void setup() {
pixelDensity(displayDensity());
size(770, 550, P2D);
// loadFont to display better quality (but not perfect) in P2D mode
FontSansSerif = loadFont("SansSerif-60.vlw");
FontConsolas = loadFont("Consolas-28.vlw");
// createFont to avoid loadFont large vlw font and ground disappearing bug when rendered
FontHNMI = createFont("HelveticaNeue-MediumItalic", 90);
FontMonoL = createFont("RobotoMonoNerdFontComplete-Medium", 84);
terrain = new Terrain();
tees = new Tees();
tournament = new Tournament();
tableUtil = new TableUtil(tournament);
}
void draw() {
//displayFrameRate();
tournament.update();
}
void displayFrameRate() {
textSize(12);
text(frameRate, 0, 20);
}
void keyPressed() {
teeControlKeymap(keyCode, true);
gameKeymap(key);
}
void keyReleased() {
teeControlKeymap(keyCode, false);
}
void teeControlKeymap(int k, boolean decision) {
Tee playerTee = tees.getHumanPlayer();
if (playerTee.brainControl) return;
if (k == LEFT) {
playerTee.pressLeft = decision;
playerTee.updateLastMoveFrame();
} else if (k == RIGHT) {
playerTee.pressRight = decision;
playerTee.updateLastMoveFrame();
} else if (k == 90) { // 'Z'
playerTee.pressJump = decision;
playerTee.updateLastMoveFrame();
} else if (k == 88) { // 'X'
playerTee.pressShoot = decision;
playerTee.updateLastMoveFrame();
}
}
void gameKeymap(char asciiKey) {
switch(asciiKey) {
case 'n': // Start next generation
if (tournament.roundEndCode == -2) {
tournament.nextGen();
}
break;
case 'v': // Fastforward training
if (tournament.roundEndCode != -2 && tournament.generation > 0) { // Only enabled in training
tournament.skip = !tournament.skip;
}
break;
case 's': // Fastforward one round
if (tournament.roundEndCode != -2) { // Enabled in training, free play and fight mode
tournament.skip = true;
tournament.skipOne = true;
}
break;
case 'g': // Nonstop evolution, only enabled in training
if (tournament.roundEndCode != -2 && tournament.generation > 0 && tournament.stage != 4) {
tournament.autoNextGen = !tournament.autoNextGen;
}
break;
case 'p': // Pause
if (pause) {
loop();
} else {
noLoop();
}
pause = !pause;
break;
case 'r': // Free play mode
if (tournament.roundEndCode == -2 && tournament.generation == 0) {
tournament.freePlayMode(true);
}
break;
case 'q': // Switch player in free play mode
if (tournament.roundEndCode == -1 && tournament.generation == 0) {
tees.getHumanPlayer().cancelPressStatus();
tees.switchPlayer();
}
break;
case 'b': // Back to menu from free play mode
if (tournament.roundEndCode == -1 && tournament.generation == 0) {
tournament.freePlayMode(false);
}
break;
case 'f': // Fight mode: human vs. AI
if (tournament.roundEndCode == -2 && tournament.generation > 0) {
tournament.fightMode();
}
break;
case 'e': // Save population
if (tournament.roundEndCode == -2 && tournament.generation > 0) {
tableUtil.saveData();
}
break;
case 'l': // Load population
if (tournament.roundEndCode == -2 && tournament.generation == 0) {
tableUtil.loadData();
}
break;
case 'd': // Toggle debug info
if (tournament.roundEndCode == -1) {
debug = !debug;
}
break;
}
}