📄 actor_move.java
字号:
/*
* Actor_Move.java
*
* Created on 2006年4月20日, 下午2:28
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
import javax.microedition.lcdui.*;
/**
*
* @author Administrator
*/
public class Actor_Move {
// public int step;//发连招时的步骤,没有大招则不用
protected final int lifeMax=10; //角色最大生命值
protected int life; //当前生命值
protected int x, y; //当前所处位置,y是脚底的坐标
protected boolean isBeenAttack; //被打
protected boolean hitFor;//打中对方,碰撞成功后赋值
protected boolean isDied; //死亡
protected int action; //当前的行为,比如站立,行走,防御,被打等
protected boolean isWin;//过关标志
protected int bRight; //为True表示人物面向右,为False则面向左
public static final int ACT_STAND = 0; //站立
public static final int ACT_LEFT = 20;
public static final int ACT_RIGHT = 21;
public static final int ACT_DOWN = 22;
public static final int ACT_UP = 23;
protected Image img; //人物的各种动作图像
// protected Image headImg; //角色的头像,显示血条所用
protected int id; //当前人物的动作在图像中的索引位置
protected int w, h; //当前动作图像的宽,高
protected int x1,y1;//当前人物图象在大图片的位置
protected int imgW;//整个图片的宽度
protected long frameStartTime; //当前帧开始时间
protected long oldFrameStartTime;//打中状态的起始时间,每次打中后开始记时
protected int frameDelayTime; //当前帧持续时间
int i=0;//通用索引变量
int m=0;//从m开始取得索引,m是从jump()进行到哪一贞时候得到的
int m2=0;//普通攻击态的记录索引
int moveX;//取位移差
int moveY;//取位移差
boolean attackTure=false;//一次性变量
protected int stop_frame;
/** Creates a new instance of Actor_Move */
public Actor_Move() {
x=10;
y=50;//人物初始位置
init();
try{
img=Image.createImage("/man3.png");
}catch(Exception e){}
imgW=img.getWidth();
}
public void init() {//重新使主角的各个属性值得到恢复,重新定位
bRight=1;//方向向左
life=10;//当前生命值
action= ACT_STAND;//当前行为ACT_LEFT;///
this.setAction(action);
}
public int getAction(){
return action;
}
public void setstopframe(int frame){
this.stop_frame = frame;
}
public void setDirection(int direction){
bRight=direction;
}
void upDate(){//其目的就是在每次画人物之前处理好将要用到的图片的id,x,y,w,h,imgw
if(action == this.ACT_LEFT){
leftmove();
}else if(action == this.ACT_RIGHT){
rightmove();
}else if(action == this.ACT_DOWN){
downmove();
}else if(action == this.ACT_UP){
upmove();
}else if(action==ACT_STAND){//站立
doStand();
}
}
public static final int[] actStand=new int[]{//站立
//44,500,
//45,500
1,500,
4,500,
6,500,
9,500
};
public static final int[] left_move = {
0,100,1,0,
1,100,1,0,
2,100,1,0
};
public static final int[] right_move ={
3,100,1,0,
4,100,1,0,
5,100,1,0
};
public static final int[] down_move = {
6,100,0,1,
7,100,0,1,
8,100,0,1
};
public static final int[] up_move = {
9,100,0,1,
10,100,0,1,
11,100,0,1
};
public void draw(Graphics g){
upDate();
try{
g.setClip(x,y,w,h);//画小图片
g.drawImage(img,x-x1,y-y1,Graphics.LEFT|Graphics.TOP);//画大图片
g.setClip(0, 0, 176, 208);
}catch (Exception e) {}
}
public void setAction(int act){
moveX=0;
moveY=0;
action=act;
i=0;//通用索引
//frameStartTime=System.currentTimeMillis();//通用记录起始时间
// if(act ==this.ACT_LEFT){//左边
/// id = left_move[0];
// //}else if(act == this.ACT_RIGHT){
// id = right_move[0];
// }else if(act == this.ACT_DOWN){
/// id = down_move[0];
/// }else if(act == this.ACT_UP){
// id = up_move[0];
// }else if(act==ACT_STAND){
// id=actStand[0];//只存储图片的索引,函数会处理接下来的事情
//}
//x1=imgdata[id*4];//根据索引取得初始值
// y1=imgdata[id*4+1];
//w=imgdata[id*4+2];
//h=imgdata[id*4+3];
}
public int getX(){
return x;
}
public int getY(){
return y;
}
void setX(int x){
this.x=x;
}
void setY(int y){
this.y=y;
}
public void doDrop(){
y=y+4;
}
void doUnder(){//具体朝哪边滑根据具体情况而顶
x=x+2;
y=y+2;
}
void doStand(){
if(System.currentTimeMillis()-frameStartTime>actStand[stop_frame*2+1]){//比较延迟时间
frameStartTime=System.currentTimeMillis();
id=actStand[stop_frame*2];
x1=imgdata[id*4];//根据索引取得初始值
y1=imgdata[id*4+1];
w=imgdata[id*4+2];
h=imgdata[id*4+3];
}
}
void leftmove(){
if(System.currentTimeMillis() - frameStartTime >=this.left_move[i*4+1]){//比较延迟时间
i++;
if(i>2)
i=0;
frameStartTime = System.currentTimeMillis();
id = left_move[i*4];
x1 = imgdata[id*4];
y1 = imgdata[id*4+1];
w = imgdata[id*4+2];
h = imgdata[id*4+3];
moveX = left_move[i*4+2];//得到位移偏差;
moveY = left_move[i*4+3];
//y += moveY;
}
x -= moveX;
}
void rightmove(){
if(System.currentTimeMillis() - frameStartTime >= this.right_move[i*4+1]){//比较延迟时间
i++;
if(i>2)
i=0;
frameStartTime = System.currentTimeMillis();
id = right_move[i*4];
x1 = imgdata[id*4];
y1 = imgdata[id*4+1];
w = imgdata[id*4+2];
h = imgdata[id*4+3];
moveX = right_move[i*4+2];
moveY = right_move[i*4+3];
// y += moveY;
}
x += moveX;
}
void downmove(){
if(System.currentTimeMillis() - frameStartTime >=this.down_move[i*4+1]){//比较延迟时间
i++;
if(i>2)
i=0;
frameStartTime = System.currentTimeMillis();
id = down_move[i*4];
x1 = imgdata[id*4];
y1 = imgdata[id*4+1];
w = imgdata[id*4+2];
h = imgdata[id*4+3];
moveX = down_move[i*4+2];//得到位移偏差;
moveY = down_move[i*4+3];
// x += moveX;
}
y += moveY;
}
void upmove(){
if(System.currentTimeMillis() - frameStartTime >=this.up_move[i*4+1]){//比较延迟时间
i++;
if(i>2)
i=0;
frameStartTime = System.currentTimeMillis();
id = up_move[i*4];
x1 = imgdata[id*4];
y1 = imgdata[id*4+1];
w = imgdata[id*4+2];
h = imgdata[id*4+3];
moveX = up_move[i*4+2];//得到位移偏差;
moveY = up_move[i*4+3];
//x += moveX;
}
y -= moveY;
}
public static final short[] imgdata ={
4,0,19,30,//左
30,0,18,30,//停
54,0,19,30,
78,0,18,30,//右
103,0,18,30,//停
129,0,17,30,
154,0,17,30,//下 停
177,0,18,30,
204,0,18,30,
228,1,18,29,//上 停
253,0,19,30,
279,0,19,30
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -