?? brawnman.java
字號:
import javax.microedition.lcdui.Graphics;
public class BrawnMan extends Enemy{
static final byte LEFT_MOVE = 0; //向左移動
static final byte RIGHT_MOVE = 1;//向右移動
static final byte LEFT_ATTACK = 2;
static final byte RIGHT_ATTACK = 3;
static final byte DEAD = 4; //左死亡
private static final byte DELETE = 5;//刪除對象
byte att,def;
byte hp;
public BrawnMan()
{
initAction();// must be first
initBase();
}
private void initBase() {
setRoleY((short)171);
changState(BrawnMan.LEFT_MOVE);
att = 17;
def = 4;
hp = 28;
exp = 12;
brTime = 400;
speed = 2;
}
private short[][] walk = new short[][]{
{1,80,34,117,0,0,0,0},
{41,80,72,117,0,0,0,0},
{79,80,112,117,0,0,0,0},
{114,80,147,117,0,0,0,0},
{151,80,182,117,0,0,0,0},
{182,80,215,117,0,0,0,0},
{219,81,252,117,0,0,0,0}
};
private short[][] attack = new short[][]{
{0,123,34,159,0,1,0,1},
{39,124,73,159,0,2,0,2},
{76,124,109,159,-1,2,2,2},
{114,123,173,158,4,2,-30,2},
{178,123,247,158,0,2,-36,2}
};
protected boolean isDead() {
if(enemyState == DEAD)
{
return true;
}
return false;
}
private void tickAI()
{
boolean can = false;
short dis = (short)(CastleCanvas.soma.roleX-roleX);
if(Math.abs(dis)<105)
can = true;//在攻擊范圍之內
if(dis>0 && can && hp > 0)
{
if(Math.abs(dis)<=30)
{
if(enemyState!=RIGHT_ATTACK)
changState(RIGHT_ATTACK);
}
else
{
if(enemyState!=RIGHT_MOVE)
changState(RIGHT_MOVE);
move();
}
}
else if(dis<0 && can && hp > 0)
{
if(Math.abs(dis)<=30)
{
if(enemyState!=LEFT_ATTACK)
changState(LEFT_ATTACK);
}
else
{
if(enemyState!=LEFT_MOVE)
changState(LEFT_MOVE);
move();
}
}
}
public void paint(Graphics g) {
tickEnemyXY();
tickAI();
if(x<190 && x>-20 && y>-20 && y<240)
switch(enemyState)
{
case LEFT_MOVE:
drawLeftWalk(g);
setDir(false);
break;
case RIGHT_MOVE:
drawRightWalk(g);
setDir(true);
break;
case LEFT_ATTACK:
drawLeftAttack(g);
break;
case RIGHT_ATTACK:
drawRightAttack(g);
break;
case DEAD:
drawDead(g);
changWaitState(DELETE);
break;
case DELETE:
CastleCanvas.enemy.removeElement(this);
break;
}
}
private void drawLeftWalk(Graphics g)
{
tickArgmentMirror(walk,(byte)6);
drawLeftRole(g,enemy);
}
private void drawRightWalk(Graphics g)
{
tickArgment(walk,(byte)6);
drawRightRole(g,enemy);
}
private void drawLeftAttack(Graphics g)
{
tickArgmentMirror(attack,(byte)4);
drawLeftRole(g,enemy);
}
private void drawRightAttack(Graphics g)
{
tickArgment(attack,(byte)4);
drawRightRole(g,enemy);
}
private void drawDead(Graphics g)
{
tickArgmentMirror(dead);
drawLeftRole(g,enemy);
}
protected void dead() {
if(enemyState!=DEAD)
{
changState(DEAD);
}
}
private void initAction() {
actionFrame = new byte[]{
(byte)walk.length,
(byte)walk.length,
(byte)attack.length,
(byte)attack.length,
(byte)dead.length,
0,
};
}
public boolean hit(RoleBase r) {
short x = (short)(this.x+9);
byte w = 10;
byte h = 36;
// System.out.println("x:"+x+"y:"+y);
if(dir)
{
if(x+w>r.x+r.ox && r.x+17+r.ox>x && y+h>r.y && r.y+r.imgH+r.oy>y)
return true;
}
else
{
if(x+w>r.x && r.x+17+r.mirx>x && y+h>r.y && r.y+r.imgH+r.miry>y)
return true;
}
return false;
}
private boolean weaponHit(byte[][] pos,byte fTick,boolean isMir)
{
short weaWidth = (short)(pos[frame-fTick][4]);
short weaHeight = (short)(pos[frame-fTick][5]);
RoleMan e = CastleCanvas.soma;
if(!isMir)
{
short weaponX = (short)(x+pos[frame-fTick][0]+ox);
short weaponY = (short)(y+pos[frame-fTick][1]+oy);
if(CastleCanvas.soma.dir)
{
if(e.x+e.ox+e.imgW>weaponX && weaponX+weaWidth>e.x+e.ox && e.y+e.oy+e.imgH>weaponY &&
weaponY+weaHeight>e.y+e.oy )
{
if(e.getAphal() && !e.isDead())
{
return true;
}
}
}
else
{
if(e.x+e.mirx+e.imgW>weaponX && weaponX+weaWidth>e.x+e.mirx+4 && e.y+e.miry+e.imgH>weaponY &&
weaponY+weaHeight>e.y+e.miry)
{
if(e.getAphal() && !e.isDead())
{
return true;
}
}
}
}
else
{
short weaponX = (short)(x+pos[frame-fTick][2]+mirx);
short weaponY = (short)(y+pos[frame-fTick][3]+miry);
if(CastleCanvas.soma.dir)
{
if(e.x+e.ox+e.imgW>weaponX && weaponX+weaWidth>e.x+e.ox && e.y+e.oy+e.imgH>weaponY &&
weaponY+weaHeight>e.y+e.oy )
{
if(e.getAphal() && !e.isDead())
{
return true;
}
}
}
else
{
if(e.x+e.mirx+e.imgW>weaponX && weaponX+weaWidth>e.x+e.mirx+4 && e.y+e.miry+e.imgH>weaponY &&
weaponY+weaHeight>e.y+e.miry)
{
if(e.getAphal() && !e.isDead())
{
return true;
}
}
}
}
return false;
}
private boolean attckHit()
{
byte[][] att = new byte[][]{ //普通
{28,5,0,5,35,6},//0,1為右邊攻擊的矩形塊,2,3為左邊,4,5為寬度和高度
{35,7,0,7,38,6}
};
switch(enemyState)
{
case LEFT_ATTACK:
if(frame>2)
return weaponHit(att,(byte)3,true);
break;
case RIGHT_ATTACK:
if(frame>2)
return weaponHit(att,(byte)3,false);
break;
}
return false;
}
public boolean attack()
{
if(attckHit())
return true;
return false;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -