1.buff奖励类
/*
奖励类
*/
_public class BuffAward extends FlySprite implements ActionSprite{
//x 步数
private int xSpeed = 2;
//y 步数
private int ySpeed = 2;
//奖励类型 0 双发 1 加命
private int awardType;
public BuffAward(){
this.init();
}
@Override
public void init() {
Random random = new Random();
//产生的随机数0,1就是奖励类型
this.awardType = random.nextInt(2);
super.image = ImageLoaderUtil._load(“proptype“+awardType+”.png”);
super.width = super.image.getWidth();
super.height = super.image.getHeight();
//初始 x 位置 y 位置
y=-super.height;
x=random.nextInt(FlyFrame.WIDTH-super.width);
}
@Override<br /> public void destroy() {<br /> FlyPanel._enemys_.remove(this);<br /> }
@Override<br /> public void down() {<br /> //向下运行 走S行 xy 都变<br /> if(super.x>=FlyFrame._WIDTH_-super.width){<br /> xSpeed = -2;<br /> }<br /> if(super.x<=0){<br /> xSpeed = 2;<br /> }<br /> super.x+=xSpeed;<br /> super.y+=ySpeed;<br /> if(super.y>FlyFrame._HEIGHT_){<br /> this.destroy();<br /> }<br /> }<br />}<br />定时任务类<br />class EnemyTask extends TimerTask {<br /> @Override<br /> public void run() {<br /> Random rand = new Random();<br /> int type = rand.nextInt(10); // 生成0到19的随机数<br /> if (type == 0) { // 随机数为0,返回bee;否则返回敌机<br /> BuffAward e = new BuffAward();<br /> _enemys_.add(e);<br /> } else {<br /> EnemyAirplane e = new EnemyAirplane();<br /> _enemys_.add(e);<br /> }<br /> //重绘<br /> repaint();<br /> }<br />}
//敌机的集合, 泛型 EnemyAirplane 多态
public static CopyOnWriteArrayList
//只要页面发送变动,就重绘的方法
@Override
public void paint(Graphics g) {
g.drawImage(background, x, y, bgWidth, bgHeight, null);
paintState(g);
hero.draw(g);
for (Bullet bullet : bulletList) {
bullet.draw(g);
bullet.up();
}
for (FlySprite flySprite : enemys) {
flySprite.draw(g);
ActionSprite actionSprite = (ActionSprite)flySprite;
actionSprite.down();
}
}