📄 human.java
字号:
import com.nokia.mid.ui.DirectGraphics;
import com.nokia.mid.ui.DirectUtils;
import javax.microedition.lcdui.*;
public class Human extends MovingObject
{
static final int LEG_OFFSET = 3;
protected int MAX_HP;
protected int DEFAULT_ATT_POWER;
protected int DEFAULT_DEF_POWER;
protected Image img;
protected String name;
protected int hp;
protected int actionId;
protected int drawImgId;
protected int actionScript;
protected int actionScriptLength;
protected int dalayAction;
protected int bodyOffsetX;
protected int curPosY;
protected int actionImgWidth;
protected boolean isMoving;
protected boolean isKeyHold;
protected int invisible;
protected int attWidth;
protected int attHeight;
protected Rectangle attArea;
protected Rectangle legArea;
protected int attPower;
protected int defPower;
protected int damage;
protected int explosionStage;
protected int numWeapon;
protected int weaponId;
protected int gauge;
protected int newItem;
protected int itemStock[];
protected boolean canMoveUp;
protected boolean canMoveDown;
protected boolean canMoveLeft;
protected boolean canMoveRight;
protected int oldDirection;
protected int msgTimer;
protected String msg[];
public Human(int objType, int locX, int locY, int width, int height)
{
super(objType, locX, locY, width, height);
MAX_HP = 100;
DEFAULT_ATT_POWER = 5;
DEFAULT_DEF_POWER = 4;
img = null;
hp = 10;
actionId = 0;
drawImgId = 0;
actionScript = 0;
actionScriptLength = 0;
dalayAction = 2;
bodyOffsetX = 0;
curPosY = 0;
actionImgWidth = 0;
isMoving = true;
isKeyHold = false;
invisible = 0;
attWidth = 34;
attHeight = 25;
attArea = null;
legArea = null;
attPower = DEFAULT_ATT_POWER;
defPower = DEFAULT_DEF_POWER;
damage = 0;
explosionStage = 0;
numWeapon = 0;
weaponId = 0;
gauge = 0;
newItem = -1;
itemStock = null;
canMoveUp = true;
canMoveDown = true;
canMoveLeft = true;
canMoveRight = true;
oldDirection = -1;
msgTimer = 0;
msg = null;
super.speedX = 4;
super.speedY = 4;
curPosY = super.curLoc.GetY() + super.curLoc.GetHeight();
itemStock = new int[18];
for(int i = 0; i < itemStock.length; i++)
{
itemStock[i] = -1;
}
itemStock[0] = 0;
numWeapon = 1;
SetWeaponId(0);
}
public void Initial(String name, int objType, String imgURL, int maxHP, int actImgWidth)
{
try
{
img = Image.createImage(imgURL);
}
catch(Exception ioe)
{
return;
}
Initial(name, objType, img, maxHP, actImgWidth);
}
public void Initial(String name, int objType, Image playerImg, int maxHP, int actImgWidth)
{
this.name = name;
SetType(objType);
SetMaxHP(maxHP);
SetHP(maxHP);
actionImgWidth = actImgWidth;
bodyOffsetX = (super.curLoc.GetWidth() - actionImgWidth) / 2;
super.direction = 1;
SetAction(0);
if(GetType() == 20 || GetType() == 22)
{
attWidth = 34;
attHeight = 25;
attArea = new Rectangle(GetLocationX(), GetLocationY(), attWidth, attHeight);
} else
{
attWidth = 30;
attHeight = 30;
attArea = new Rectangle(GetLocationX(), GetLocationY(), attWidth, attHeight);
}
legArea = new Rectangle();
SetLocation(super.curLoc.GetX(), super.curLoc.GetY());
int bodyWidth = super.curLoc.GetWidth();
legArea.SetWidth(bodyWidth);
legArea.SetHeight(bodyWidth);
try
{
img = playerImg;
if(MovingObject.weaponImg == null)
{
MovingObject.weaponImg = Image.createImage("/Images/Player/menu.png");
}
}
catch(Exception ioe)
{
return;
}
}
public void Run()
{
if(gauge > 0)
{
gauge--;
}
if(GetHP() <= 0 && GetAction() != 7)
{
SetAction(7);
} else
{
if(IsDead())
{
return;
}
if(invisible > 0)
{
invisible--;
}
}
isMoving = false;
switch(actionId)
{
case 0: // '\0'
default:
break;
case 1: // '\001'
if(--dalayAction <= 0)
{
if(++actionScript > actionScriptLength)
{
if(isKeyHold)
{
SetAction(1);
} else
{
ChangeAction(0);
}
} else
{
if(actionScript == 2)
{
drawImgId = 2;
} else
{
drawImgId = 0;
}
dalayAction = 2;
}
}
super.moveDis = MoveToDirection(super.speedX, true);
break;
case 2: // '\002'
if(--dalayAction <= 0)
{
if(++actionScript > actionScriptLength)
{
if(isKeyHold)
{
SetAction(2);
} else
{
ChangeAction(0);
}
} else
{
if(actionScript == 2)
{
drawImgId = 2;
} else
{
drawImgId = 0;
}
dalayAction = 1;
}
}
super.moveDis = MoveToDirection(super.speedX + 2, true);
break;
case 3: // '\003'
if(--dalayAction > 0)
{
break;
}
if(++actionScript > actionScriptLength)
{
if(isKeyHold)
{
SetAction(3);
} else
{
ChangeAction(0);
}
} else
{
drawImgId++;
dalayAction = GetType() != 21 || drawImgId != 5 ? 2 : 4;
}
break;
case 5: // '\005'
if(--dalayAction > 0)
{
break;
}
if(++actionScript > actionScriptLength)
{
ChangeAction(0);
} else
{
dalayAction = 20;
}
break;
case 4: // '\004'
if(--dalayAction <= 0)
{
ChangeAction(0);
} else
{
super.moveDis = MoveToDirection(8, true);
}
break;
case 6: // '\006'
if(--dalayAction <= 0)
{
if(++actionScript > actionScriptLength)
{
invisible = 20;
ChangeAction(0);
} else
{
drawImgId = 1;
dalayAction = 2;
}
} else
{
super.moveDis = MoveOppositeDirection(GetType() != 22 ? 2 + dalayAction * 3 : 2 + dalayAction * 4, false);
}
break;
case 7: // '\007'
if(--dalayAction <= 0)
{
if(++actionScript > actionScriptLength)
{
super.destroy = true;
} else
{
drawImgId = 1;
dalayAction = 7;
}
break;
}
if(actionScript <= 0)
{
super.moveDis = MoveOppositeDirection(2 + dalayAction * 3, false);
}
break;
case 8: // '\b'
if(--dalayAction <= 0)
{
if(++actionScript > actionScriptLength)
{
ChangeAction(0);
} else
if(actionScript < 4)
{
drawImgId++;
dalayAction = drawImgId != 5 ? 6 : 25;
} else
{
drawImgId--;
dalayAction = 3;
}
}
if(drawImgId == 5)
{
super.moveDis = MoveToDirection(super.speedX * 2, true);
}
break;
case 9: // '\t'
case 10: // '\n'
if(--dalayAction > 0)
{
break;
}
if(++actionScript > actionScriptLength)
{
ChangeAction(0);
newItem = -1;
} else
{
dalayAction = 4;
}
break;
}
}
public void Reset()
{
super.Reset();
super.destroy = false;
isKeyHold = false;
hp = 10;
actionId = 0;
actionScript = 0;
actionScriptLength = 0;
drawImgId = 0;
dalayAction = 0;
curPosY = 0;
invisible = 0;
damage = 0;
explosionStage = 0;
gauge = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -