?? 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;//發(fā)連招時的步驟,沒有大招則不用
protected final int lifeMax=10; //角色最大生命值
protected int life; //當(dāng)前生命值
protected int x, y; //當(dāng)前所處位置,y是腳底的坐標(biāo)
protected boolean isBeenAttack; //被打
protected boolean hitFor;//打中對方,碰撞成功后賦值
protected boolean isDied; //死亡
protected int action; //當(dāng)前的行為,比如站立,行走,防御,被打等
protected boolean isWin;//過關(guān)標(biāo)志
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; //當(dāng)前人物的動作在圖像中的索引位置
protected int w, h; //當(dāng)前動作圖像的寬,高
protected int x1,y1;//當(dāng)前人物圖象在大圖片的位置
protected int imgW;//整個圖片的寬度
protected long frameStartTime; //當(dāng)前幀開始時間
protected long oldFrameStartTime;//打中狀態(tài)的起始時間,每次打中后開始記時
protected int frameDelayTime; //當(dāng)前幀持續(xù)時間
int i=0;//通用索引變量
int m=0;//從m開始取得索引,m是從jump()進(jìn)行到哪一貞時候得到的
int m2=0;//普通攻擊態(tài)的記錄索引
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() {//重新使主角的各個屬性值得到恢復(fù),重新定位
bRight=1;//方向向左
life=10;//當(dāng)前生命值
action= ACT_STAND;//當(dāng)前行為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];//只存儲圖片的索引,函數(shù)會處理接下來的事情
//}
//x1=imgdata[id*4];//根據(jù)索引取得初始值
// 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(){//具體朝哪邊滑根據(jù)具體情況而頂
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];//根據(jù)索引取得初始值
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
};
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -