-
Notifications
You must be signed in to change notification settings - Fork 1
/
Game.pde
249 lines (213 loc) · 6.1 KB
/
Game.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//Startvariables
float speed = maxspeed;
//Variables
float scroll, nscroll;
float trackscroll;
float noisepos = 0;
float noiseoff;
boolean instation = false;
PImage background;
boolean showtrans = false;
float transscroll;
boolean firsttrans = true;
int acc = 0;
int acclastmillis;
String overlaytext = "";
int remauf = 0;
int remfahr = 0;
int sec;
boolean firstsetacc = true;
boolean startanimation = true;
void gamesetup() {
//create seats
for (int i = 0; i< seatx.length; i++) {
for (int j = 0; j < seaty.length; j++) {
seats[i*seaty.length+j] = new Seat(seatx[i], seaty[j], (i%2==0) ? 3 : 1);
}
}
seats[40] = new Seat(38, 19, 1);
seats[41] = new Seat(757, 19, 3);
seats[42] = new Seat(38, 157, 1);
seats[43] = new Seat(757, 157, 3);
seatlist = new ArrayList<Seat>();
for (int i = 0; i< seats.length; i++) {
seatlist.add(seats[i]);
}
//create NPCs
for ( int i = 0; i < charnum; i++) {
int hotseatnum = (int)random(seatlist.size());
Seat hotseat = seatlist.get(hotseatnum);
seatlist.remove(hotseatnum);
npcs[i] = new character(pl[(int)random(2)], hotseat.getX(), hotseat.getY(), hotseat.dir, i, npcs, 5);
npcs[i].seat = hotseat;
hotseat.occupied = true;
}
//Initiate Players
p1 = new Player(pl[(int)random(2)], 50, vheight*vertoff, 1, npcs);
p1.defineKeys(p1k);
p2 = new Player(pl[(int)random(2)], vwidth-50, vheight*vertoff, 3, npcs);
p2.defineKeys(p2k);
p1.otherpl = p2;
p2.otherpl = p1;
gameover = false;
overlaytext = "";
sec = millis();
remfahr = (int)random(10,20);
}
void gameloop() {
if(sec + 1000 < millis()){
if(instation){
sec = millis();
remauf--;
if(!gameover) overlaytext = str(remauf);
if(remauf == 0){
overlaytext = "";
instation = false;
dopen = false;
checkwin();
remfahr = (int)random(10,20);
firstsetacc = true;
setAcc(1);
}
}else{
sec = millis();
remfahr--;
if(remfahr == 0 && firstsetacc){
setAcc(-1);
firstsetacc = false;
}
}
}
if (acc == -1){
if(acclastmillis + 100 < millis()){
speed*=0.98;
acclastmillis = millis();
}
if (speed < maxspeed*0.1){
speed = 0;
dopen = true;
acc = 0;
firsttrans = true;
instation = true;
remauf = (int)random(15,30);
if(!gameover) overlaytext = str(remauf);
}
if (speed/maxspeed < 0.9 && firsttrans) {
firsttrans = false;
showtrans = true;
transscroll = trackscroll-tracks.width*2;
}
if(!firsttrans && transscroll > tracks.width){
background = station;
}
if(!firsttrans && transscroll > tracks.width*2){
showtrans = false;
}
}
if (acc == 1){
if(acclastmillis + 100 < millis()){
speed*=1.1;
acclastmillis = millis();
}
if (speed > maxspeed*0.99){
speed = maxspeed;
}
if(firsttrans){
firsttrans = false;
showtrans = true;
transscroll = trackscroll-tracks.width*2;
}
if(!firsttrans && transscroll > tracks.width + scroll){
showtrans = false;
firsttrans = true;
acc = 0;
background = tracks;
}
}
if(speed == 0) background = station;
//Draw Background (Tracks or station)
nimage(background, trackscroll, vheight/2);
nimage(background, trackscroll-tracks.width, vheight/2);
nimage(background, trackscroll+tracks.width, vheight/2);
trackscroll += speed;
if (trackscroll > tracks.width) trackscroll -= tracks.width;
if(showtrans && acc == -1) {
transscroll += speed;
nimage(tracks, transscroll+tracks.width, vheight/2);
nimage(transition1, transscroll, vheight/2);
nimage(station, transscroll-tracks.width, vheight/2);
}
if(showtrans && acc == 1) {
transscroll += speed;
nimage(tracks, transscroll-tracks.width, vheight/2);
nimage(transition2, transscroll, vheight/2);
nimage(station, transscroll+tracks.width, vheight/2);
}
//Draw level
noisepos += 0.07*speed/maxspeed; //Wackeln der wagen;
noiseoff = (noise(noisepos)-0.5)*2.5;
nimage(level, vwidth/2, vheight*vertoff+noiseoff);
nimage(link, (vwidth-level.width-link.width)/2, vheight*vertoff+(noise(noisepos+20)-0.5)*2.5);
nimage(wagon, (vwidth-level.width-wagon.width)/2-link.width, vheight*vertoff+(noise(noisepos+30)-0.5)*2.5);
nimage(link, (vwidth+level.width+link.width)/2, vheight*vertoff+(noise(noisepos+40)-0.5)*2.5);
nimage(wagon, (vwidth+level.width+wagon.width)/2+link.width, vheight*vertoff+(noise(noisepos+50)-0.5)*2.5);
ddraw();
//Show NPCs
for (int i = 0; i < charnum; i++) {
npcs[i].collide();
npcs[i].randmove();
npcs[i].show();
}
//Draw and move players
p1.show();
p1.move();
p1.collide();
p2.show();
p2.move();
p2.collide();
//Show Text
textAlign(CENTER,CENTER);
textSize(45*scale);
text(overlaytext, width/2, height*0.1);
textSize(20*scale);
if(gameover) text("Drücke eine beliebige Taste zum Fortfahren.", width/2, height*0.9);
//Scroll
if((intrain(p1.x,p1.y,0) && intrain (p2.x,p2.y,0) || instation) && !gameover){
nscroll = constrain((p1.x+p2.x-vwidth)/2, -vwidth/2, vwidth/2);
//Block if outside of display
if(startanimation){
if(abs(scroll-nscroll) < 2){
scroll = nscroll;
startanimation = false;
}else{
scroll = (scroll-nscroll)*0.95+nscroll;
}
}else{
scroll = nscroll;
if (abs(p1.x-p2.x)+10 > vwidth) {
if (p1.x-scroll < 5) {
p1.x = 5+scroll;
p2.x = vwidth+scroll-5;
} else {
p2.x = 5+scroll;
p1.x = vwidth+scroll-5;
}
}
}
}
}
void checkwin(){
if(!intrain(p1.x,p1.y,0) && !intrain(p2.x,p2.y,0)){
overlaytext = "Ihr habt beide verloren!";
gameover = true;
tastencooldown = millis() + 1000;
}else if(!intrain(p1.x,p1.y,-minDist/2)){
overlaytext = "Spieler 2 hat gewonnen";
gameover = true;
tastencooldown = millis() + 1000;
}else if(!intrain(p2.x,p2.y,-minDist/2)){
overlaytext = "Spieler 1 hat gewonnen";
gameover = true;
tastencooldown = millis() + 1000;
}
}