第一步,界面上画出英雄生命值
private int score = 0; // 得分
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public void paintScore(Graphics g) { // 画分,画命
g.setColor(new Color(0xFF0000));
g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 20));
g.drawString(“LIFE: “ + hero.getLife(), 20, 45);
g.drawString(“SCORE: “ + hero.getScore(), 20, 25);
}
// 检测敌机是否与子弹碰撞
for(Bullet bullet:bullets){
for(FlySprite enemy:enemys){
//PhysicsManager.isHit(bullet,enemy)
if(bullet.isHit(enemy)){
bullet.destroy();
if(enemy instanceof EnemyAirplane){
EnemyAirplane enemyAirplane = (EnemyAirplane) enemy;
// 减少血量
enemyAirplane.setBlood(enemyAirplane.getBlood()-1);
// 判断敌机血槽是否已空
if (enemyAirplane.getBlood() == 0) {
enemy.setDead(true);
hero.setScore(hero.getScore()+enemyAirplane.getScore());
}
}
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 />}