public class World extends JPanel { public static final int WIDTH = 400;//public static final int WIDTH=400; public static final int HEIGHT = 700;//public static final int HEIGHT=700; private Sky sky = new Sky();//private Sky sky=new Sky(); private Hero hero = new Hero();//private Hero hero=new Hero(); private FlyingObject[] enemies = {}; // 敌人数组 private FlyingObject []enemies={}; private Bullet[] bullets = {}; // 子弹数组 private Bullet[]bullets={}; public static final int START = 0;//public static final int START=0; public static final int RUNNING = 1;//public static final int RUNNING=1; public static final int PAUSE = 2;//public static final int PAUSE=2; public static final int GAME_OVER = 3;//public static final int GAME_OVER=3; private int state = START;//private int state=START; public static BufferedImage start;//public static BufferedImage start; public static BufferedImage pause;//public static BufferedImage pause; public static BufferedImage gameover;//public static BufferedImage gameover; static {//static{静态块 start = Images.loadImage("start.png");//start=Images.loadImage("start.png); pause = Images.loadImage("pause.png");//pause=Images.loadImage("pause.png"); gameover = Images.loadImage("gameover.png");//gameover=Images.loadImage("gameover.png"); } public FlyingObject nextOne() {//public FlyingObject nextOne(){ Random rand = new Random();//Random rand=new Random(); int type = rand.nextInt(20);//int type=rand .nextInt(20); if (type < 5) {//if(type<5){ return new Bee();//return new Bee(); } else if (type < 20) {//else if (type<20){ return new Airplane();//return new Airplane(); } else {//else return new BigAirplane();//return new BigAirplane(); } } int flyEnterIndex = 0;//int flyEnterIndex=0; public void enterAction() {//public void enterAction(){ flyEnterIndex++;//flyEnterIndex++; if (flyEnterIndex % 40 == 0) {//if(flyEnterIndex%40==0){ FlyingObject obj = nextOne();//FlyingObject obj=nextOne; enemies = Arrays.copyOf(enemies, enemies.length + 1);//enemies =Arrays.copyOf(enemies,enemies.length+1); enemies[enemies.length - 1] = obj;//enemies [enemies.length-1]=obj; } } public void stepAction() {//public void stepAction(){ sky.step();//sky.step(); for (int i = 0; i < enemies.length; i++) {//for(int i=0;i