Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
fix health bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine-Bouche committed Jun 17, 2022
1 parent ba297a0 commit 395e471
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/main/java/fr/sae/terraria/Terraria.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public void start(Stage stage) throws IOException
gameController.scaleMultiplicatorHeight = ((newV.intValue()-gameController.title.getPrefHeight()) / Terraria.DISPLAY_RENDERING_HEIGHT);
});
gameController.environment.getPlayer().pvProperty().addListener((obs, oldV, newV) ->{

if (newV.longValue() == 0){
stage.close();
}
});

stage.show();
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/fr/sae/terraria/modele/entities/Slime.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ else if (environment.getPlayer().getX() < this.x.getValue())
if (!whereCollide.isEmpty())
if (whereCollide.get("left").equals(Boolean.TRUE) || whereCollide.get("right").equals(Boolean.TRUE))
this.idleOnX();

if (environment.getPlayer().getRect().collideRect(this.getRect()) && !environment.getPlayer().getHit()){
environment.getPlayer().setHit(true);
environment.getPlayer().setPv(environment.getPlayer().getPv() -1 );
environment.getPlayer().hit();
environment.getPlayer().setInvicibilityFrame(this.environment.getTicks());
}
if (environment.getPlayer().getHit() && this.environment.getTicks() - environment.getPlayer().getInvicibilityFrame() == TIME_BEFORE_HITTING_AGAIN_THE_PLAYER){

if (environment.getPlayer().getHit() && this.environment.getTicks() - environment.getPlayer().getInvicibilityFrame() == TIME_BEFORE_HITTING_AGAIN_THE_PLAYER)
environment.getPlayer().setHit(false);
}
}

@Override public void move()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected Entity(int x, int y)

public Animation getAnimation() { return this.animation; }
public Rect getRect() { return this.rect; }
public double getPvMax() { return this.pv.get(); }
public double getPvMax() { return this.pvMax; }
public double getPv() { return this.pv.get(); }
public double getX() { return this.x.get(); }
public double getY() { return this.y.get(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public Player(final Environment environment)

@Override public void hit()
{
this.setPv(this.getPv() - 1);
this.pv.set(this.getPv() - 1);
this.hit = true;
}

@Override public void spawn(int x, int y)
Expand Down Expand Up @@ -171,10 +172,10 @@ else if (key == KeyCode.Q)
public Map<KeyCode, Boolean> getKeysInput() { return this.keysInput; }
public Stack getStackSelected() { return this.stackSelected; }
public Inventory getInventory() { return this.inventory; }
public Boolean getHit() { return hit; }
public void setHit(Boolean hit) { this.hit = hit; }
public boolean getHit() { return this.hit; }
public int getInvicibilityFrame() { return invicibilityFrame; }
public void setInvicibilityFrame(int ticks2) { this.invicibilityFrame = ticks2; }

public void setStackSelected(Stack stackSelected) { this.stackSelected = stackSelected; }
public void setHit(boolean b) { this.hit = b; }
public void setInvicibilityFrame(int ticks2) { this.invicibilityFrame = ticks2; }
}
10 changes: 8 additions & 2 deletions src/main/java/fr/sae/terraria/vue/hud/HealthBarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ private void displayHealthBar(double inventoryBarX, double inventoryBarY)

// Modifie le cœur selon la vie du joueur
player.pvProperty().addListener((obs, oldPv, newPv) -> {
if (oldPv.intValue() >= 0) {
ImageView healthView = healths[oldPv.intValue()-1];
ImageView healthView;
if (newPv.intValue() > oldPv.intValue()) {
healthView = healths[newPv.intValue()-1];
Rectangle2D viewPort = new Rectangle2D((healthView.getImage().getWidth()/3)*2, 0, (healthView.getImage().getWidth()/3), healthView.getImage().getHeight());
healthView.setViewport(viewPort);
}

if (newPv.intValue() < oldPv.intValue()) {
healthView = healths[oldPv.intValue()-1];
Rectangle2D viewPort = new Rectangle2D((healthView.getImage().getWidth()/3)*0, 0, (healthView.getImage().getWidth()/3), healthView.getImage().getHeight());
healthView.setViewport(viewPort);
}
Expand Down

0 comments on commit 395e471

Please sign in to comment.