我似乎无法让以下工作:我得到了这个方法 checkEnemyHealth() 通过更改精灵和添加杀戮等来照顾敌人的健康。但是,我需要更改特定 Playertank 对象的杀戮,所以我尝试了以下代码:
public void collisionOccured(GameItem collidedItem)
{
if(collidedItem instanceof Playertank) //Botsing met player
{
enemyHealth = 0.0;
}
if (collidedItem instanceof Weapon) //Botsing met wapen
{
lowerEnemyHealth(Weapon.weaponDamage);
System.out.println("loweredddd");
}
if ((collidedItem instanceof Weapon) || (collidedItem instanceof Playertank))
{
checkEnemyHealth((GameItem)collidedItem);
}
}
public void checkEnemyHealth(GameItem collidedItem)
{
if (enemyHealth >= (2.0/3.0 * startupEnemyHealth))
{
this.setFrame(0); //Green Enemy
this.setEnemyStage(0);
}
else if (enemyHealth < (2.0/3.0 * startupEnemyHealth) && enemyHealth >= (1.0/3.0 * startupEnemyHealth))
{
this.setFrame(1); //Orange Enemy
this.setEnemyStage(1);
}
else if (enemyHealth < (1.0/3.0 * startupEnemyHealth) && enemyHealth > 0)
{
this.setFrame(2); //Red Enemy
this.setEnemyStage(2);
}
else if (enemyHealth <= 0 && (getEnemyStage() != 3))
{
setImage("/images/death.png", 27, 33); //Dead enemy
enemyOnDeath();
if (collidedItem instanceof Playertank)
{
((Playertank)collidedItem).raisePlayerKills(1);
mygame.setKillsonDashboard(((Playertank)collidedItem).getPlayerKills());
((Playertank)collidedItem).raisePlayerLandmines(1);
mygame.setLandminesonDashboard(((Playertank)collidedItem).getPlayerLandmines());
}
mygame.setTimer(10, 33, this);
}
printHealth();
System.out.println(this.getEnemyStage());
}
但是,即使实例是武器,我也需要执行 raisePlayerKills()。我似乎找不到解决方案。
更多信息:
Playertank.java creates the gameplayer and extends GamePlayer.java
GamePlayer.java extends MoveableGameItem.java
Enemytank.java extends MoveableGameItem.java
MoveableGameItem.java extends GameItem.java
我希望它足以解决这个问题,提前谢谢 Flame