网站链接: element-ui dtcms
当前位置: 首页 > 技术博文  > 技术博文

JAVA学习day36--飞机大战09

2021/4/25 0:53:25 人评论

飞机大战09 天空 package day19; import java.awt.image.BufferedImage; /** 天空*/ public class Sky extends FlyingObject{private static BufferedImage image;static{image loadImage("background.png");}private int speed; //移动速度private int y1; …

飞机大战09

天空

package day19;
import java.awt.image.BufferedImage;
/** 天空*/
public class Sky extends FlyingObject{
	private static BufferedImage image;
	static{
		image = loadImage("background.png");
	}

	private int speed;    //移动速度
	private int y1;       //第二张图的y坐标
	/** 构造方法*/
	public Sky(){
		super(400,700,0,0);
		speed = 1;
		y1 = -700;
		
	}
	/** step*/
	public void step(){
		System.out.println("天空的Y坐标和Y1坐标都移动了:"+speed);
	}

}

超类

package day19;

import java.util.Random;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class FlyingObject {
	protected int width;
	protected int height;
	protected int x;
	protected int y;
	/**专门给英雄机,天空,子弹提供的 */
	public FlyingObject(int width,int height,int x,int y){
		this.width = width;
		this.height = height;
		this.x = x;
		this.y = y;
	}
	
	/** 专门给小敌机,大敌机,小蜜蜂提供的*/
	
	public FlyingObject(int width,int height){
		this.width = width;
		this.height = height;
		Random rand = new Random();//随机数对象
		x = rand.nextInt(400-this.width);//x:0到(窗口宽-小敌机宽)之间当的随机数
		y = -this.height;//y:负的小敌机的高
	}
	//读取图片
	public static BufferedImage loadImage(String fileName){
		try{
			BufferedImage img = ImageIO.read(FlyingObject.class.getResource(fileName));//同包中读取文件
			return img;
		}catch(Exception e){
			e.printStackTrace();
			throw new RuntimeException();
		}
	}
	
	/** 飞行物移动*/
	public void step(){
		System.out.println("飞行物移动了");
	}


}

相关资讯

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?