📄 player_west.java~5~
字号:
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
/*
* 创建日期 2006-1-13
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
/**
* @author admin
*
* TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class Player_West extends Sprite
{
GameDataSimple data = WestGameCanvas.data;
int playerState; //当前应该的动作状态
int prePlayerState; //正在运行的状态
private int speedX;
private int speedY;
private int mark;
private int xPlayerInMap;
private int yPlayerInMap;
private int cloudIdx;
private int mapDx, mapDy, dx; //地图移动的位置
private boolean isDownWorld; //判断是否进入地内
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 长面向左<第3贞
{ 5, -59, 46, },//5 长面向左<第4贞
{ 4, -37, -36, },//6 长面向右>第3贞
{ 5, 53, 44, },//7 长面向右>第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;
//正式移动,不出边界
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;
//除了上跳动作以外的其他动作和地面的碰撞检测
isDownWorld = false;
changeMapY();
}
void paintSelf(Graphics g)
{
if ((this.playerState & 64) > 0 && this.imgWeapon != null)
{
//短:左右平;长:左右平
//索引 0 1 2 3 4 5
weaponIdx = this.getFrame();
//判断是否是出棍的贞
if (weaponIdx == 3 || weaponIdx == 4)
{
//短面向左攻击
if ((this.playerState & 1) > 0)
weaponIdx -= 3;
//短面向右攻击
else
weaponIdx -= 1;
//判断随机条件,如果当前时间为奇数,将短棒变长棒索引
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:
//判断如果下一个动作是举着石头的站立状态,就扔出石头
if ((768 & prePlayerState) != 0)
playerState = 1024 + (1 & prePlayerState);
//判断当前状态允不允许攻击
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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -