-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNature_Park.pde
200 lines (177 loc) · 4.46 KB
/
Nature_Park.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import g4p_controls.*;
import java.util.Observer;
//import processing.sound.*;
public static final String VERSION = "0.8.1";
Config config;
// Declare constants
public static final int TILESIZE = 10;
// The actual width of the game on a phone
// to allow scaling up proportionately
public static final int INTROWIDTH = 128;
public static final int INTROHEIGHT = 128;
int gameWidth = 128;
int gameHeight = 128;
int windowWidth = 0;
int windowHeight = 0;
int padding = 0;
GameBoard board;
ParticleSim sim;
int initspeed = 1000;
int speed = initspeed;
int fastestSpeed = 200;
int numLevels = 10;
int level = 0;
int score = 0;
int combos = 0;
// Delay the spawn of the next player
//float nextPlayerDelay = 1000;
int gameState = 1;
public static final int STATEINTRO = 1;
public static final int STATEGAME = 2;
public static final int STATESETTINGS = 3;
int prevGameState = 0;
boolean gameStateChanged = false;
NumericFont scoreFont;
NumericFont comboFont;
PVector center;
class Events implements Observer {
@Override
public void update(Observable o, Object arg) {
if (o instanceof Config) {
if (arg instanceof ConfigLoadEvent) {
updateGameSize(); // needed to scale GUI images
initGUI();
}
if (arg instanceof ConfigPropChangeEvent) {
ConfigPropChangeEvent e = (ConfigPropChangeEvent) arg;
// If the number of tiles has changed, re-caculate game width and height
if (e.changed.contains("xTiles") || e.changed.contains("yTiles")) {
updateGameSize();
}
}
}
}
}
Events events;
void setup() {
size(128,128);
//fullScreen();
noSmooth();
config = new Config(dataPath("config.json"));
events = new Events();
config.addObserver(events);
// Load all images in the data directory
loadAllImages("/");
loadAllImages("board/");
loadAllImages("buttons/");
loadAllImages("numbers/");
loadAllImages("blocks/");
loadAllImages("text/");
loadAllImages("gui/");
// Generate all the different block types
generateBlocks();
initRandomShapeGen();
// Load last settings and highscore from the config file
// also initialize the GUI
try {
config.load();
} catch (Exception e) {
showErrorMessage(e.getMessage()+"\n\n The default configuration will be loaded instead.", "Error loading config");
config.loadDefault();
}
//initSounds();
// Initialize the particle simulation
sim = new ParticleSim();
scoreFont = new NumericFont(new String[][] {
{"0", "0"},
{"1", "1"},
{"2", "2"},
{"3", "3"},
{"4", "4"},
{"5", "5"},
{"6", "6"},
{"7", "7"},
{"8", "8"},
{"9", "9"},
});
comboFont = new NumericFont(new String[][] {
{"combo_0", "0"},
{"combo_1", "1"},
{"combo_2", "2"},
{"combo_3", "3"},
{"combo_4", "4"},
{"combo_5", "5"},
{"combo_6", "6"},
{"combo_7", "7"},
{"combo_8", "8"},
{"combo_9", "9"},
});
}
float now = 0, then = 0, time = 0;
void draw() {
now = millis();
time = now-then;
gameStateChanged = false;
if (gameState!=prevGameState) {
gameStateChanged = true;
}
prevGameState = gameState;
switch (gameState) {
case STATEINTRO:
intro(time);
break;
case STATEGAME:
game(time);
break;
case STATESETTINGS:
gameSettings(time);
break;
}
updateGUI(time);
then = now;
}
public void keyPressed() {
if (key==CODED) {
setMove(str(keyCode), true, true);
} else {
setMove(str(key), false, true);
}
if (key == ESC) {
//key = 0;
}
if (gameState==STATEGAME) {
if (!gameover && !newGame) {
if (isKeyDown("left")) {
board.player.move(-1,0);
timers.put("keyLeft",0f);
}
if (isKeyDown("right")) {
board.player.move(1,0);
timers.put("keyRight",0f);
}
}
}
}
public void keyReleased() {
if (key==CODED) {
setMove(str(keyCode), true, false);
} else {
setMove(str(key), false, false);
}
if (gameState==STATEGAME) {
if (!gameover && !newGame) {
if (keyCode==DOWN && timers.get("keyDown")>0) {
board.player.toBoard = true;
timers.put("keyDown",0f);
}
}
if (key==' ') {
if (newGame) {
newGame();
}
else if (!newGame) {
paused = !paused;
}
}
}
}