1414import static com .almasb .fxgl .dsl .FXGL .play ;
1515import static com .almasb .fxgl .dsl .FXGL .run ;
1616import static com .almasb .fxgl .dsl .FXGL .spawn ;
17+ import static org .enstabretagne .Game .GameMode .CLASSIQUE ;
18+ import static org .enstabretagne .Game .GameMode .INFINITY_MODE ;
19+ import static org .enstabretagne .Game .GameMode .SOLO ;
1720
1821import java .util .Arrays ;
1922import java .util .EnumSet ;
2023import java .util .Map ;
2124
22- import org .enstabretagne .Component .*;
25+ import org .enstabretagne .Component .AlienComponent ;
26+ import org .enstabretagne .Component .EntityType ;
27+ import org .enstabretagne .Component .LifeComponent ;
28+ import org .enstabretagne .Component .PlayerComponent ;
29+ import org .enstabretagne .Component .SpaceInvadersFactory ;
2330import org .enstabretagne .Core .AlienBulletCollision ;
2431import org .enstabretagne .Core .AlienPlayerCollision ;
2532import org .enstabretagne .Core .BulletBulletCollision ;
@@ -60,8 +67,7 @@ public class GameLauncher extends GameApplication {
6067 private long last_ambient_sound = System .currentTimeMillis ();;
6168 private int delay_ambient_sound = FXGLMath .random (Constant .AMBIENT_SOUND_DELAY_MIN ,
6269 Constant .AMBIENT_SOUND_DELAY_MAX );
63-
64- private int GameMode = 2 ; // 0 -> classique, 1 -> InfinityMode, 2->Solo
70+ private GameMode GameMode = CLASSIQUE ;
6571
6672 /**
6773 * Initialisation des paramètres du jeu
@@ -73,7 +79,7 @@ protected void initSettings(GameSettings settings) {
7379 settings .setWidth (Constant .GAME_WIDTH .intValue ());
7480 settings .setHeight (Constant .GAME_HEIGHT .intValue ());
7581 settings .setTitle ("Duel Invaders" );
76- settings .setAppIcon ("duelinvaders_icon2.png" );
82+ settings .setAppIcon (assetNames . textures . APP_ICON );
7783 settings .setVersion ("0.2.0" );
7884 settings .setMainMenuEnabled (true );
7985 settings .setGameMenuEnabled (true );
@@ -106,7 +112,6 @@ protected void initSettings(GameSettings settings) {
106112 */
107113 @ Override
108114 protected void initInput () {
109-
110115 onKey (KeyCode .ENTER , () -> {
111116 playerComponent1 .shoot ();
112117 });
@@ -120,23 +125,23 @@ protected void initInput() {
120125 });
121126
122127 onKey (KeyCode .SPACE , () -> {
123- if (GameMode == 2 ) {
128+ if (GameMode == SOLO ) {
124129 playerComponent1 .shoot ();
125130 } else {
126131 playerComponent2 .shoot ();
127132 }
128133 });
129134
130135 onKey (KeyCode .D , () -> {
131- if (GameMode == 2 ) {
136+ if (GameMode == SOLO ) {
132137 playerComponent1 .moveRight ();
133138 } else {
134139 playerComponent2 .moveRight ();
135140 }
136141 });
137142
138143 onKey (KeyCode .Q , () -> {
139- if (GameMode == 2 ) {
144+ if (GameMode == SOLO ) {
140145 playerComponent1 .moveLeft ();
141146 } else {
142147 playerComponent2 .moveLeft ();
@@ -174,7 +179,7 @@ protected void initGame() {
174179 playerComponent1 = player1 .getComponent (PlayerComponent .class );
175180 playerComponent1 .setDirection (Constant .Direction .UP );
176181
177- if (GameMode != 2 ) {
182+ if (GameMode != SOLO ) {
178183 // spawn Player2
179184 player2 = spawn (entityNames .PLAYER );
180185 player2 .setX (Constant .GAME_WIDTH / 2 );
@@ -183,9 +188,8 @@ protected void initGame() {
183188 playerComponent2 .setDirection (Constant .Direction .DOWN );
184189 }
185190
186- if (GameMode == 1 ) {
191+ if (GameMode == INFINITY_MODE ) {
187192 // spawn Aliens pour infinity mode
188-
189193 Entity alien1 = spawn (entityNames .ALIEN , 0 , Constant .GAME_HEIGHT / 2 - Constant .ALIEN_HEIGHT );
190194 alien1 .getComponent (AlienComponent .class ).initialize (Constant .Direction .UP );
191195 Entity alien2 = spawn (entityNames .ALIEN , 0 , Constant .GAME_HEIGHT / 2 - Constant .ALIEN_HEIGHT );
@@ -199,9 +203,9 @@ protected void initGame() {
199203 alien .getComponent (AlienComponent .class ).initialize (Constant .Direction .DOWN );
200204 }, Duration .seconds (1.5 ));
201205
202- } else if (GameMode == 0 ) {
206+ } else if (GameMode == CLASSIQUE ) {
203207 makeAlienBlock ();
204- } else if (GameMode == 2 ) {
208+ } else if (GameMode == SOLO ) {
205209 makeAlienBlockSolo ();
206210 }
207211
@@ -239,7 +243,6 @@ private void makeAlienLine(int line, Constant.Direction direction) {
239243 alien .getComponent (AlienComponent .class ).initialize (direction );
240244 alien .getComponent (AlienComponent .class ).setAlienNumber (i );
241245 }
242-
243246 }
244247 }
245248
@@ -260,8 +263,7 @@ private void makeAlienBlockSolo() {
260263 protected void initPhysics () {
261264 getPhysicsWorld ().addCollisionHandler (new AlienPlayerCollision ());
262265 getPhysicsWorld ().addCollisionHandler (new AlienBulletCollision ());
263- getPhysicsWorld ()
264- .addCollisionHandler (new EnemyShootPlayerCollision ());
266+ getPhysicsWorld ().addCollisionHandler (new EnemyShootPlayerCollision ());
265267 getPhysicsWorld ().addCollisionHandler (new BulletPlayerCollision ());
266268 getPhysicsWorld ().addCollisionHandler (new BulletBulletCollision ());
267269 getPhysicsWorld ().addCollisionHandler (new EnemyShootBulletCollision ());
@@ -297,14 +299,12 @@ protected void onUpdate(double tpf) {
297299 if (getb (GameVariableNames .isGameWon ))
298300 winScreen ();
299301
300- // teste le temps écoulé depuis la dernière fois que le son d'ambiance a été
301- // joué
302302 if ((System .currentTimeMillis () - last_ambient_sound ) > delay_ambient_sound ) {
303303 ambientSound ();
304304 last_ambient_sound = System .currentTimeMillis ();
305305 delay_ambient_sound = FXGLMath .random (Constant .AMBIENT_SOUND_DELAY_MIN , Constant .AMBIENT_SOUND_DELAY_MAX );
306306 }
307- Life_Update ();
307+ updateLife ();
308308 run (() -> {
309309 getGameWorld ().getEntitiesByType (EntityType .ALIEN ).forEach ((alien ) -> {
310310 if (FXGLMath .randomBoolean (0.01 ))
@@ -313,7 +313,7 @@ protected void onUpdate(double tpf) {
313313 }, Duration .seconds (Constant .random .nextDouble () * 10 ));
314314 }
315315
316- private void Life_Update () {
316+ private void updateLife () {
317317 int life_number = geti (GameVariableNames .PLAYERS_LIVES );
318318 if (life_number == 3 ) {
319319 life1 .getComponent (LifeComponent .class ).updateLife (false );
0 commit comments