1.分析出FlySprite 精灵类 父类_
/*
精灵类:玩家机,敌机,子弹,道具机等元素都属于精灵对象
*/
_public abstract class FlySprite {
protected BufferedImage image;
protected int x;
protected int y;
protected int width;
protected int height;
protected boolean dead;
_/**<br /> * 初始化精灵信息<br /> */<br /> _public abstract void init();
_/**<br /> * 绘制<br /> * _**_@param _**_g<br /> */<br /> _public void draw(Graphics g){<br /> g.drawImage(image, x, y, width, height, null);<br /> }
_/**<br /> * 销毁<br /> */<br /> _public abstract void destroy();<br />}<br />第二步 2创建玩家类
public class Hero extends FlySprite{
public Hero(){
init();
}
@Override<br /> public void init() {<br /> BufferedImage img = ImageLoaderUtil._load_("hero1.png");<br /> this.image = img;<br /> this.width = img.getWidth() / 2;<br /> this.height = img.getHeight() / 2;<br /> this.x = (FlyFrame._WIDTH_- this.width) / 2;<br /> this.y = (FlyFrame._HEIGHT_- this.height - 50);<br /> }<br /> @Override<br /> public void destroy() {
}<br />}<br />3.面板上画出飞机<br />public static Hero _hero _= new Hero();<br />@Override<br />public void paint(Graphics g) {<br /> //画背景图片<br /> g.drawImage(_background_, x, y, bgWidth, bgHeight, null);<br /> paintState(g);<br /> _hero_.draw(g);<br />}