因此,我正在尝试为玩家制作一个带有健康栏的游戏,但每当我使用交叉产品或任何其他数学方法应该起作用时,百分比结果是0.0......这是处理此问题的.java文件:
package com.game.graphics;
import com.game.entity.mob.Mob;
public class HUD {
Mob target;
Sprite healthbar;
Sprite bgBar;
double percent_normal;
public HUD(Mob target) {
this.target = target;
bgBar = new Sprite(0xff777777, 104, 8);
healthbar = new Sprite(0xffFF0000, 100, 6);
}
public void update() {
percent_normal = target.getHealth() / 100;
percent_normal *= target.getMaxHealth();
}
public void printData() {
System.out.println("Normal(" + percent_normal + ")");
// if the targets's health is any lower than the max health then this seems to always return 0 …Run Code Online (Sandbox Code Playgroud)