Create bar with player HP
This commit is contained in:
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@@ -24,6 +24,9 @@ public abstract class Character extends EntityDelegate {
|
|||||||
@Getter
|
@Getter
|
||||||
protected boolean immortal = false;
|
protected boolean immortal = false;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
protected int maxHp;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
protected int hp;
|
protected int hp;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public class Enemy extends Character implements NPC {
|
|||||||
this.template = template;
|
this.template = template;
|
||||||
name = template.getName();
|
name = template.getName();
|
||||||
hp = template.getHp();
|
hp = template.getHp();
|
||||||
|
maxHp = hp;
|
||||||
setSpeed(template.getSpeed());
|
setSpeed(template.getSpeed());
|
||||||
setAnimationSpeed(template.getAnimationSpeed());
|
setAnimationSpeed(template.getAnimationSpeed());
|
||||||
setBlocking(template.isBlocking());
|
setBlocking(template.isBlocking());
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ public class Player extends Character {
|
|||||||
|
|
||||||
public Player(@NonNull Context context, @NonNull Entity entity) {
|
public Player(@NonNull Context context, @NonNull Entity entity) {
|
||||||
super(context, entity);
|
super(context, entity);
|
||||||
|
this.hp = 100;
|
||||||
|
this.maxHp = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
65
src/main/java/com/bartlomiejpluta/demo/gui/Bar.java
Normal file
65
src/main/java/com/bartlomiejpluta/demo/gui/Bar.java
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package com.bartlomiejpluta.demo.gui;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.api.gui.*;
|
||||||
|
import com.bartlomiejpluta.base.lib.gui.*;
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.api.screen.*;
|
||||||
|
import com.bartlomiejpluta.base.api.context.Context;
|
||||||
|
import com.bartlomiejpluta.base.api.input.*;
|
||||||
|
|
||||||
|
public class Bar extends BaseComponent {
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private float value = 1.0f;
|
||||||
|
private float actualValue = 1.0f;
|
||||||
|
private float speed = 0.05f;
|
||||||
|
private final Color stroke;
|
||||||
|
private final Color fill;
|
||||||
|
|
||||||
|
public Bar(Context context, GUI gui) {
|
||||||
|
super(context, gui);
|
||||||
|
|
||||||
|
this.stroke = gui.createColor();
|
||||||
|
this.fill = gui.createColor();
|
||||||
|
|
||||||
|
stroke.setAlpha(1f);
|
||||||
|
fill.setAlpha(1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStrokeColor(Integer hex) {
|
||||||
|
stroke.setRGB(hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFillColor(Integer hex) {
|
||||||
|
fill.setRGB(hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getContentWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getContentHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Screen screen, GUI gui) {
|
||||||
|
var remainingDistance = value - actualValue;
|
||||||
|
actualValue += remainingDistance * speed;
|
||||||
|
|
||||||
|
gui.beginPath();
|
||||||
|
gui.drawRectangle(x, y, Math.max(width * actualValue, 0), height);
|
||||||
|
gui.setFillColor(fill);
|
||||||
|
gui.fill();
|
||||||
|
gui.closePath();
|
||||||
|
gui.beginPath();
|
||||||
|
gui.drawRectangle(x, y, width, height);
|
||||||
|
gui.setStrokeColor(stroke);
|
||||||
|
gui.stroke();
|
||||||
|
gui.closePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,9 @@ public class HUD extends BorderLayout {
|
|||||||
|
|
||||||
private float logVisibilityDuration = 0f;
|
private float logVisibilityDuration = 0f;
|
||||||
|
|
||||||
|
@Ref("hp")
|
||||||
|
private Bar hp;
|
||||||
|
|
||||||
@Ref("debug")
|
@Ref("debug")
|
||||||
private Label debugLbl;
|
private Label debugLbl;
|
||||||
|
|
||||||
@@ -60,6 +63,8 @@ public class HUD extends BorderLayout {
|
|||||||
public void update(float dt) {
|
public void update(float dt) {
|
||||||
super.update(dt);
|
super.update(dt);
|
||||||
|
|
||||||
|
hp.setValue((float) player.getHp() / (float) player.getMaxHp());
|
||||||
|
|
||||||
if(logVisibilityDuration > 0) {
|
if(logVisibilityDuration > 0) {
|
||||||
logVisibilityDuration -= dt * 1000;
|
logVisibilityDuration -= dt * 1000;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -8,6 +8,20 @@
|
|||||||
width="1f"
|
width="1f"
|
||||||
height="1f">
|
height="1f">
|
||||||
|
|
||||||
|
<base:BorderLayout-TopLeft>
|
||||||
|
|
||||||
|
<demo:Bar
|
||||||
|
ref="hp"
|
||||||
|
strokeColor="0x111111"
|
||||||
|
fillColor="0xFF0000"
|
||||||
|
widthMode="SizeMode.ABSOLUTE"
|
||||||
|
heightMode="SizeMode.ABSOLUTE"
|
||||||
|
width="250f"
|
||||||
|
height="20f"
|
||||||
|
margin="5f" />
|
||||||
|
|
||||||
|
</base:BorderLayout-TopLeft>
|
||||||
|
|
||||||
<base:BorderLayout-BottomLeft>
|
<base:BorderLayout-BottomLeft>
|
||||||
|
|
||||||
<base:Label
|
<base:Label
|
||||||
|
|||||||
Reference in New Issue
Block a user