@@ -33,7 +33,7 @@ public Game() {
33
33
public void run () {
34
34
int speed = 10 ;
35
35
System .out .println ("Game.run()" );
36
-
36
+
37
37
while (Runner .state == Runner .STATE .GAME ) {
38
38
ticks ++;
39
39
@@ -47,7 +47,7 @@ public void run() {
47
47
}
48
48
49
49
// incrémente le niveau tout les 500 ticks
50
- if (ticks % 250 == 0 ) {
50
+ if (ticks % 500 == 0 ) {
51
51
level ++;
52
52
speed = (int )round (speed * 1.2 );
53
53
}
@@ -76,18 +76,19 @@ public void run() {
76
76
}
77
77
}
78
78
79
- // stoppe player au niveau du sol
80
- if (player .y >= Runner .HEIGHT - 160 || player .y < 0 ) {
79
+ // stoppe player au niveau du sol en fonction de sa position
80
+ if (( player .y >= Runner .HEIGHT - 160 || player .y < 0 ) && ! player . crouched ) {
81
81
player .y = Runner .HEIGHT - 160 ;
82
- }
83
-
84
- // réinitialise le double saut quand player atterit
85
- if (player .y == 440 ) {
82
+ player .jumping = 0 ;
83
+ } else if ((player .y >= Runner .HEIGHT - 140 || player .y < 0 ) && player .crouched ) {
84
+ player .y = Runner .HEIGHT - 140 ;
86
85
player .jumping = 0 ;
87
86
}
88
- System .out .println (player .y );
89
- // actualise le rendu
90
- Runner .renderer .repaint ();
87
+
88
+ // actualise le rendu tout les deux ticks
89
+ if (ticks % 2 == 0 ) {
90
+ Runner .renderer .repaint ();
91
+ }
91
92
92
93
try {
93
94
Thread .sleep (20 );
@@ -142,9 +143,11 @@ public void mousePressed(MouseEvent e) {
142
143
switch (Runner .state ) {
143
144
case GAME :
144
145
System .out .println (Runner .state );
145
- if (e .getButton () == 1 ) { // si clic droit
146
+ // si clic gauche
147
+ if (e .getButton () == 1 ) {
146
148
player .jump ();
147
- } else {
149
+ player .uncrouch ();
150
+ } else if (player .jumping == 0 ) {
148
151
player .crouch ();
149
152
}
150
153
break ;
@@ -155,5 +158,16 @@ public void mousePressed(MouseEvent e) {
155
158
break ;
156
159
}
157
160
}
161
+
162
+ public void mouseReleased (MouseEvent e ) {
163
+ // si clic droit pendant l'état de jeu
164
+ if (e .getButton () == 3 && player .crouched ) {
165
+ player .crouch ();
166
+ }
167
+ }
168
+
169
+ public void mouseClicked (MouseEvent e ) {
170
+ System .out .println ("a" );
171
+ }
158
172
159
173
}
0 commit comments