📄 plane.java
字号:
package spriteplane;
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
public class Plane {
public static int MOVE = 4;
public Sprite plane;
private Graphics g = null;
int scnX, scnY;
int frameX, frameY;
int x, y;
boolean b = true;
Image img;
public Plane(Graphics g, int width, int height, int frameWidth,
int frameHeight) {
scnX = width;
scnY = height;
if (width > height) {
x = y = height / 2;
}
else {
x = y = width / 2;
}
this.g = g;
img = null;
this.frameX = frameWidth;
this.frameY = frameHeight;
try {
img = Image.createImage("/res/planes.png");
}
catch (Exception e) {
System.out.println("io error");
}
plane = new Sprite(img, frameWidth, frameHeight);
}
public void DrawSelf() {
if (b == true) {
plane.setPosition(x,y);
plane.paint(g);
// bullet.paint(g);//
b = false;
}
else {
plane.paint(g);
}
}
public void moveLeft() {
getXY();
if (x - MOVE > 0) {
plane.move(MOVE * -1, 0);
}
}
public void moveRight() {
getXY();
if ( (x + MOVE + frameX) < scnX) {
plane.move(MOVE, 0);
}
}
public void moveNS() {
getXY();
if ( (x - MOVE) > 0) {
plane.move(MOVE * -1, MOVE * -1);
}
}
public void moveUp() {
getXY();
if (y - MOVE > 0) {
plane.move(0, MOVE * -1);
}
}
public void moveDown() {
getXY();
if (y + MOVE + frameY < scnY) {
plane.move(0, MOVE);
}
}
public void getXY() {
x = plane.getX();
y = plane.getY();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -