private void drawEntityHealthBar(Graphics g, EntityLocationTuple entityLocationHealthTriple) { Point p = entityLocationHealthTriple.point; Entity entity = entityLocationHealthTriple.entity; int oldHealth = entityHealthMap.get(entity).intValue(); int entityX = (int) p.getX() - hexWidth * 3 / 8; int entityY = (int) p.getY() - hexHeight * 3 / 8; Stats stats = entity.getStats(); int entitysCurrentActualHealth = stats.getStat(Stats.Type.HEALTH); // Only render health on NPCs // Also only update health bar, if the entities current health is diff than its old health if (!(entity == avatar)) { if (!entityEffedUpHealthMap.containsKey(entity) || oldHealth != entitysCurrentActualHealth) { System.out.println("CHANGIN ENTITY HEALTH"); Skill observation = avatar.getSpecificSkill(Skill.SkillDictionary.OBSERVATION); ObservationSkill observationSkill = (ObservationSkill) observation; observationSkill.onUpdate(entity); int effedUpHealth = observationSkill.getCombatError(entitysCurrentActualHealth); entityEffedUpHealthMap.put(entity, effedUpHealth); entityHealthMap.put(entity, entitysCurrentActualHealth); } // int health = entityEffedUpHealthMap.get(entity); int health = entitysCurrentActualHealth + entityEffedUpHealthMap.get(entity); int maxHealth = stats.getStat(Stats.Type.MAX_HEALTH); health = health > maxHealth ? maxHealth : health; health = health < 0 ? 0 : health; // Sizes int healthBarWidth = getScreenWidth() / 12; int healthBarHeight = getScreenHeight() / 53; // Set the font Font f = new Font("Courier New", 1, 14); g.setFont(f); // Set the location and size of the health bar. int healthBarX = entityX - healthBarWidth / 3; int healthBarY = entityY - healthBarHeight; // Draw the outline of the health bar. g.setColor(Color.RED); g.fillRect(healthBarX, healthBarY, healthBarWidth, healthBarHeight); // Determine what fraction of the healthbar should be shown. double healthFraction = (double) health / (double) maxHealth; int healthFillWidth = (int) (healthFraction * healthBarWidth); // Fill the healthbar g.setColor(Color.GREEN); g.fillRect(healthBarX, healthBarY, healthFillWidth, healthBarHeight); // Display the fraction of health g.setColor(Color.WHITE); String healthFractionString = "(" + health + "/" + maxHealth + ")"; FontMetrics fm = g.getFontMetrics(f); // Place the font at the right of the bar Rectangle2D healthFractionRect = fm.getStringBounds(healthFractionString, g); int healthFractionX = healthBarX + (healthBarWidth - (int) healthFractionRect.getWidth()) / 2; int healthFractionY = healthBarY + healthBarHeight - 4; g.drawString(healthFractionString, healthFractionX, healthFractionY); } }