plane.java
来自「j2me 小的子弹精灵,简单介绍sprite 的一个例子」· Java 代码 · 共 91 行
JAVA
91 行
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 + =
减小字号Ctrl + -
显示快捷键?