📄 roleman.java
字号:
import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.lcdui.*;
public class RoleMan extends RoleBase{
/***
* private short[][] xxxx = new short[][]{
子图 x1,x2,y1,y2, ox(偏移X),oy(偏移X),mirx(镜象X偏移动),miry(mirx(镜象Y偏移动))
{72,157,91,189,-2,2,0,0},
};
* **/
private short[][] rToL = new short[][]{
{0,40,27,72,0,1,0,1},
// {38,42,61,74,0,1,0,1},
// {68,41,90,74,0,1,0,1}
};
private short[][] wentDown = new short[][]{
{0,305,28,329,-5,10,-5,10},
{35,309,62,329,-4,14,-4,14},
//{69,309,95,329,0,14,0,0},
{104,343,130,363,-3,14,-3,14}
};
private short[][] readyMagic = new short[][]{
{72,157,91,189,-2,2,0,2},
//{100,156,123,189,-6,1},
{128,157,156,189,-11,2,0,2},
{159,157,182,189,-6,2,0,2},
{186,157,207,189,-4,2,0,2}
};
private short[][] walk = new short[][]{
{0,82,20,117,0,1,0,1},
{33,83,56,117,0,1,0,1},
{64,84,87,117,0,1,0,1},
{91,83,118,117,0,1,0,1},
{120,83,145,117,0,1,0,1}
};
private short[][] stand= new short[][]{
{0,0,17,35,0,-1,0,-1},
{36,0,53,35,0,-1,0,-1},
{69,0,87,35,0,-1,-1,-1}
};
private short[][] stop = new short[][]{
{1,121,25,153,0,2,-6,2},
{27,122,50,153,0,3,-6,3},
// {54,121,78,153,0,2,0,0},
{83,120,104,153,0,1,-6,1}
};
private short[][] paAtt = new short[][]{
{9,84,38,117,-9,1,0,1},
{54,83,83,116,-9,1,0,1},
{90,81,140,114, -17,1,-15,1}, //-*
{155,80,206,113,-17,1,-16,1},
{220,79,255,112,-13,1,-4,1},
{272,82,301,115,-10,1,-1,1},
{254,127,279,160,-7,1,0,1}
/*X1=0 Y1=92 X2=42 Y2=125
X1=58 Y1=92 X2=84 Y2=125
X1=111 Y1=92 X2=136 Y2=125
X1=166 Y1=92 X2=188 Y2=125
X1=219 Y1=92 X2=240 Y2=125
X1=271 Y1=92 X2=292 Y2=125
42 0 x2 -x1 1-2 1-3 1-4
26 16
25 17
22 20
21 21
21 21*/
};
private short[][] startDrop = new short[][]{
{0,230,27,261,0,0,0,0},
{35,229,61,260,0,0,0,0},
{67,228,94,261,0,0,0,0}
};
private short[][] group = new short[][]{
{1,192,29,224,0,0,0,0},
{35,193,62,225,0,0,0,0}
};
private short[][] droping = new short[][]{
{98,297,123,331,0,0,0,0},
{126,297,152,331,0,0,0,0}
};
private short[][] orgJump = new short[][]{
{4,154,23,188,0,0,0,0},
{26,154,44,189,0,0,0,0},
{48,154,67,189,0,0,0,0}
};
private short[][] jump = new short[][]{
{1,192,29,224,0,0,0,0},
{35,193,62,225,0,0,0,0}
};
private short[][] downPlAtt = new short[][]{
{6,138,35,159,-3,14,0,14},
{53,140,101,159,-7,15,-13,15},
{110,139,139,159,-2,15,0,15},
{164,139,189,159,1,15,0,15},
{216,139,242,159,0,15,0,15}
};
private short[][] jumpAtt = new short[][]{
{8,273,32,306,-6,0,0,0},
{44,273,68,306,-6,0,0,0},
{73,273,124,306,-14,0,-19,0},
{133,273,165,306,-6,0,-8,0},
{176,273,202,306,-5,0,-3,0}
};
private short[][] bruise = new short[][]{
{0,265,25,297,-4,2,-4,2},
{0,265,25,297,-4,2,-4,2},
{32,264,53,297,-2,1,-2,1}
};
private short[][] con_bruise = new short[][]{
{38,331,63,364,-2,2,-6,2},
{70,330,95,364,-2,2,-6,2}
};
private short[][] air_con_bruise = new short[][]{
{38,331,63,364,-2,2,-6,2},
// {70,330,95,364,-2,2,-6,2}
};
private short[][] flick = new short[][]{
{0,331,28,364,-4,0,-4,0}
};
private short[][] downGroud = new short[][]{
{0,305,28,329,0,11,0,11},
{35,309,62,329,0,14,0,14},
{69,309,95,329,0,14,0,14},
};
private short[][] wentDownHit = new short[][]{
{135,344,164,362,0,16,0,16},
{135,344,164,362,0,16,0,16},
// X1=135 Y1=344 X2=164 Y2=362
};
private short[][] relseMagic = new short[][]{
{133,226,160,259,-2,2,-7,2},
{163,226,190,259,-3,2,-6,2}
};
private short[][] air_relseMagic = new short[][]{
{90,261,132,294,-15,0,-10,0},
{136,261,162,294,-7,0,-2,0},
{165,261,191,294,-6,0,-3,0}
};
private short[][] dead = new short[][]{
{100,40,126,73,0,0,0,0},
{101,0,129,33,0,0,0,0},
{150,0,175,32,0,0,0,0},
{149,43,186,71,0,11,0,11}
};
/** 角色状态划分 ******************/
static final byte LEFT_STAND = 0; //左站立
static final byte RIGHT_STAND = 1;//右站立
static final byte L_TO_R_FRO = 2; //向右转身
static final byte R_TO_L_FRO = 3; //向左转生
static final byte LEFT_WALK = 4; //向左走
static final byte RIGHT_WALK = 5; //向右走
static final byte LEFT_TO_STOP = 6; //向左走停下
static final byte RIGHT_TO_STOP = 7;//向右走停下
static final byte LEFT_READY_RELEASE = 8; //向左准备释放魔法状态
static final byte RIGHT_READY_RELEASE = 9;//向右准备释放魔法状态
static final byte LEFT_ORIGIN_JUMP = 10; //向左原地跳跃
static final byte RIGHT_ORIGIN_JUMP = 11;//向右原地跳跃
static final byte LEFT_JUMP = 12; //向左跳
static final byte RIGHT_JUMP = 13;//向右跳
static final byte LEFT_START_DROP = 14; //向左开始下落
static final byte RIGHT_START_DROP = 15;//向右开始下落
static final byte LEFT_CONTINUANCE_DROP = 16; //向左持续下落
static final byte RIGHT_CONTINUANCE_DROP = 17;//向右持续下落
static final byte LEFT_FALL_GROUND = 18; //向左落地
static final byte RIGHT_FALL_GROUND = 19;//向右落地
static final byte LEFT_GROUND_LIGHTHIT = 20; //向左地上受到轻击
static final byte RIGHT_GROUND_LIGHTHIT = 21;//向右地上受到轻击
static final byte LEFT_G_BACK_LIGHTHIT = 22; //向左地上 背后 受到轻击
static final byte RIGHT_G_BACK_LIGHTHIT = 23;//向右地上 背后 受到轻击
static final byte LEFT_GROUND_BANG = 24; //向左地上受到 重击
static final byte RIGHT_GROUND_BANG = 25;//向右地上受到 重击
static final byte LEFT_G_BACK_BANG = 26; //向左地上 背后 受到 重击
static final byte RIGHT_G_BACK_BANG = 27;//向右地上 背后 受到 重击
static final byte LEFT_AIR_HIT = 28; //向左空中受到攻击
static final byte RIGHT_AIR_HIT = 29;//向右空中受到攻击
static final byte LEFT_AIR_BACK_HIT = 30; //向左空中 背后 受到攻击
static final byte RIGHT_AIR_BACK_HIT = 31;//向右空中 背后 受到攻击
static final byte LEFT_COLG_JUMP = 32; //向左跳遇到障碍
static final byte RIGHT_COLG_JUMP = 33;//向右跳遇到障碍
static final byte LEFT_TOP_COLG = 34; //向左跳 上方遇到 障碍
static final byte RIGHT_TOP_COLG = 35;//向右跳 上方遇到 障碍
static final byte LEFT_AIR_RELEASE = 36; //向左空中释放魔法
static final byte RIGHT_AIR_RELEASE = 37;//向右空中释放魔法
static final byte LEFT_GROUND_RELEASE = 38; //向左地面释放魔法
static final byte RIGHT_GROUND_RELEASE = 39;//向右地面释放魔法
static final byte LEFT_DUCK_BASE = 40; //向左 蹲下 拳头攻击基本模式
static final byte RIGHT_DUCK_BASE = 41;//向右 蹲下 拳头攻击基本模式
static final byte LEFT_DOWN_DUCK = 42; //向左 地上 拳头攻击基本模式
static final byte RIGHT_DOWN_DUCK = 43;//向右 地上 拳头攻击基本模式
static final byte LEFT_AIR_DUCK = 44; //向左 空中 拳头攻击基本模式
static final byte RIGHT_AIR_DUCK = 45; //向右 空中 拳头攻击基本模式
static final byte LEFT_CREESE_BASE = 46; //向左 蹲下 短剑攻击基本模式
static final byte RIGHT_CREESE_BASE = 47;//向右 蹲下 短剑攻击基本模式
static final byte LEFT_DOWN_CREESE = 48; //向左 地上 短剑攻击基本模式
static final byte RIGHT_DOWN_CREESE = 49;//向右 地上 短剑攻击基本模式
static final byte LEFT_AIR_CREESE = 50; //向左 空中 短剑攻击基本模式
static final byte RIGHT_AIR_CREESE = 51; //向右 空中 短剑攻击基本模式
static final byte LEFT_DEAD = 52; //向左角色死亡
static final byte RIGHT_DEAD = 53;//向右角色死亡
static final byte LEFT_WENT_DOWN = 54; //向左蹲下
static final byte RIGHT_WENT_DOWN = 55;//向右蹲下
static final byte LEFT_LIE_DOWN = 56; //特殊:角色躺下
static final byte RIGHT_DOWN_GROUND = 57;//向右被击飞 或 高空 落地
static final byte LEFT_DOWN_GROUND = 58;//向左被击飞 或 高空 落地
static final byte LEFT_WENTDOWN_HIT = 59; //左蹲被攻击
static final byte RIGHT_WENTDOWN_HIT = 60;//右蹲被攻击
//未完待续。。。。。
private byte direction;//FORE 0 ,BACK 1
private String name;
private Image roleBase;
private Image attRole;
/*** 定义角色的自生属性 ****************************/
private short backHp,backMp;//后台的血,实际血量
private short hp,mp; //显示在前台的血,用于实现动画效果
private short maxHp,maxMp;//最大HP,MP
private short str,con,$int,lck;//力量,耐久,智力,幸运
private short att,def;//att=(str+wep) def=(con/2+wep)
private byte lv;
private int exp,nextExp;//总经验,下一级所要经验
private String $state;
final byte speedY = 7;
/*** 定义游戏的其他属性 ****************************/
private int gold;
private byte rateB,rateS;//游戏地图百分比 0.0%~100.0% mapB.mapS%; mapB0~100 mapS0~9
private byte hour,min,sec;//游戏总时间
private byte sHour,sMin,sSec;//游戏开始时间
/*****当前装备********************************/
protected Magic currMainMagic;//当前魔法
private byte fCount;
private boolean aphal;//设置无敌
private long sAphal;//记录开始无敌的时间
static final short reMpTime = 3000;
private long mpTimeStart;//记录回蓝时间
private boolean isResume;
private short hitX,hitY;//与武器,魔法碰撞到点
private SpEffect blood;
static Vector shot;
public RoleMan(short x,short y)
{
name = "来须 苍真";
this.roleX = x;
this.roleY = y;
mapX = CastleCanvas.map.getPosX();
mapY = CastleCanvas.map.getPosY();
this.x = (short)(roleX-mapX);
this.y = (short)(roleY-mapY);
roleBase = CastleCanvas.createImage("RoleBase");
attRole = CastleCanvas.createImage("attack");
initAction();
roleInit();
changState(RIGHT_STAND);
vY = speedY;
aphal = true;
shot = new Vector();
}
private void initAction()
{
actionFrame = new byte[]{ //记录各个动作的最大帧数
(byte)stand.length,//左站立
(byte)stand.length,//右站立
(byte)rToL.length,//向右转身
(byte)rToL.length,//向左转身
(byte)walk.length, //向左走
(byte)walk.length, //向右走
(byte)stop.length,//向左走停下
(byte)stop.length,//向右走停下
(byte)readyMagic.length,//向左准备释放魔法状态
(byte)readyMagic.length,//向右准备释放魔法状态
(byte)orgJump.length,//向左原地跳跃
(byte)orgJump.length,//向右原地跳跃
(byte)jump.length,//向左跳
(byte)jump.length,//向右跳
0,//向左开始下落
0,//向右开始下落
(byte)droping.length,//向左持续下落
(byte)droping.length,//向右继续下落
(byte)startDrop.length,//向左落地
(byte)startDrop.length,//向右落地
(byte)bruise.length, //向左地上受到轻击
(byte)bruise.length, //向右地上受到轻击
(byte)con_bruise.length,//向左地上 背后 受到轻击
(byte)con_bruise.length,//向右地上 背后 受到轻击
0,//向左地上受到 重击
0,//向右地上受到 重击
(byte)bruise.length,//向左地上 背后 受到 重击
(byte)bruise.length,//向右地上 背后 受到 重击
(byte)flick.length,//向左空中受到攻击
(byte)flick.length,//向右空中受到攻击
(byte)air_con_bruise.length, //向左空中 背后 受到攻击
(byte)air_con_bruise.length,//向右空中 背后 受到攻击
0, //向左跳遇到障碍
0,//向右跳遇到障碍
0,//向左跳 上方遇到 障碍
0,//向右跳 上方遇到 障碍
(byte)air_relseMagic.length,//向左空中释放魔法
(byte)air_relseMagic.length,//向右空中释放魔法
(byte)relseMagic.length,//向左地面释放魔法
(byte)relseMagic.length,//向右地面释放魔法
0,//向左蹲下拳头攻击基本模式
0,//向右蹲下拳头攻击基本模式
0,//向左 地上 拳头攻击基本模式
0,//向右 地上 拳头攻击基本模式
0,//向左 空中 拳头攻击基本模式
0,//向右 空中 拳头攻击基本模式
(byte)downPlAtt.length,//向左 蹲下 短剑攻击基本模式
(byte)downPlAtt.length,//向右 蹲下 短剑攻击基本模式
(byte)paAtt.length,//向左 地上 短剑攻击基本模式
(byte)paAtt.length,//向右 地上 短剑攻击基本模式
(byte)jumpAtt.length,//向左 空中 短剑攻击基本模式
(byte)jumpAtt.length,//向右 空中 短剑攻击基本模式
(byte)dead.length,//向左角色死亡
(byte)dead.length,//向右角色死亡
(byte)wentDown.length,//向左蹲下
(byte)wentDown.length,//向右蹲下
0, //特殊:角色躺下
(byte)downGroud.length,//向左被击飞 或 高空 落地
(byte)downGroud.length,//向右被击飞 或 高空 落地
(byte)wentDownHit.length,//蹲下被攻击
(byte)wentDownHit.length,
};
}
private void roleInit()
{
speed = 5;
maxHp = 200;
maxMp = 80;
hp = maxHp;
mp = maxMp;
backHp = hp;
backMp = mp;
str = 17;
con = 12;
$int= 11;
lck = 9;
$state = "good";
lv = 1;
att = str;//+wep
def = (short)(con/2);//+防具
exp = 0;
nextExp = 51;
}
public byte getLv()
{
return lv;
}
public short getMaxHp()
{
return maxHp;
}
public short getMaxMp()
{
return maxMp;
}
public short getRealHp()
{
return backHp;
}
public short getRealMp()
{
return backMp;
}
public short getHp()
{
return hp;
}
public short getMp()
{
return mp;
}
public short getAtt()
{
return att;
}
public short getDef()
{
return def;
}
public short getStr()
{
return str;
}
public short getCon()
{
return con;
}
public short getInt()
{
return $int;
}
public short getLuck()
{
return lck;
}
public int getExp()
{
return exp;
}
public int getNextExp()
{
return nextExp;
}
public String getState()
{
return $state;
}
public int getGold()
{
return gold;
}
public byte getRateB()
{
return rateB;
}
public byte getRateS()
{
return rateS;
}
public byte getHour()
{
return hour;
}
public byte getSec()
{
return sec;
}
public byte getmin()
{
return min;
}
public byte getCurrentHpRatio()
{
return (byte)((hp*100)/maxHp);
}
public byte getCurrentMpRatio()
{
return (byte)((mp*100)/maxMp);
}
protected boolean isDead()
{
if(roleState==RoleMan.LEFT_DEAD || roleState == RoleMan.RIGHT_DEAD)
return true;
return false;
}
public void relaseMagic()
{//TODO
if(CastleCanvas.soma.currMainMagic!=null)
{
switch(CastleCanvas.soma.currMainMagic.curMagic)
{
case Magic.FLYDEADHEAD:
if(shot.size()<=0 && backMp >= 10 )//Magic.use
{
backMp -= 10;//MAGID.USE TODO
if(CastleCanvas.soma.dir)
{
shot.addElement(new Bullet(true,roleX,roleY));
}
else
{
shot.addElement(new Bullet(false,roleX,roleY));
}
}
break;
}
}
}
private boolean weaponHit(byte[][] pos,byte fTick,boolean isMir,Enemy e)
{
short weaWidth = (short)(pos[frame-fTick][4]);
short weaHeight = (short)(pos[frame-fTick][5]);
short weaponX = -20;
short weaponY = -20;
if(!isMir)
{
//精准的话,这里要 if(soma.dir)判断一下的主角的方向 TODO
if(dir)
{
weaponX = (short)(x+pos[frame-fTick][0]+ox);
weaponY = (short)(y+pos[frame-fTick][1]+oy);
}
else
{
weaponX = (short)(x+pos[frame-fTick][2]+mirx);
weaponY = (short)(y+pos[frame-fTick][3]+miry);
}
// g.setColor(0xff8822);
// g.setClip(weaponX,weaponY,weaWidth,weaHeight);
// g.fillRect(0,0,176,220);
if(e.x+e.ox+e.imgW-10>weaponX && weaponX+weaWidth>e.x+e.ox && e.y+e.oy+e.imgH>weaponY &&
weaponY+weaHeight>e.y+e.oy-5 )
{
if(e.brState() && !e.isDead())
{
hitX = (short)(weaponX+weaWidth/3+-x+roleX);
hitY = (short)(weaponY-5-y+roleY);
return true;
}
}
}
else
{
if(dir)
{
weaponX = (short)(x+pos[frame-fTick][0]+ox);
weaponY = (short)(y+pos[frame-fTick][1]+oy);
}
else
{
weaponX = (short)(x+pos[frame-fTick][2]+mirx);
weaponY = (short)(y+pos[frame-fTick][3]+miry);
}
// g.setColor(0xff8822);
// g.setClip(weaponX,weaponY,weaWidth,weaHeight);
// g.fillRect(0,0,176,220);
if(e.x+e.mirx+e.imgW-10>weaponX && weaponX+weaWidth>e.x+e.mirx+4 && e.y+e.miry+e.imgH>weaponY &&
weaponY+weaHeight>e.y+e.miry-5)
{
if(e.brState() && !e.isDead())
{
hitX = (short)(weaponX-weaWidth/2-x+roleX);
hitY = (short)(weaponY-5-y+roleY);
return true;
}
}
}
return false;
}
private boolean attckHit(Enemy e)
{
byte[][] posPara = new byte[][]{ //普通
{30,4,0,4,20,5},//0,1为右边攻击的矩形块X,Y,2,3为左边,4,5为宽度和高度
{30,4,0,4,20,5},
{35,6,0,5,12,2},
{31,4,0,4,10,2}
};
byte[][] downPara = new byte[][]{ //地上
{26,4,0,4,21,6},
{20,4,0,4,12,2}
};
byte[][] airPara = new byte[][]{ //空中
{30,-2,0,-2,22,5},
{35,-2,0,-2,15,3},
{35,-2,0,-2,15,3}
};
switch(roleState)
{
case RIGHT_DOWN_CREESE:
if(frame>1 && frame<6)
{
return weaponHit(posPara,(byte)2,false,e);
}
break;
case LEFT_DOWN_CREESE:
if(frame>1 && frame<6)
{
return weaponHit(posPara,(byte)2,true,e);
}
break;
case RIGHT_AIR_CREESE:
if(frame>1 && frame<5)
{
return weaponHit(airPara,(byte)2,false,e);
}
break;
case LEFT_AIR_CREESE:
if(frame>1 && frame<5)
{
return weaponHit(airPara,(byte)2,true,e);
}
break;
case RIGHT_CREESE_BASE:
if(frame>0 && frame<3)
{
return weaponHit(downPara,(byte)1,false,e);
}
break;
case LEFT_CREESE_BASE:
if(frame>0 && frame<3)
{
return weaponHit(downPara,(byte)1,true,e);
}
break;
}
return false;
}
private void attHitEnemy()
{
Enumeration v = CastleCanvas.enemy.elements();
while(v.hasMoreElements())
{
Enemy e = (Enemy)(v.nextElement());
if(attckHit(e))
{
//其他处理,伤血,死亡
short brHp = 0;
if(e instanceof Corpse)
{
Corpse c = ((Corpse)e);
brHp = (short)(att-c.def);
if(brHp<1)
brHp = 1;
c.hp -= brHp;
if(c.hp <= 0)
{//TODO
exp += c.getExp();
c.dead();
}
}
else if(e instanceof BrawnMan)
{
BrawnMan b = (BrawnMan)e;
brHp = (short)(att-b.def);
if(brHp<1)
brHp = 1;
b.hp -= brHp;
if(b.hp <= 0)
{
exp += b.getExp();
b.dead();
}
}
else if(e instanceof Bat)
{
Bat b = (Bat)e;
brHp = (short)(att-b.def);
if(brHp<1)
brHp = 1;
b.hp -= brHp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -