主机类
/**
-
主机
-
@author Administrator
*/
public class Hero extends FlyingObiect{
private static BufferedImage[] images;
static{
images = new BufferedImage[2];
for (int i = 0; i < images.length; i++) {
images[i] = loadImage(“hero” + i + “.png”);
}
}
private int life ;
private int doubleFire;public Hero() {
super(97, 124, 140, 400);
life = 6;
doubleFire = 0;
}
public void moveTo(int x,int y){
this.x = x - this.width/2;
this.y = y - this.height/2;
}
public void step(){
System.out.println(“图片的切换”);
}
@Override
public BufferedImage getImage() {
return images[0];
}
/*英雄机产生子弹/
public Bullet[] shoot() {
int xStep = this.width/4;
int yStep = 15;
if (doubleFire >0) {//双倍火力
Bullet[] bs = new Bullet[2];
bs[0] = new Bullet(this.x + xStep * 1, this.y - yStep);
bs[1] = new Bullet(this.x + xStep * 3, this.y - yStep);
return bs;
}else {
Bullet[] bs = new Bullet[1];
bs[0] = new Bullet(this.x + xStep * 2, this.y - yStep);
return bs;
}
}
public void addDoubleFire() {
doubleFire +=10;
}
public void addLife() {
life++;
}
public int getLife() {
return life;
}
public void substractLife() {
life–;
}
public void clearDoublieFire() {
// TODO Auto-generated method stub
doubleFire = 0;
}
}
小型敌机类
public class AirPlane extends FlyingObiect implements Enemy{
private static BufferedImage[] images;
static{
images = new BufferedImage[5];
for (int i = 0; i < images.length; i++) {
images[i] = loadImage(“airplane” + i + “.png”);
}
}
//成员变量
private int speed;//速度
//方法
/构造方法/
public AirPlane () {
super(49, 36);
//小敌机出现的位置
this.speed = 2;
}
/移动/
public void step(){
this.y += speed;
}
//得到图片
int index = 1;
@Override
public BufferedImage getImage() {
if (isLife()) {
return images[0];
} else if(isDead()){//图片切换
BufferedImage img = images[index++];
if (index == images.length) {
state = REMOVE;
}
return img;
}
return null;
}
/*得分奖励/
@Override
public int getScore() {
return 1;
}
}
大型敌机
public class BigAirplane extends FlyingObiect implements Enemy{
private static BufferedImage[] images;
static{
images = new BufferedImage[5];
for (int i = 0; i < images.length; i++) {
images[i] = loadImage(“bigplane” + i + “.png”);
}
}
//成员变量
private int speed;//速度
//方法
/构造方法/
public BigAirplane () {
super(98, 72);
this.speed = 2;
}
/移动/
public void step(){
this.y += speed;
}
int index = 1;
@Override
public BufferedImage getImage() {
if (isLife()) {
return images[0];
} else if(isDead()){//图片切换
BufferedImage img = images[index++];
if (index == images.length) {
state = REMOVE;
}
return img