这段代码只有在我撞到两个敌人(走进他们)或我杀死两个敌人(用子弹)(即我遇到第一个敌人和第二个敌人,或者我用子弹杀死两个敌人)时才有效,但如果我杀了第一个敌人(有子弹)然后遇到第二个(有碰撞)我的马力不会下降。有小费吗??
if (d.intersects(r1))
{
en.isAlive = false;
hitfirst = true;
}
if (d.intersects(r2))
{
en2.isAlive = false;
}
if (d.intersects(r2) && hitfirst == false)
hitmang(hit);
p.hitting = true;
if (d.intersects(r1) && en.visible == true && en.isAlive == false && !p.hitting)
{
hitmang(hit);
p.hitting = true;
}
if (d.intersects(r2) && en.visible == true && en.isAlive == false && !p.hitting)
{
hitmang(hit);
p.hitting = true;
}
if (!d.intersects(r1) && d.intersects(r2) && en2.visible == true && !p.hitting) {
hitmang(hit);
p.hitting = true;
}
if (!d.intersects(r1) && !d.intersects(r2)){
p.hitting = false;
}
我的敌人的边界
public Rectangle getBounds() // ghost is 114 x 134
{
return new Rectangle(x, y, 114, 134);
}
敌人
en = new Enemy(700, 150);
en2 = new Enemy (980, 150);
杀手锏
private void hitmang(int x) // x=25
{
p.user_hp = p.user_hp - x;
}