📄 enemyplane.java
字号:
package airplane;
import java.awt.Image;
import java.applet.Applet;
import java.util.*;
public class EnemyPlane extends SuperSprite{
int AppletWidth, AppletHeight;
int startX, startY;
int planeImgWidth, planeImgHeight;
Random R;
public EnemyPlane(Image planeImg,
int startX,
int startY,
Applet Game,
int AppletWidth,
int AppletHeight) {
super(planeImg, startX, startY, Game); //调用父类的创建方法
this.startX = startX;
this.startY = startY;
planeImgWidth = planeImg.getWidth(Game);
planeImgHeight = planeImg.getHeight(Game);
this.AppletWidth = AppletWidth;
this.AppletHeight = AppletHeight;
setVisible(true); //不可见
setMove(true); //不可移动
}
public void updateState() { //更新敌人飞机Sprite的状态
int t;
t = Y;
R = new Random();
if (active == true) {
if (X < -planeImgWidth) { //当敌人飞机穿过左边界时,重新从右开始
do {
Y = R.nextInt() % (AppletHeight - planeImgHeight);
} while (Y <= 0 ||
Y >(AppletHeight - planeImgHeight) ||
java.lang.Math.abs(t-Y)<planeImgHeight);
X = AppletWidth;
setVisible(true);
} else
X = X - 5; //向左移动1像素
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -