当前位置:文档之家› 飞机大战

飞机大战



bee = ImageIO.read(ShootGame.class.getResource("bee.png"));

bullet = ImageIO.read(ShootGame.class.getResource("bullet.png"));

hero0 = ImageIO.read(ShootGame.class.getResource("hero0.png"));
主程序

class ShootGame extends JPanel


WIDTH,HEIGHT
background,start,pause,gameover airplane,bee,bullet,hero0,hero1 hero(Hero),flyings(FlyingObject[]),bullets(Bullet[]) static{}
创建抽象父类(飞行物)
public abstract void step ();
public boolean shootBy(Bullet bullet){
int x =bullet.x;
int y =bullet.y;
创建抽象父类(飞行物)
returnx>this.x && x<this.x+this.width && y>this.y && y<this.y+this.height;publicabstract boolean outOfBounds();

hero1 = ImageIO.read(ShootGame.class.getResource("hero1.png"));
贴图

public void enterAction(){ flyEnteredIndex++; if(flyEnteredIndex%40==0){ FlyingObject obj = nextOne(); flyings=Arrays.copyOf(flyings, flyings.length+1); flyings[flyings.length-1]=obj;
pause = ImageIO.read(ShootGame.class.getResource("pause.png")); gameover = ImageIO.read(ShootGame.class.getResource("gameover.png"));
贴图

airplane = ImageIO.read(ShootGame.class.getResource("airplane.png"));
public
public
public
public
static BufferedImage hero1;//英雄机2
主程序
private
Hero hero = new Hero();//英雄机对象 FlyingObject[] flyings ={};//敌人数组(敌机+
private
蜜蜂)
private
Bullet[] bullets ={};//子弹数组
贴图Βιβλιοθήκη try{ background = ImageIO.read(ShootGame.class.getResource("background.png"));


start = ImageIO.read(ShootGame.class.getResource("start.png"));





飞机大战游戏项目
项目元素分析
A B C
英雄机Hero 敌机Airplane 蜜蜂Bee
D
E
子弹Bullet
背景图Backgroue
元素建模
元素建模:使用一个数 据模型,描述元素的关 系,使用绘图坐标系作 为参考模型,英雄机, 敌机,蜜蜂,子弹都是
矩形区域。
创建抽象父类(飞行物)
protected int x; protected int y; protected int width; protected int height; protected BufferedImage image;


public static BufferedImage start;//启动
public static BufferedImage pause;//暂停 public static BufferedImage gameover;//游戏结束


主程序
public
static BufferedImage airplane;//敌机 static BufferedImage bee;//蜜蜂 static BufferedImage bullet;//子弹 static BufferedImage hero0;//英雄机1
主程序
public
class ShootGame extends JPanel {//继承相册 的面板 static final int WIDTH =400;//面板宽 static final int HEIGHT =654;//面板高
public
public
主程序

//图片 public static BufferedImage background;//背景图
相关主题