Skip to content

Commit d607ce3

Browse files
Fixed spacing and comments
1 parent 365eaa6 commit d607ce3

File tree

3 files changed

+68
-74
lines changed

3 files changed

+68
-74
lines changed

src/main/java/com/dinosaur/dinosaurexploder/components/LifeComponent.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ public void clearEntity() {
9595

9696
/**
9797
* Summary :
98-
* This method is overriding the superclass method to increase the life to the
99-
* current life without exceeding
98+
* This method is overriding the superclass method to increase the life to the current life without exceeding
10099
* the maximum number of lives allowed
101100
*/
102101
@Override
@@ -107,8 +106,7 @@ public int increaseLife(int i) {
107106

108107
/**
109108
* Summary :
110-
* This method is overriding the superclass method to decrease the life to the
111-
* current life
109+
* This method is overriding the superclass method to decrease the life to the current life
112110
*/
113111
@Override
114112
public int decreaseLife(int i) {

src/main/java/com/dinosaur/dinosaurexploder/controller/DinosaurController.java

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525
/**
2626
* Summary :
27-
* The Factory handles the Dinosaur , player controls and collision detection of
28-
* all entities in the game
27+
* The Factory handles the Dinosaur , player controls and collision detection of all entities in the game
2928
*/
3029
public class DinosaurController {
3130
LanguageManager languageManager = LanguageManager.getInstance();
@@ -43,12 +42,11 @@ public class DinosaurController {
4342

4443
/**
4544
* Summary :
46-
* Detecting the player damage to decrease the lives and checking if the game is
47-
* over
45+
* Detecting the player damage to decrease the lives and checking if the game is over
4846
*/
4947
public void damagePlayer() {
50-
if (player.getComponent(PlayerComponent.class).isInvincible()) {
51-
return;
48+
if(player.getComponent(PlayerComponent.class).isInvincible()){
49+
return;
5250
}
5351
int lives = life.getComponent(LifeComponent.class).decreaseLife(1);
5452
var flash = new Rectangle(DinosaurGUI.WIDTH, DinosaurGUI.HEIGHT, Color.rgb(190, 10, 15, 0.5));
@@ -68,7 +66,7 @@ public void damagePlayer() {
6866

6967
/**
7068
* Summary :
71-
* To move the space shuttle in forward , backward , right , left directions
69+
* To move the space shuttle in forward , backward , right , left directions
7270
*/
7371
public void initInput() {
7472
onKey(KeyCode.UP, () -> player.getComponent(PlayerComponent.class).moveUp());
@@ -89,10 +87,10 @@ public void initInput() {
8987
public void initGame() {
9088
initGameEntities();
9189
levelManager = new LevelManager();
92-
bossSpawner = new BossSpawner(settings, levelManager);
90+
bossSpawner = new BossSpawner(settings,levelManager);
9391
CoinSpawner coinSpawner = new CoinSpawner(10, 1.0);
9492

95-
if (!settings.isMuted()) {
93+
if(!settings.isMuted()) {
9694
FXGL.play(GameConstants.BACKGROUND_SOUND);
9795
}
9896

@@ -103,7 +101,7 @@ public void initGame() {
103101
});
104102
}
105103

106-
private void initGameEntities() {
104+
private void initGameEntities(){
107105
spawn("background", 0, 0);
108106
player = spawn("player", getAppCenter().getX() - 45, getAppHeight() - 200);
109107
levelDisplay = spawn("Level", getAppCenter().getX() - 270, getAppCenter().getY() + 350);
@@ -117,19 +115,19 @@ private void initGameEntities() {
117115

118116
/**
119117
* Summary :
120-
* This method is used to spawn the enemies
121-
* and set the spawn rate of the enemies
118+
* This method is used to spawn the enemies
119+
* and set the spawn rate of the enemies
122120
*/
123121
private void spawnEnemies() {
124-
if (enemySpawnTimer != null) {
122+
if(enemySpawnTimer != null) {
125123
enemySpawnTimer.expire();
126124
}
127125

128126
enemySpawnTimer = run(() -> {
129-
if (levelManager.getCurrentLevel() % 5 == 0) {
127+
if(levelManager.getCurrentLevel() % 5 == 0) {
130128
pauseEnemySpawning();
131129
bossSpawner.spawnNewBoss();
132-
} else {
130+
}else {
133131
if (!isSpawningPaused && random(0, 2) < 2) {
134132
Entity greenDino = spawn("greenDino", random(0, getAppWidth() - 80), -50);
135133
greenDino.getComponent(GreenDinoComponent.class).setMuted(settings.isMuted());
@@ -140,11 +138,11 @@ private void spawnEnemies() {
140138

141139
/**
142140
* Summary :
143-
* This method is used to pause the enemy spawning
141+
* This method is used to pause the enemy spawning
144142
*/
145-
private void pauseEnemySpawning() {
143+
private void pauseEnemySpawning(){
146144
isSpawningPaused = true;
147-
if (enemySpawnTimer != null) {
145+
if(enemySpawnTimer != null) {
148146
enemySpawnTimer.pause();
149147
}
150148
}
@@ -153,33 +151,32 @@ private void pauseEnemySpawning() {
153151
* Summary :
154152
* This method is used to resume the enemy spawning
155153
*/
156-
private void resumeEnemySpawning() {
154+
private void resumeEnemySpawning(){
157155
isSpawningPaused = false;
158-
if (enemySpawnTimer != null) {
156+
if(enemySpawnTimer != null){
159157
enemySpawnTimer.resume();
160-
} else {
158+
} else{
161159
spawnEnemies();
162160
}
163161
}
164162

165163
/**
166164
* Summary :
167-
* Handles level progression when enemies are defeated
168-
* and shows a message when the level is changed
165+
* Handles level progression when enemies are defeated
166+
* and shows a message when the level is changed
169167
*/
170-
private void showLevelMessage() {
171-
// Pause game elements during level transition
168+
private void showLevelMessage(){
169+
//Pause game elements during level transition
172170
FXGL.getGameWorld().getEntitiesByType(EntityType.GREEN_DINO).forEach(e -> {
173-
if (e.hasComponent(GreenDinoComponent.class)) {
171+
if(e.hasComponent(GreenDinoComponent.class)) {
174172
e.getComponent(GreenDinoComponent.class).setPaused(true);
175173
}
176174
});
177175

178176
pauseEnemySpawning();
179177

180178
// Display centered level notification
181-
Text levelText = getUIFactoryService()
182-
.newText(languageManager.getTranslation("level") + levelManager.getCurrentLevel(), Color.WHITE, 24);
179+
Text levelText = getUIFactoryService().newText(languageManager.getTranslation("level") + levelManager.getCurrentLevel(), Color.WHITE, 24);
183180
levelText.setStroke(Color.BLACK);
184181
levelText.setStrokeWidth(1.5);
185182
centerText(levelText);
@@ -196,7 +193,7 @@ private void showLevelMessage() {
196193
updateLevelDisplay();
197194

198195
FXGL.getGameWorld().getEntitiesByType(EntityType.GREEN_DINO).forEach(e -> {
199-
if (e.hasComponent(GreenDinoComponent.class)) {
196+
if(e.hasComponent(GreenDinoComponent.class)){
200197
e.getComponent(GreenDinoComponent.class).setPaused(false);
201198
}
202199
});
@@ -205,7 +202,7 @@ private void showLevelMessage() {
205202

206203
player.getComponent(PlayerComponent.class).setInvincible(true);
207204
runOnce(() -> {
208-
if (player != null && player.isActive()) {
205+
if(player != null && player.isActive()){
209206
player.getComponent(PlayerComponent.class).setInvincible(false);
210207
}
211208
}, seconds(3));
@@ -214,14 +211,14 @@ private void showLevelMessage() {
214211

215212
/**
216213
* Summary :
217-
* Center the text on the screen
214+
* Center the text on the screen
218215
*/
219-
private void centerText(Text text) {
216+
private void centerText(Text text){
220217
text.setX((getAppWidth() - text.getLayoutBounds().getWidth()) / 2.0);
221218
text.setY(getAppHeight() / 2.0);
222219
}
223220

224-
public void updateLevelDisplay() {
221+
public void updateLevelDisplay(){
225222
Text levelText = (Text) levelDisplay.getViewComponent().getChildren().get(0);
226223
levelText.setText(languageManager.getTranslation("level") + ": " + levelManager.getCurrentLevel());
227224

@@ -233,27 +230,26 @@ public void updateLevelDisplay() {
233230

234231
/**
235232
* Summary :
236-
* Detect the collision between the game elements.
233+
* Detect the collision between the game elements.
237234
*/
238235
public void initPhysics() {
239236
/*
240-
* After collision between projectile and greenDino there hava explosion
241-
* animation
237+
* After collision between projectile and greenDino there hava explosion animation
242238
* and there have 5% chance to spawn a heart
243239
*/
244240
onCollisionBegin(EntityType.PROJECTILE, EntityType.GREEN_DINO, (projectile, greenDino) -> {
245241
spawn("explosion", greenDino.getX() - 25, greenDino.getY() - 30);
246242
if (random(0, 100) < 5) {
247243
spawn("heart", greenDino.getX(), greenDino.getY());
248244
}
249-
if (!settings.isMuted()) {
245+
if(!settings.isMuted()) {
250246
FXGL.play(GameConstants.ENEMY_EXPLODE_SOUND);
251247
}
252248
projectile.removeFromWorld();
253249
greenDino.removeFromWorld();
254250
score.getComponent(ScoreComponent.class).incrementScore(1);
255251
levelManager.incrementDefeatedEnemies();
256-
if (levelManager.shouldAdvanceLevel()) {
252+
if(levelManager.shouldAdvanceLevel()) {
257253
levelManager.nextLevel();
258254
showLevelMessage();
259255
System.out.println("Level up!");
@@ -272,7 +268,7 @@ public void initPhysics() {
272268
onCollisionBegin(EntityType.PROJECTILE, EntityType.RED_DINO, (projectile, redDino) -> {
273269
spawn("explosion", redDino.getX() - 25, redDino.getY() - 30);
274270
projectile.removeFromWorld();
275-
if (!settings.isMuted()) {
271+
if(!settings.isMuted()) {
276272
FXGL.play(GameConstants.ENEMY_EXPLODE_SOUND);
277273
}
278274
redDino.getComponent(RedDinoComponent.class).damage(1);
@@ -281,32 +277,32 @@ public void initPhysics() {
281277
// if the boss is defeated it drops 100% a heart
282278
spawn("heart", redDino.getX(), redDino.getY());
283279
// if the boss dino is defeated it drops as many coins as the current level
284-
for (int i = 0; i < levelManager.getCurrentLevel(); i++) {
285-
spawn("coin", redDino.getX() + random(-25, 25), redDino.getY() + random(-25, 25));
280+
for (int i = 0; i<levelManager.getCurrentLevel(); i++){
281+
spawn("coin", redDino.getX()+random(-25,25), redDino.getY()+random(-25,25));
286282
}
287283
bossSpawner.removeBossEntities();
288284

289285
score.getComponent(ScoreComponent.class).incrementScore(levelManager.getCurrentLevel());
290286
levelManager.nextLevel();
291287
showLevelMessage();
292288
System.out.println("Level up!");
293-
} else {
289+
} else{
294290
bossSpawner.updateHealthBar();
295291
}
296292

297293
});
298294

299295
onCollisionBegin(EntityType.PROJECTILE, EntityType.ENEMY_PROJECTILE, (projectile, enemyProjectile) -> {
300296
spawn("explosion", enemyProjectile.getX() - 25, enemyProjectile.getY() - 30);
301-
if (!settings.isMuted()) {
297+
if(!settings.isMuted()) {
302298
FXGL.play(GameConstants.ENEMY_EXPLODE_SOUND);
303299
}
304300
projectile.removeFromWorld();
305301
enemyProjectile.removeFromWorld();
306302
});
307303

308304
onCollisionBegin(EntityType.ENEMY_PROJECTILE, EntityType.PLAYER, (projectile, player) -> {
309-
if (!settings.isMuted()) {
305+
if(!settings.isMuted()) {
310306
FXGL.play(GameConstants.PLAYER_HIT_SOUND);
311307
}
312308
projectile.removeFromWorld();
@@ -315,7 +311,7 @@ public void initPhysics() {
315311
});
316312

317313
onCollisionBegin(EntityType.PLAYER, EntityType.GREEN_DINO, (player, greenDino) -> {
318-
if (!settings.isMuted()) {
314+
if(!settings.isMuted()) {
319315
FXGL.play(GameConstants.PLAYER_HIT_SOUND);
320316
}
321317
greenDino.removeFromWorld();
@@ -324,15 +320,15 @@ public void initPhysics() {
324320
});
325321

326322
onCollisionBegin(EntityType.PLAYER, EntityType.RED_DINO, (player, redDino) -> {
327-
if (!settings.isMuted()) {
323+
if(!settings.isMuted()) {
328324
FXGL.play(GameConstants.PLAYER_HIT_SOUND);
329325
}
330326
System.out.println("You touched a red dino !");
331327
damagePlayer();
332328
});
333329

334330
onCollisionBegin(EntityType.PLAYER, EntityType.COIN, (player, coin) -> {
335-
if (!settings.isMuted()) {
331+
if(!settings.isMuted()) {
336332
FXGL.play(GameConstants.COIN_GAIN);
337333
}
338334
coin.removeFromWorld();
@@ -346,7 +342,7 @@ public void initPhysics() {
346342
});
347343

348344
onCollisionBegin(EntityType.PLAYER, EntityType.HEART, (player, heart) -> {
349-
if (!settings.isMuted()) {
345+
if(!settings.isMuted()) {
350346
FXGL.play(GameConstants.HEART_HIT_SOUND);
351347
}
352348
heart.removeFromWorld();
@@ -357,7 +353,7 @@ public void initPhysics() {
357353

358354
/**
359355
* Summary :
360-
* To detect whether the player lives are empty or not
356+
* To detect whether the player lives are empty or not
361357
*/
362358
public void gameOver() {
363359
new GameOverDialog(languageManager).createDialog();

src/main/java/com/dinosaur/dinosaurexploder/model/GameEntityFactory.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,34 +147,34 @@ public Entity newGreenDino(SpawnData data) {
147147
public Entity newCoin(SpawnData data) {
148148
System.out.println("Loading coin texture: " + GameConstants.COIN_IMAGE_FILE);
149149
return entityBuilderBase(data, EntityType.COIN)
150-
.with(new OffscreenCleanComponent())
151-
.view(texture(GameConstants.COIN_IMAGE_FILE, 40, 40))
152-
.bbox(new HitBox(BoundingShape.box(40, 40)))
153-
.collidable()
154-
.with(new CoinComponent())
155-
.build();
150+
.with(new OffscreenCleanComponent())
151+
.view(texture(GameConstants.COIN_IMAGE_FILE, 40, 40))
152+
.bbox(new HitBox(BoundingShape.box(40, 40)))
153+
.collidable()
154+
.with(new CoinComponent())
155+
.build();
156156
}
157157

158158
@Spawns("redDino")
159159
public Entity newRedDino(SpawnData data) {
160160
return entityBuilderBase(data, EntityType.RED_DINO)
161-
.with(new OffscreenCleanComponent())
162-
.view(texture(GameConstants.RED_DINO_IMAGE_FILE, 100, 80))
163-
.bbox(new HitBox(BoundingShape.box(65, 55)))
164-
.collidable()
165-
.with(new RedDinoComponent())
166-
.build();
161+
.with(new OffscreenCleanComponent())
162+
.view(texture(GameConstants.RED_DINO_IMAGE_FILE, 100, 80))
163+
.bbox(new HitBox(BoundingShape.box(65, 55)))
164+
.collidable()
165+
.with(new RedDinoComponent())
166+
.build();
167167
}
168168

169-
@Spawns("healthBar")
170-
public Entity newHealthbar(SpawnData data) {
171-
Rectangle healthbar = new Rectangle(200.0, 25.0, Color.RED);
172-
return entityBuilderBase(data, EntityType.HEALTHBAR)
173-
.with(new OffscreenCleanComponent())
174-
.with(new HealthbarComponent())
175-
.view(healthbar)
176-
.build();
177-
}
169+
@Spawns("healthBar")
170+
public Entity newHealthbar(SpawnData data) {
171+
Rectangle healthbar = new Rectangle(200.0, 25.0, Color.RED);
172+
return entityBuilderBase(data, EntityType.HEALTHBAR)
173+
.with(new OffscreenCleanComponent())
174+
.with(new HealthbarComponent())
175+
.view(healthbar)
176+
.build();
177+
}
178178

179179
/**
180180
* Summary :

0 commit comments

Comments
 (0)