Skip to content

Commit e89a008

Browse files
committed
#199 improved visuals of missing lives
1 parent 852ad94 commit e89a008

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import javafx.scene.text.Font;
1212
import javafx.scene.text.Text;
1313

14+
import java.util.List;
15+
1416
/**
1517
* Summary :
1618
* This handles the life component of the Player implements the life interface and extends the Component
@@ -19,6 +21,7 @@ public class LifeComponent extends Component implements Life {
1921

2022
private static final int MAX_LIVES = 3;
2123
private final Image heart = new Image(GameConstants.HEART_IMAGE_PATH);
24+
private final Image heartLost = new Image(GameConstants.HEART_LOST_IMAGE_PATH);
2225
private int life = MAX_LIVES;
2326

2427
// Declaring Lives Text
@@ -59,24 +62,21 @@ private void updateLifeDisplay() {
5962
// Clear previous entities
6063
clearEntity();
6164

62-
// Adjust hearts and set them based on the current life value
63-
heart1.setLayoutY(10);
64-
heart2.setLayoutY(10);
65-
heart3.setLayoutY(10);
66-
67-
heart2.setLayoutX(heart1.getLayoutX() + 30);
68-
heart3.setLayoutX(heart2.getLayoutX() + 30);
65+
List<ImageView> lives = List.of(heart1, heart2, heart3);
6966

7067
// Set the appropriate number of hearts based on `life`
71-
if (life == 3) {
72-
setEntity(heart1);
73-
setEntity(heart2);
74-
setEntity(heart3);
75-
} else if (life == 2) {
76-
setEntity(heart1);
77-
setEntity(heart2);
78-
} else if (life == 1) {
79-
setEntity(heart1);
68+
for(int i = MAX_LIVES; i > 0; i--){
69+
ImageView currentHeart = lives.get(MAX_LIVES - i);
70+
if(i > life){
71+
currentHeart.setImage(heartLost);
72+
}else{
73+
currentHeart.setImage(heart);
74+
75+
}
76+
77+
currentHeart.setLayoutY(10);
78+
currentHeart.setLayoutX((MAX_LIVES -i) * 30);
79+
setEntity(currentHeart);
8080
}
8181

8282
// Display the lifeText component

src/main/java/com/dinosaur/dinosaurexploder/constants/GameConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class GameConstants {
2323
public static final String COIN_IMAGE_FILE = "coin.png";
2424
public static final String HEART_IMAGE_PATH = "assets/textures/life.png";
2525
public static final String HEART_IMAGE_FILE = "life.png";
26+
public static final String HEART_LOST_IMAGE_PATH = "assets/textures/lifeLost.png";
27+
public static final String HEART_LOST_IMAGE_FILE = "lifeLost.png";
2628
public static final String BOMB_IMAGE_PATH = "assets/textures/bomb.png";
2729
public static final String GAME_ICON_DINOSAUR = "icon.png";
2830

3.46 KB
Loading

0 commit comments

Comments
 (0)