Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.risenphoenix.jnk.StarField.HUD;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.image.BufferedImage;
- import net.risenphoenix.jnk.StarField.Engine;
- import net.risenphoenix.jnk.StarField.INIT;
- public class HealthBar implements SFHudElement {
- double currentHealth;
- double healthLimit;
- double percentage;
- BufferedImage heart1;
- BufferedImage heart2;
- BufferedImage heart3;
- public HealthBar() {
- this.heart1 = Engine.RE.getResource("heart_full");
- this.heart2 = Engine.RE.getResource("heart_half");
- this.heart3 = Engine.RE.getResource("heart_none");
- }
- @Override
- public void drawElement(Graphics g) {
- this.currentHealth = Engine.game.getPlayer().getHealth();
- this.healthLimit = Engine.game.getPlayer().getHealthLimit();
- int numFull;
- int numEmpty;
- int halfPos;
- numEmpty = (int) Math.ceil((100 - this.currentHealth) / 10);
- numFull = (int)this.currentHealth / 10;
- halfPos = numFull;
- boolean shouldDrawHalf = false;
- boolean shouldDrawFull = false;
- // Half Heart Logic
- if (((int)this.currentHealth % 10) < 5 && ((int)this.currentHealth % 10) > 0) {
- shouldDrawHalf = true;
- } else if (((int)this.currentHealth % 10) > 5) {
- shouldDrawFull = true;
- }
- // Dead Hearts
- for(int i = (INIT.getFrameSize().width - 40) - (9*23); i < INIT.getFrameSize().width && numEmpty > 0; i += 23) {
- g.drawImage(this.heart3, i, 5, null);
- numEmpty--;
- }
- // Full Hearts
- for(int i = INIT.getFrameSize().width - 40; i > 0 && numFull > 0; i -= 23) {
- g.drawImage(this.heart1, i, 5, null);
- numFull--;
- }
- // For Dynamic Half Heart
- if (shouldDrawHalf) {
- g.drawImage(this.heart2, (INIT.getFrameSize().width - 40) - (halfPos*23), 5, null);
- } else if (shouldDrawFull) {
- g.drawImage(this.heart1, (INIT.getFrameSize().width - 40) - (halfPos*23), 5, null);
- }
- g.setColor(Color.WHITE);
- int xPos;
- // Determine xPosition of Readout
- if (this.currentHealth == 100) {
- xPos = ((INIT.getFrameSize().width - 40) - (10*23) - 5);
- } else {
- xPos = ((INIT.getFrameSize().width - 40) - (10*23));
- }
- // Numeric Readout
- g.drawString("" + (int)this.currentHealth, xPos, 20);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement