百合文库
首页 > 网文

Java教程-看这个就够了(B)(13)

2023-08-19 来源:百合文库
g.drawImage(img,(int)x,(int) y,null);
}
public Rectangle getRect(){//返回对象所在矩形,方便以后做碰撞检测!
return new Rectangle((int)x,(int)y,width,height);
}//属性设置的是double,所以要转型int
//下面是构造方法,接下来可以开始设计飞机类了
public GameObject(Image img, double x, double y, int speed) {
this.img = img;
this.x = x;
this.y = y;
this.speed = speed;
}
public GameObject(Image img, double x, double y, int speed, int width, int height) {
this.img = img;

Java教程-看这个就够了(B)


this.x = x;
this.y = y;
this.speed = speed;
this.width = width;
this.height = height;
}
public GameObject(){
}
public GameObject(Image img, double x, double y) {
this.img = img;
this.x = x;
this.y = y;
}
}
五,飞机类重构设计
这是飞机类的设计代码
import java.awt.*;
public class plane extends GameObject{
public void drawSelf(Graphics g) {//重写父类方法画出飞机
g.drawImage(img,(int)x,(int) y,null);
x ;y ;//对飞机的轨迹暂时先这样吧

Java教程-看这个就够了(B)


猜你喜欢