📄 trialsprit.java
字号:
//Download by http://www.codefans.net
import java.io.IOException;
import java.util.Random;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
public class TrialSprit extends Sprite {
int mType;
int mFrameIndex = 0;
int mDirection = 0;
int mSpeed;
final static int TNormal = 1;
int mStepCnt = 0;
int mInternalCnt = 15;
Random mRandom = new Random();
final static int TBullet = 2;
private int RectX0=0,RectY0=0,RectWidth=200,RectHeight=240; //飞行范围
private static final int[] kFrameLookup = {12, 13, 14, 15, 8, 9, 10, 11, 0,
1, 2, 3, 4, 5, 6, 7};
public TrialSprit(Image arg0, int arg1, int arg2, int type) {
super(arg0, arg1, arg2);
mType = type;
mSpeed = 5;
mInternalCnt = mRandom.nextInt() % 10;
this.setPosition(mRandom.nextInt() % RectWidth, mRandom.nextInt() % RectHeight);
}
public TrialSprit() throws IOException {
super(Image.createImage("/bird160X160.png"), 40, 40);
mType = TBullet;
}
public void setRect(int x,int y,int w,int h){
RectX0=x;RectY0=y; RectWidth=w;RectHeight=h;
}
private void turnTo(int dir) {
mDirection = dir;
setFrame(kFrameLookup[mDirection * 4]);
}
private void forward(int delta) {
switch (mDirection) {
case 0 :
move(0, -delta);
break;
case 1 :
move(delta, 0);
break;
case 2 :
move(0, delta);
break;
case 3 :
move(-delta, 0);
break;
}
mFrameIndex = (mFrameIndex + 1) % 4;
setFrame(kFrameLookup[mDirection * 4 + mFrameIndex]);
}
public boolean stepMove() {
if (mStepCnt >= mInternalCnt) {
mStepCnt = 0;
mInternalCnt = mRandom.nextInt() % 20 + 10;
if (getX() > RectWidth)
mDirection = 3;
else if (getX() < RectX0)
mDirection = 1;
else if (getY() > RectHeight)
mDirection = 0;
else if (getY() < RectY0)
mDirection = 2;
else
mDirection = Math.abs(mRandom.nextInt()) % 4;
turnTo(mDirection);
return false;
}
forward(mSpeed);
mStepCnt++;
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -