小敌机
package day19;
import java.awt.image.BufferedImage;
import java.util.Random;
public class Airplane extends FlyingObject{
private static BufferedImage[] images;
static {
images= new BufferedImage[5];
images[0] = loadImage("airplane.png");
images[1] = loadImage("airplane.png");
images[2] = loadImage("airplane.png");
images[3] = loadImage("airplane.png");
images[4] = loadImage("airplane.png");
}
private int speed;
public Airplane(){
super(49,36);
speed = 2;
}
public void step(){
y+=speed;
}
int index = 1;
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;
}
}
小蜜蜂
package day19;
import java.awt.image.BufferedImage;
import java.util.Random;
public class Bee extends FlyingObject{
private int xSpeed;
private int ySpeed;
private int awardType;
public Bee(){
super(60,50);
xSpeed = 1;
ySpeed = 2;
Random rand = new Random();
awardType = rand.nextInt(2);
}
public void step(){
x+=xSpeed;
y+=ySpeed;
if(x<=0 || x>World.WINTH-this.width){
xSpeed*=-1;
}
}
int index = 1;
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;
}
}
天空
package day19;
import java.awt.image.BufferedImage;
public class Sky extends FlyingObject{
private static BufferedImage image;
static{
image = loadImage("background.png");
}
private int speed;
private int y1;
public Sky(){
super(World.WINTH,World.HEIGHT,0,0);
speed = 1;
y1 = -World.HEIGHT;
}
public void step(){
y+=speed;
y1+=speed;
if(y>=World.HEIGHT){
y-=World.HEIGHT;
}
if(y1>=World.WINTH){
y1-=World.HEIGHT;
}
}
public BufferedImage getImage(){
return image;
};
}