?? player_west.java~3~
字號(hào):
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
/*
* 創(chuàng)建日期 2006-1-13
*
* TODO 要更改此生成的文件的模板,請(qǐng)轉(zhuǎn)至
* 窗口 - 首選項(xiàng) - Java - 代碼樣式 - 代碼模板
*/
/**
* @author admin
*
* TODO 要更改此生成的類(lèi)型注釋的模板,請(qǐng)轉(zhuǎn)至 窗口 - 首選項(xiàng) - Java - 代碼樣式 - 代碼模板
*/
public class Player_West extends Sprite
{
GameDataSimple data = WestGameCanvas.data;
int playerState; //當(dāng)前應(yīng)該的動(dòng)作狀態(tài)
int prePlayerState; //正在運(yùn)行的狀態(tài)
private int speedX;
private int speedY;
private int mark;
private int xPlayerInMap;
private int yPlayerInMap;
private int cloudIdx;
private int mapDx, mapDy, dx; //地圖移動(dòng)的位置
private boolean isDownWorld; //判斷是否進(jìn)入地內(nèi)
public Image imgWeapon[];
private byte[][] weaponIdxXY = {//
//0:img索引,1:x偏移,2:y偏移
{ 0, 43, -22, },//0 短面向左<第3貞
{ 2, -43, 46, },//1 短面向左<第4貞
{ 1, -25, -24, },//2 短面向右>第3貞
{ 2, 53, 44, },//3 短面向右>第4貞
{ 3, 43, -34, },//4 長(zhǎng)面向左<第3貞
{ 5, -59, 46, },//5 長(zhǎng)面向左<第4貞
{ 4, -37, -36, },//6 長(zhǎng)面向右>第3貞
{ 5, 53, 44, },//7 長(zhǎng)面向右>第4貞
};
private int weaponIdx;
/**
* @param id
* @param image
* @param frameWidht
* @param frameHeight
*/
public Player_West(int id, Image image, int frameWidht, int frameHeight)
{
super(id, image, frameWidht, frameHeight);
jbInit();
}
void jbInit()
{
prePlayerState = playerState = 2;
setCurrSequence(data.getPlayer()[24], data.getPlayer()[25]);
speedX = speedY = mark = 0;
cloudIdx = -1;
}
void moveSelf()
{
if (WestGameCanvas.hp <= 0)
{
playerState = 32 + (1 & prePlayerState);
if ((32 & prePlayerState) != 0 && getFrame() == 0)
{
setFrame(getFrameSequenceLength() - 1);
}
}
if ((64 & prePlayerState) != 0)
{
if (getFrame() == getFrameSequenceLength() - 1)
{
playerState = playerState - 64;
}
}
if ((128 & prePlayerState) != 0)
{
mark--;
if (mark <= 0)
{
playerState = 2 + (1 & prePlayerState);
}
}
nextFrame();
setFinalSequence(false);
if ((24 & prePlayerState) != 0)
{
if (mark >= data.playerJump()[0].length || mark < 0)
{
playerState = 16 + (prePlayerState & 65);
}
else
{
speedX = data.playerJump()[1][mark];
speedY = data.playerJump()[0][mark];
if ((8 & prePlayerState) == 8)
{
speedY = -speedY;
}
if ((1 & prePlayerState) == 1)
{
speedX = -speedX;
}
if ((8 & prePlayerState) != 0)
{
mark++;
if (mark >= data.playerJump()[0].length)
{
playerState = 16 + (prePlayerState & 65);
}
}
if ((16 & prePlayerState) != 0)
{
mark--;
if (mark < 0)
{
mark = 0;
}
}
}
}
if ((1024 & prePlayerState) != 0)
{
mark--;
if (mark <= 0)
{
playerState = (1 & prePlayerState) + 2;
}
}
mapDx = WestGameCanvas.mapX;
mapDy = WestGameCanvas.mapY;
dx = x;
//正式移動(dòng),不出邊界
WestGameCanvas.mapY -= speedY;
yPlayerInMap = y - WestGameCanvas.mapY;
if (-WestGameCanvas.mapX >= data.getWorldMessage()[5]
&& -WestGameCanvas.mapX <= data.getWorldMessage()[6]
&& yPlayerInMap >= data.getWorldMessage()[7])
{
moveMap(data.getWorldMessage()[5], data.getWorldMessage()[6]);
}
else
{
moveMap(0, data.getWorldMessage()[4]);
}
if (x < 0)
x = 0;
else if (x > WestGameCanvas.screenWidth - srcFrameWidth)
x = WestGameCanvas.screenWidth - srcFrameWidth;
//除了上跳動(dòng)作以外的其他動(dòng)作和地面的碰撞檢測(cè)
isDownWorld = false;
changeMapY();
}
void paintSelf(Graphics g)
{
if ((this.playerState & 64) > 0 && this.imgWeapon != null)
{
//短:左右平;長(zhǎng):左右平
//索引 0 1 2 3 4 5
weaponIdx = this.getFrame();
//判斷是否是出棍的貞
if (weaponIdx == 3 || weaponIdx == 4)
{
//短面向左攻擊
if ((this.playerState & 1) > 0)
weaponIdx -= 3;
//短面向右攻擊
else
weaponIdx -= 1;
//判斷隨機(jī)條件,如果當(dāng)前時(shí)間為奇數(shù),將短棒變長(zhǎng)棒索引
if ((System.currentTimeMillis() & 1) > 0)
weaponIdx += 4;
g.setClip(this.x - 59, this.y - 36, 172, 86);
g.drawImage(this.imgWeapon[this.weaponIdxXY[weaponIdx][0]],
this.x + this.weaponIdxXY[weaponIdx][1], this.y
+ this.weaponIdxXY[weaponIdx][2], 0);
}
}
this.paint(g);
}
void keyPress(int key)
{
switch (key)
{
case WestGameCanvas.KEY_NUM0:
break;
case WestGameCanvas.KEY_NUM1:
if ((24 & playerState) == 0)
playerState = 9 + (prePlayerState & 64);
break;
case WestGameCanvas.KEY_NUM2:
case WestGameCanvas.KEYCODE_DIRECT_UP:
if (prePlayerState > 1 && prePlayerState < 6)
playerState = 256 + (1 & prePlayerState);
break;
case WestGameCanvas.KEY_NUM3:
if ((24 & playerState) == 0)
playerState = 8 + (prePlayerState & 64);
break;
case WestGameCanvas.KEY_NUM4:
case WestGameCanvas.KEYCODE_DIRECT_LEFT:
if ((768 & prePlayerState) != 0)
{
playerState = 513;
}
else if ((24 & prePlayerState) == 0)
{
playerState = 5 + (prePlayerState & 64);
}
break;
case WestGameCanvas.KEY_NUM5:
case WestGameCanvas.KEYCODE_DIRECT_FIRE:
//判斷如果下一個(gè)動(dòng)作是舉著石頭的站立狀態(tài),就扔出石頭
if ((768 & prePlayerState) != 0)
playerState = 1024 + (1 & prePlayerState);
//判斷當(dāng)前狀態(tài)允不允許攻擊
else if (((254 & prePlayerState) > 0 && (254 & prePlayerState) < 32))
playerState = 64 + prePlayerState;
break;
case WestGameCanvas.KEY_NUM6:
case WestGameCanvas.KEYCODE_DIRECT_RIGHT:
if ((768 & prePlayerState) != 0)
{
playerState = 512;
}
else if ((24 & prePlayerState) == 0)
{
playerState = 4 + (prePlayerState & 64);
}
break;
case WestGameCanvas.KEY_NUM7:
break;
case WestGameCanvas.KEY_NUM8:
case WestGameCanvas.KEYCODE_DIRECT_DOWN:
break;
case WestGameCanvas.KEY_NUM9:
break;
}
}
void keyRelease(int key)
{
//----------------------------------------------test
switch (key)
{
case WestGameCanvas.KEY_NUM4:
case WestGameCanvas.KEYCODE_DIRECT_LEFT:
if ((prePlayerState & 5) == 5)
{
playerState = 3 + (64 & prePlayerState);
}
if (prePlayerState == 513)
{
playerState = 257;
}
break;
case WestGameCanvas.KEY_NUM6:
case WestGameCanvas.KEYCODE_DIRECT_RIGHT:
if ((prePlayerState & 4) == 4)
{
playerState = 2 + (64 & prePlayerState);
}
if (prePlayerState == 512)
{
playerState = 256;
}
break;
}
}
//TODO isCollideWith
void isColl(Npc_Bound npc)
{
//defineCollisionRectangle(0,0,srcFrameWidth,srcFrameHeight);
int npcLen=npc.npc.length;
int i;
if (cloudIdx != -1)
{
int idUse = -1;
for (i = npcLen; --i >= 0;)
{
if (null != npc.npc[i])
{
if (npc.npc[i].num == cloudIdx)
{
if (x + 26 < npc.npc[i].x
|| x + 26 > npc.npc[i].x
+ npc.npc[i].srcFrameWidth
|| y + 54 < npc.npc[i].y
|| y + 54 > npc.npc[i].y
+ npc.npc[i].srcFrameHeight)
{
cloudIdx = -1;
}
else
idUse = i;
break;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -