第一步,添加火力值属性
private int doubleFire;//火力值
public void addDoubleFire(){
doubleFire += 40;
}
//活力值清零
public void setDoubleFire(int doubleFire){
this.doubleFire = doubleFire;
}
public void shoot() {
int xStep = this.width / 4;
if(doubleFire > 0) { //双发
Bullet bullets0 = new Bullet(this.x + 1 xStep, this.y - 20);
Bullet bullets1 = new Bullet(this.x + 3 xStep, this.y - 20);
doubleFire -= 2; //发射双倍火力,每次减2,实际就是2倍火力的持续时间
FlyPanel.bullets.add(bullets0);
FlyPanel.bullets.add(bullets1);
}else {
Bullet bullet = new Bullet(this.x + 2 * xStep, this.y - 20);
FlyPanel.bullets.add(bullet);
}
}
// 检测敌机是否与子弹碰撞
for(Bullet bullet:bullets){
for(FlySprite enemy:enemys){
//PhysicsManager.isHit(bullet,enemy)
if(bullet.isHit(enemy)){
bullet.destroy();
if(enemy instanceof EnemyAirplane){
enemy.setDead(true);
}
if(enemy instanceof BuffAward){<br /> BuffAward buffAward = (BuffAward)enemy;<br /> if(buffAward.getAwardType()==0){<br /> _hero_.addDoubleFire();<br /> }else {<br /> _hero_.addLife();<br /> }<br /> enemy.destroy();<br /> }<br /> }<br /> }<br />}