[英]Adding a new life once a score has been reached in a Java game
Im developing a java game where you kill enemies and earn points. 我正在开发一个Java游戏,您可以杀死敌人并获得积分。 Every 3000 points you obtain id like to add 1 more life point to the players ship. 每获得3000点ID,便会为玩家的飞船增加1点生命。 My current implementation means that once you've reached 3000 points, you get 1 life for every kill (which is not what i want). 我当前的实现方式意味着,一旦您达到3000点,您每击杀一次即可获得1条生命(这不是我想要的)。 What i would like is 1 life for every 3000 point (1 life at 3000, 1 more life at 6000). 我想要的是每3000点增加1点生命(3000点增加1点生命,6000点增加1点生命)。 How would i go about doing this ? 我将如何去做? My score method: 我的评分方法:
public void incScore(int inc){
//hit asteroid 100
//hit spaceship 250
//mothership = 500
score = score + inc;
if (score >= 3000){
playerShip.life = playerShip.life +1;
}
}
Use (before increasing the score): 使用(在增加分数之前):
if (score /3000 < (score + inc) / 3000)
playerShip.life++;
Use an extra variable like lifecount. 使用额外的变量,例如lifecount。
int lifecount = 1;
public void incScore(int inc){
//hit asteroid 100
//hit spaceship 250
//mothership = 500
score = score + inc;
if (score >= 3000*lifecount){
playerShip.life = playerShip.life +1;
lifecount++;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.