-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNitrous.pde
More file actions
167 lines (135 loc) · 4.09 KB
/
Nitrous.pde
File metadata and controls
167 lines (135 loc) · 4.09 KB
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
//KeyPress booleans
boolean keyW, keyA, keyS, keyD;
int score = 0;
Tile[][] ground;
int distAway = 500;
int xSize = 50, ySize = 50;
StarterCar playerCar;
AICar[] aiCar;
float ts = 120; //TileSize
int delta = 0;
int lastUpdate;
void setup() {
//size(1600, 900, P3D);
fullScreen(P3D);
stroke(255);
frameRate(60);
smooth(2);
loadAssets();
lastUpdate = millis();
ground = new Tile[xSize][ySize];
for (int i = 0; i < ground.length; i++) {
for (int j = 0; j < ground[i].length; j++) {
float Xpos = -ts * ground.length/2 + ts * i;
float Ypos = -ts * ground[i].length/2 + ts * j;
ground[i][j] = new Tile(Xpos, Ypos, 0, ts, ts);
}
}
keyW = keyA = keyS = keyD = false;
playerCar = new StarterCar(0, 0, car1);
roadGen(xSize, ySize);
aiCar = new AICar[3];
for (int i = 0; i < aiCar.length; i++)
{
aiCar[i] = new AICar(ts * (10 + random(0, 10)), ts * (10 + random(0, 10)), car1);
}
for (int i = 0; i < ground.length; i++) {
for (int j = 0; j < ground[i].length; j++) {
boolean nearRoad = testIfRoad(i + 1, j)||testIfRoad(i, j + 1)||testIfRoad(i - 1, j)||testIfRoad(i, j - 1);
if (nearRoad && random(1) > 0.8) ground[i][j].addCollider(1);
if (random(1) > 0.9) ground[i][j].addCollider(0);
if (ground[i][j].type == ROAD) ground[i][j].obstacle = null;
}
}
}
void draw() {
///update timing functions///
delta = millis() - lastUpdate;
lastUpdate = millis();
update();
}
void drawSplash() {
image(splash, 0, 0, width, height);
}
void drawGame() {
//println(delta);
drawScore();
pushMatrix();
{
background(135, 206, 235);
translate(width/2, height/2);
camera(distAway, distAway, distAway*1.6, /*Position of the camera itself*/
0, 0, 0, /*Point the camera looks towards*/
0, 0, -1.0); /*Axis control*/
//camera(0, 0, 6000, /*Position of the camera itself*/
// 0, 0, 0, /*Point the camera looks towards*/
// 1.0, 0, 0); /*Axis control*/
lights();
directionalLight(100, 100, 100, -1, -1, -1.6);
for (int i = 0; i <ground.length; i++) {
for (int j = 0; j < ground[i].length; j++) {
ground[i][j].update(playerCar.pos);
ground[i][j].display();
if (ground[i][j].obstacle != null) {
PVector[] obs = ground[i][j].obstacle.getPoints();
for (int k = 0; k < obs.length; k++) obs[k].add(ground[i][j].pos);
if (collidePolyPoly(obs, playerCar.getPoints())) {
//playerCar.health -= 10;
playerCar.vel-=10;
//playerCar.acc = 0;
ground[i][j].obstacle = null;
score += 50;
}
}
}
}
for (int i = 0; i < aiCar.length; i++) {
if (aiCar[i] != null) {
if (collidePolyPoly(aiCar[i].getPoints(), playerCar.getPoints())) {
playerCar.health -= playerCar.fullHealth / aiCar.length + 1;
aiCar[i] = null;
}
}
}
if (playerCar.health <= 0) {
state = 2;
}
translate(0, 0, 1);
playerCar.update();
playerCar.display();
for (AICar car : aiCar)
{
if (car != null) {
car.update(playerCar.pos);
car.display();
}
}
}
popMatrix();
playerCar.drawHealth(20, 20, 500, 50);
}
//Moved this out here since it's a general function
boolean range(int value, int min, int max) {
return value > min && value < max;
}
void keyPressed() {
if (key == 'w' || key == 'W' || keyCode == 38) keyW = true;
if (key == 's' || key == 'S' || keyCode == 40) keyS = true;
if (key == 'a' || key == 'A' || keyCode == 37) keyA = true;
if (key == 'd' || key == 'D' || keyCode == 39) keyD = true;
if (state == 0) state = 1;
}
void keyReleased() {
if (key == 'w' || key == 'W' || keyCode == 38) keyW = false;
if (key == 's' || key == 'S' || keyCode == 40) keyS = false;
if (key == 'a' || key == 'A' || keyCode == 37) keyA = false;
if (key == 'd' || key == 'D' || keyCode == 39) keyD = false;
}
//needed features
// player health DONE
// framerate based updates DONE
// ai collision with player
// ai collision with each other
// score system
// ai wrap around
// faster on roads DONE