-
Notifications
You must be signed in to change notification settings - Fork 0
/
Crappy.java
executable file
·169 lines (123 loc) · 5.34 KB
/
Crappy.java
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
import java.awt.Font;
import StdDraw;
public class Crappy {
public static void main(String[] args) {
// set the scale of the coordinate system
boolean i = true;
boolean exit = false;
// main animation loop
while (i && exit == false){
int checkHighScore = 0;
boolean restart = false;
boolean scorek = false;
boolean startcheck = false;
double collision = 0.0;
StdDraw.setXscale(-10.0, 10.0);
StdDraw.setYscale(-10.0, 10.0);
// initial values
char check = 'a';
char b = 's';
char c = 's';
double move = 0;
double moveb = 0;
double pipe1x = 8.0; //pipe positions
double pipe2x = 15.0;
double pipe3x = 22.0;
double radius = 0.45;
int track = 0;
double rx = -5.0, ry = 0.0; // position
double vx = 0.0, vy = 0.0; // velocity
double pipe1cut = StdRandom.uniform(0,8); //pipe cut out positions
double pipe2cut = StdRandom.uniform(0,8);
double pipe3cut = StdRandom.uniform(0,8);
double[] check2 = new double[2];
while( startcheck == false && exit == false){
StdDraw.picture(0, 0, "photo.JPG");
StdDraw.show(50);
startcheck = StdDraw.hasNextKeyTyped() ;
}
if(startcheck == true){
check = StdDraw.nextKeyTyped();
if ( check == ' '){
while(collision == 0){
// check if any key is pressed
boolean z = StdDraw.hasNextKeyTyped() ;
//Graphics p = new Graphics();
// bounce off wall according to law of elastic collision
if (Math.abs(ry + vy) > 11.0 - radius) vy = -vy;
// update position
rx = rx + vx;
ry = ry + vy;
// set the pipes in motion
pipe1x = pipe.move(pipe1x);
pipe2x = pipe.move(pipe2x);
pipe3x = pipe.move(pipe3x);
pipe1cut = pipe.randomcuts(pipe1x,pipe1cut);
pipe2cut = pipe.randomcuts(pipe2x,pipe2cut);
pipe3cut = pipe.randomcuts(pipe3x,pipe3cut);
pipe1x = pipe.teleport(pipe1x);
pipe2x = pipe.teleport(pipe2x);
pipe3x = pipe.teleport(pipe3x);
// clear the background
move = parallax.groundm(move);
move = parallax.groundt(move);
moveb = parallax.background(moveb);
moveb = parallax.backgroundt(moveb);
StdDraw.picture(moveb, 0, "Flappy-Backgrounds day.png");
pipe.create(pipe1x,pipe1cut);
pipe.create(pipe2x,pipe2cut);
pipe.create(pipe3x,pipe3cut);
StdDraw.picture(move, -9.54, "Flappy-Ground.png");
check2 = keycheck.check(z,rx,ry,vy,collision);
vy = check2[0];
collision = check2[1];
//collision test for each pipe
collision = collisiontest.test(rx,ry,pipe1x,pipe1cut,collision,radius);
collision = collisiontest.test(rx,ry,pipe2x,pipe2cut,collision,radius);
collision = collisiontest.test(rx,ry,pipe3x,pipe3cut,collision,radius);
if(collision == 12){
}
track = score.track(track,rx,radius,pipe1x,ry);
track = score.track(track,rx,radius,pipe2x,ry);
track = score.track(track,rx,radius,pipe3x,ry);
// display and pause for 50 ms
StdDraw.show(50);
}
if(collision == 12){
while( ry >= -7){
ry = ry-.5;
StdDraw.picture(0, 0, "Flappy-Backgrounds day.png");
pipe.create(pipe1x,pipe1cut);
pipe.create(pipe2x,pipe2cut);
pipe.create(pipe3x,pipe3cut);
StdDraw.picture(rx, ry, "Flap down - fall.png");
pipe.create(pipe1x,pipe1cut);
pipe.create(pipe2x,pipe2cut);
pipe.create(pipe3x,pipe3cut);
StdDraw.picture(0, -10, "Flappy-Ground.png");
StdDraw.show(50);
}
while(b != 'a'){
StdDraw.show(50);
StdDraw.picture((rx + 5), 0, "dead.jpg");
StdDraw.setPenColor(StdDraw.YELLOW);
Font f = new Font(Font.SERIF,Font.BOLD, 50);
StdDraw.setFont(f);
StdDraw.text((rx + 5) ,-8 , "Press a to continue: ");
restart = StdDraw.hasNextKeyTyped();
if(restart == true){
b = StdDraw.nextKeyTyped();
}
}
checkHighScore = ReadFile.check();
if(checkHighScore < track){
WriteFile.high(track);
}
ReadFile.score(c,rx,scorek,track);
}
}
}
}
WriteFile.high(0);
}
}