?? character.java
字號:
//package bushfighting;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Graphics;
/*
這個類用于處理場景中人物的基本行為
*/
public class Character extends SceneUnit {
protected int mState = HF.STATE_STILL;
protected int mFrameIndex = 0; //當前的動作號,對應不同方向的行走姿態
protected int mPicIndex = 0;//當前的圖片索引號
protected int mAttackDelay = 0;//每次攻擊之間的延時間隔
protected boolean mHurtCount =false;
protected int desX;
protected int desY;
protected Image[] mImages = null;
protected int[] mFrames = null;
public Character( int[] imgFrames) {
super();
desX= -1;
desY= -1;
//mImages = images;
mFrames = imgFrames;
}
public void setImages(Image[] images) {
mImages = images;
}
//設置角色的狀態的方向
protected void setState(int state) {
if(state>=HF.STATE_MOVE_UP&&state<=HF.STATE_MOVE_RIGHT){
if(state == HF.STATE_MOVE_UP||state == HF.STATE_MOVE_DOWN) {
if(mDirection == HF.STATE_MOVE_LEFT) {
mPicIndex = mDirection;
mDirection = state;
} else if(mDirection == HF.STATE_MOVE_LEFT) {
mPicIndex = mDirection;
mDirection = state;
} else if(mDirection == HF.STATE_MOVE_UP||mDirection == HF.STATE_MOVE_DOWN) {
mDirection = state;
}
} else {
mDirection = state;
mPicIndex = state;
}
} else if(state == HF.STATE_ATTACK) {
if(mPicIndex==HF.STATE_MOVE_LEFT) {
mDirection = HF.STATE_MOVE_LEFT;
} else if(mPicIndex==HF.STATE_MOVE_RIGHT) {
mDirection = HF.STATE_MOVE_RIGHT;
}
} else if(mDirection != HF.STATE_MOVE_LEFT){
mDirection = HF.STATE_MOVE_RIGHT;//默認的方向向右
}
if(state == HF.STATE_ATTACK){
mFrameIndex = 0;
if(mDirection == HF.STATE_MOVE_LEFT){
mPicIndex = 6;
} else{
mPicIndex = 7;
}
} else if(state == HF.STATE_DIE){
mFrameIndex = 0;
if(mDirection == HF.STATE_MOVE_LEFT){
mPicIndex = 4;
} else{
mPicIndex = 5;
}
}
mState = state;
}
//切換動作幀
protected void setFrame() {
if(mState != HF.STATE_STILL)
mFrameIndex = (mFrameIndex+1)%mFrames[mPicIndex];
if(mFrameIndex== 0&&mState == HF.STATE_DIE){
mUsed = false;//顯示死亡的樣子完畢后,標記未不存在
}
if(mFrameIndex == 0&&mState == HF.STATE_ATTACK){
//等到攻擊的狀態結束后,自動切換成靜止狀態
mState = HF.STATE_STILL;
mPicIndex = mDirection;
}
}
protected void setPictureIndex(int index) {
mPicIndex = index;
mFrameIndex = 0;
}
//繪制角色
public void draw(Graphics g) {
if(mType == HF.PLAYER&&mHurtCount ==true) {
Image img;
int fCount;
if(mPicIndex%2==0) {
img = mImages[4];
fCount = mFrames[4];//當前圖片含有的幀數目
} else {
img = mImages[5];
fCount = mFrames[5];//當前圖片含有的幀數目
}
int width = img.getWidth()/fCount;
int height = img.getHeight();
int x = mX - width/2;
int y = mY - height/2;
mHurtCount = false;
g.setClip(x,y,width,height);
if(mPicIndex%2==0){
g.drawImage(img,x,y,Graphics.LEFT|Graphics.TOP);
}
else{
g.drawImage(img,x-width,y,Graphics.LEFT|Graphics.TOP);
}
} else {
// if(mType == HF.PLAYER && mState==HF.STATE_ATTACK){
// if()
// }
Image img = mImages[mPicIndex];
int fCount = mFrames[mPicIndex];//當前圖片含有的幀數目
int width = img.getWidth()/fCount;
int height = img.getHeight();
int x = mX - width/2;
int y = mY - height/2;
g.setClip(x,y,width,height);
int tmf=mFrameIndex;
if(mPicIndex == 3 || mPicIndex == 5 || mPicIndex == 7){
tmf=fCount-mFrameIndex-1;
}
g.drawImage(img,x-tmf*width,y,Graphics.LEFT|Graphics.TOP);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -