-
Notifications
You must be signed in to change notification settings - Fork 0
/
World.pde
184 lines (158 loc) · 4.45 KB
/
World.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
class World
{
// Ground
PShape ground;
int chunkSize;
// Objects
Camera cam;
Player player;
ArrayList<Projectile> projs = new ArrayList<Projectile>();
ArrayList<Spike> spikes = new ArrayList<Spike>();
// Enemies
ArrayList<Enemy> enemies = new ArrayList<Enemy>();
EnemySpawner espawner;
// High Scores
JSONArray saveData;
int highestStepsAlive;
int highestEnemiesKilled;
int highestMaxDistance;
// Menus
boolean mainMenu;
World()
{
chunkSize = 300;
// Objects
cam = new Camera();
player = new Player();
espawner = new EnemySpawner();
// Ground
textureMode(NORMAL);
ground = createShape();
ground.beginShape(QUADS);
ground.texture(loader.groundTex);
ground.vertex(-chunkSize * 0.5, 0, -chunkSize * 0.5, 0, 0);
ground.vertex(chunkSize * 0.5, 0, -chunkSize * 0.5, 0, chunkSize * 0.1);
ground.vertex(chunkSize * 0.5, 0, chunkSize * 0.5, chunkSize * 0.1, chunkSize * 0.1);
ground.vertex(-chunkSize * 0.5, 0, chunkSize * 0.5, chunkSize * 0.1, 0);
ground.vertex(-chunkSize * 0.5, 0, -chunkSize * 0.5, 0, 0);
ground.endShape();
// High Scores
saveData = loadJSONArray("save-data.txt");
highestStepsAlive = saveData.getJSONObject(0).getInt("value");
highestEnemiesKilled = saveData.getJSONObject(1).getInt("value");
highestMaxDistance = saveData.getJSONObject(2).getInt("value");
// Load mouse sense
input.mouseHSense = saveData.getJSONObject(3).getFloat("value");
input.mouseVSense = saveData.getJSONObject(4).getFloat("value");
// Menus
mainMenu = true;
}
void restart()
{
// Main menu
mainMenu = false;
// Empty array lists
for (int i = enemies.size() - 1; i >= 0; i--) { enemies.remove(i); }
for (int i = projs.size() - 1; i >= 0; i--) { projs.remove(i); }
// Player
player.restart();
espawner.restart();
// Blip sound
loader.sndBlip.play();
}
boolean touchingSpikes(float x, float z)
{
if (int(x) % chunkSize == 250 && int(z) % chunkSize == 250) { return true; }
return false;
}
void update()
{
// Objects
psystem.update();
player.update();
espawner.update();
cam.update();
for (int i = 0; i < projs.size(); i++) { projs.get(i).update(); }
for (int i = 0; i < enemies.size(); i++) { enemies.get(i).update(); }
}
void draw()
{
// Background
background(0);
cam.draw();
// Particles
psystem.draw();
// Origin
if (!mainMenu)
{
pushMatrix();
fill(255);
noStroke();
box(2, 0.5, 2);
stroke(0);
popMatrix();
}
// Ground
pushMatrix();
textureWrap(REPEAT);
translate(int(cam.center.x / chunkSize) * chunkSize - chunkSize, 0, int(cam.center.z / chunkSize) * chunkSize - chunkSize);
for (int j = 0; j < 3; j++)
{
for (int i = 0; i < 3; i++)
{
shape(ground);
translate(chunkSize, 0, 0);
}
translate(-chunkSize * 3, 0, chunkSize);
}
popMatrix();
// Objects
player.draw();
for (int i = 0; i < projs.size(); i++) { projs.get(i).draw(); }
for (int i = 0; i < enemies.size(); i++) { enemies.get(i).draw(); }
for (int i = 0; i < spikes.size(); i++) { spikes.get(i).draw(); }
// DRAW GUI
hint(DISABLE_DEPTH_TEST);
perspective();
camera();
noLights();
if (mainMenu)
{
// Main menu
pushMatrix();
fill(0, 255, 0);
// Title
translate(width / 2, 350);
shearY(PI / 8);
translate(-115, 0);
textSize(96);
textAlign(LEFT, TOP);
text("OH3D", 0, 0);
// Button prompt
translate(0, 256);
textSize(32);
shearY(-PI / 4.2);
translate(-175, -20);
text("Press R to play", 0, 0);
// High scores
shearY(0.23);
fill(255, 255, 0);
textSize(24);
translate(-420, -315);
text("Longest Time Alive: " + String.format("%.1f", world.highestStepsAlive / 60.0), 0, 0);
translate(20, 35);
text("Most Enemies Killed: " + highestEnemiesKilled, 0, 0);
translate(20, 35);
text("Furthest Max Distance: " + highestMaxDistance, 0, 0);
fill(255);
popMatrix();
// Credits
textAlign(RIGHT, BOTTOM);
fill(255, 0, 255);
text("created by nandbolt, v0.0.1", width - 64, height - 32);
fill(255);
}
else { player.drawGui(); }
hint(ENABLE_DEPTH_TEST);
}
}