publicclassPlaneextendsGameObject{boolean left;boolean right;boolean up;boolean down;//飞机状态boolean live =true;publicPlane(Image airplane,double x,double y,int width,int height,int speed){this.setImage(airplane);this.setX(x);this.setY(y);this.setWidth(width);this.setHeight(height);setSpeed(speed);}@OverridepublicvoiddrawSelf(Graphics graphics){if(live){
graphics.drawImage(this.getImage(),(int)this.getX(),(int)this.getY(),null);if(left){setX(getX()-getSpeed());}if(up){setY(getY()-getSpeed());}if(right){setX(getX()+getSpeed());}if(down){setY(getY()+getSpeed());}}}//按下某键 增加相应的方向publicvoidaddDirection(KeyEvent keyEvent){switch(keyEvent.getKeyCode()){case KeyEvent.VK_LEFT:
left =true;break;case KeyEvent.VK_UP:
up =true;break;case KeyEvent.VK_RIGHT:
right =true;break;case KeyEvent.VK_DOWN:
down =true;break;}}//抬起某键 减少相应的方向publicvoidminusDirection(KeyEvent keyEvent){switch(keyEvent.getKeyCode()){case KeyEvent.VK_LEFT:
left =false;break;case KeyEvent.VK_UP:
up =false;break;case KeyEvent.VK_RIGHT:
right =false;break;case KeyEvent.VK_DOWN:
down =false;break;}}}
目录1. 常量类2.工具类3.游戏对象父类4.飞机类5.炸弹类6.主类7.测试类1. 常量类public class Constant { public static final int WINDOW_WIDTH = 700; public static final int WINDOW_HEIGHT = 700;}2.工具类public class GameUtil { //工具最好将构造器私有化 private GameUtil(){ } //返