开发工具:
文件大小: 221kb
下载次数: 0
上传时间: 2012-12-03
详细说明: 小剑士import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.Random; import javax.microedition.lcdui.*; import javax.microedition.rms.RecordStore; public class HeroSprite extends ASprite{ public final int LISTENER_LEFT=4; public final int LISTENER_RIGHT=32; public final int LISTENER_UP=2; public final int LISTENER_DOWN=64; public final int LISTENER_FIRE=256; public int dir,hp,maxhp,lv,exp,nextexp,prevexp,itemlv,gold,at,df,mapdir=0; public String MyItem; publ ic boolean isAlive,isAttach,isStop,isBattle,iisBattle,iiisBattle,isStopb,isPause=false;//是否生存以及是否攻击两个判定量 //Sprite HSprite=new Sprite(HeroImage,60,61); public int x,y,luX,luY,ruX,ruY,ldX,ldY,rdX,rdY,stopTime=5,time=0; public Random random=new Random(); public int numEmpty=0; //代表各个方向的常量 public final int DIR_LEFT=2; public final int DIR_DOWN=1; public final int DIR_RIGHT=4; public final int DIR_UP=3; public final int DIR_LU=5; public final int DIR_RU=6; public final int DIR_LD=7; public final int DIR_RD=8; public String DataName; public char itemcode[]={'0','0','0','0','0','0','0','0','0','0','0','0','0'}; //各个方向的图象序列数组 private int up_seq[]={1,2,3,4,5,6,7,8}; private int lu_seq[]={14,15,16,17,18,19,20,21}; private int ru_seq[]={40,41,42,43,44,45,46,47}; private int ld_seq[]={66,67,68,69,70,71,72,73}; private int rd_seq[]={79,80,81,82,83,84,85,86}; private int left_seq[]={92,93,94,95,96,97,98,99}; private int down_seq[]={53,54,55,56,57,58,59,60}; private int right_seq[]={27,28,29,30,31,32,33,34}; public int itemat[]={0,30,70,120,200}; public int itemdf[]={0,20,60,110,190}; private int up[]={0}; private int lu[]={13}; private int ru[]={39}; private int ld[]={65}; private int rd[]={78}; private int left[]={91}; private int down[]={52}; private int right[]={26}; //打斗时候的图象序列数组 public int downb_seq[]={9,10,11,12}; public int upb_seq[]={35,36,37,38}; public int leftb_seq[]={48,49,50,51}; public int rightb_seq[]={61,62,63,64}; private int lub_seq[]={87,88,89,90}; private int rub_seq[]={74,75,76,77}; private int ldb_seq[]={22,23,24,25}; private int rdb_seq[]={100,101,102,103}; public boolean[][] isWalkable; //构造函数 public HeroSprite(Image hImage,int height,int width){ super(hImage,height,width); x=180; y=180; luX=(int)(x/16)+1; luY=(int)(y/16); lv=1; maxhp=160+(lv-1)*40; itemlv=0; gold=0; MyItem="000000000000"; /*for(int i=0;i<12;i++){ itemcode[i]='0'; }*/ //itemcode={'0','0','0','0','0','0','0','0','0','0','0','0','0'}; exp=210; hp=maxhp; at=30; df=20; prevexp=lv*lv*60-(lv-1)*(lv-1)*60+150; nextexp=prevexp+(lv-1)*(lv-1)*60-(lv-2)*(lv-2)*60+150; System.out.print("已装载英雄类"); this.setFrameSequence(down); isAlive=true; System.out.print("英雄类装载完毕"); } public byte[] chgTorms(boolean isFirst) throws IOException{ ByteArrayOutputStream baos=new ByteArrayOutputStream(); DataOutputStream dos=new DataOutputStream(baos); if(itemcode!=null){ MyItem=String.valueOf(itemcode); } dos.writeUTF(String.valueOf(lv));//将具体数据写入流 dos.writeUTF(String.valueOf(itemlv)); dos.writeUTF(String.valueOf(gold)); dos.writeUTF(String.valueOf(MyItem)); dos.writeUTF(String.valueOf(exp)); if(isFirst==false){//如果不是第一次读入数据则计算攻防 at=itemat[itemlv]+(lv-1)*8+30; df=itemdf[itemlv]+(lv-1)*10+20; } baos.close(); dos.close(); numEmpty=0; if(isFirst==false){ for(int i=0;i=nextexp){//目前设定的最高等级为11级 if(lv<12){ lv++; } at=itemat[itemlv]+(lv-1)*8+30; df=itemdf[itemlv]+(lv-1)*10+20; maxhp=160+(lv-1)*40; hp=maxhp; } try{ rs.setRecord(recordid,chgTorms(false),0,chgTorms(false).length); }catch(Exception e){System.out.println(e);} isBattle=false; } } private void getNowHanglie(){//获得主角的行列数值 luX=(int)(x/16)+1; luY=(int)(y/16); ruX=(int)((x+40)/16)+1; ruY=luY; ldX=luX; ldY=(int)((y+40)/16); rdX=ldX; rdY=ldY; } public void chgMapbool(boolean[][] newbool){ this.isWalkable=newbool; } public void doMove(int keyState){ //System.out.println(ldX+","+ldY); if(hp<=0){ this.isAlive=false; } if(this.isAlive){ getNowHanglie(); if(isPause==false){ switch(keyState){ case LISTENER_UP: if(dir!=DIR_UP){//如果按下UP键时之前的状态不是朝UP的话,则改变状态 dir=DIR_UP; this.setFrameSequence(up_seq); } if(isWalkable[ldX][ldY-1] && isWalkable[rdX][rdY-1]){//对下一步的判断 if(isBattle==true){//按下UP键时候如果是打斗状态则转化为UP奔跑帧 this.setFrameSequence(up_seq); isBattle=false; } if(isStop==true){//如果是停止状态也转化为UP奔跑帧 this.setFrameSequence(up_seq); isStop=false; } y=y-5;//坐标变化 this.nextFrame();//帧变化 } break; case LISTENER_DOWN: if(dir!=DIR_DOWN){ dir=DIR_DOWN; this.setFrameSequence(down_seq); } if(isBattle==true){ this.setFrameSequence(down_seq); isBattle=false; } if(isStop==true){ this.setFrameSequence(down_seq); isStop=false; } if(isWalkable[ldX][ldY+1] && isWalkable[rdX][rdY+1]){ y=y+5; this.nextFrame(); } break; case LISTENER_LEFT: if(dir!=DIR_LEFT){ dir=DIR_LEFT; this.setFrameSequence(left_seq); } if(isBattle==true){ this.setFrameSequence(left_seq); isBattle=false; } if(isStop==true){ this.setFrameSequence(left_seq); isStop=false; } if(isWalkable[ldX-1][ldY]){ x=x-5; this.nextFrame(); } break; case LISTENER_RIGHT: if(dir!=DIR_RIGHT){ dir=DIR_RIGHT; this.setFrameSequence(right_seq); } if(isBattle==true){ this.setFrameSequence(right_seq); isBattle=false; } if(isStop==true){ this.setFrameSequence(right_seq); isStop=false; } if(isWalkable[rdX+1][rdY]){ x=x+5; this.nextFrame(); } break; case LISTENER_LEFT+LISTENER_UP: if(dir!=DIR_LU){ dir=DIR_LU; this.setFrameSequence(lu_seq); } if(isBattle==true){ this.setFrameSequence(lu_seq); isBattle=false; } if(isStop==true){ this.setFrameSequence(lu_seq); isStop=false; } if(isWalkable[ldX-1][ldY] && isWalkable[ldX][ldY-1] && isWalkable[rdX][rdY-1]){ x=x-3; y=y-3; this.nextFrame(); } break; case LISTENER_RIGHT+LISTENER_UP: if(dir!=DIR_RU){ dir=DIR_RU; this.setFrameSequence(ru_seq); } if(isBattle==true){ this.setFrameSequence(ru_seq); isBattle=false; } if(isStop==true){ this.setFrameSequence(ru_seq); isStop=false; } if(isWalkable[ldX][ldY-1] && isWalkable[rdX][rdY-1] && isWalkable[rdX+1][rdY]){ x=x+3; y=y-3; this.nextFrame(); } break; case LISTENER_LEFT+LISTENER_DOWN: if(dir!=DIR_LD){ dir=DIR_LD; this.setFrameSequence(ld_seq); } if(isBattle==true){ this.setFrameSequence(ld_seq); isBattle=false; } if(isStop==true){ this.setFrameSequence(ld_seq); isStop=false; } if(isWalkable[ldX-1][ldY] && isWalkable[ldX][ldY+1] && isWalkable[rdX][rdY+1]){ x=x-3; y=y+3; this.nextFrame(); } break; case LISTENER_RIGHT+LISTENER_DOWN: if(dir!=DIR_RD){ dir=DIR_RD; this.setFrameSequence(rd_seq); } if(isBattle==true){ this.setFrameSequence(rd_seq); isBattle=false; } if(isStop==true){ this.setFrameSequence(rd_seq); isStop=false; } if(isWalkable[rdX+1][rdY] && isWalkable[ldX][ldY+1] && isWalkable[rdX][rdY+1]){ x=x+3; y=y+3; this.nextFrame(); } break; case 0: if(isBattle==false){ isStop=true; switch(dir){ case DIR_DOWN: this.setFrameSequence(down); break; case DIR_LEFT: this.setFrameSequence(left); break; case DIR_UP: this.setFrameSequence(up); break; case DIR_RIGHT: this.setFrameSequence(right); break; case DIR_LU: this.setFrameSequence(lu); break; case DIR_RU: this.setFrameSequence(ru); break; case DIR_RD: this.setFrameSequence(rd); break; case DIR_LD: this.setFrameSequence(ld); break; } } break; case LISTENER_FIRE: if(mapdir==1){ switch(dir){ case 1: if(isBattle==false){ this.setFrameSequence(downb_seq); } break; case 2: if(isBattle==false){ this.setFrameSequence(leftb_seq); } break; case 3: if(isBattle==false){ this.setFrameSequence(upb_seq); } break; case 4: if(isBattle==false){ this.setFrameSequence(rightb_seq); } break; case DIR_LU: if(isBattle==false){ this.setFrameSequence(lub_seq); } break; case DIR_LD: if(isBattle==false){ this.setFrameSequence(ldb_seq); } break; case DIR_RU: if(isBattle==false){ this.setFrameSequence(rub_seq); } break; case DIR_RD: if(isBattle==false){ this.setFrameSequence(rdb_seq); } break; } isBattle=true; break; } } if(isBattle==true){ //如果是打斗状态 if(this.getFrame()==2){//如果是打斗状态的第二帧 iiisBattle=true;//打中状态置于真 }else{ iiisBattle=false; } this.nextFrame(); } if(iiisBattle && isBattle){ iisBattle=true; }else{ iisBattle=false; } dx=x; dy=y; } }else{ if(this.exp>150){ this.exp=this.exp-150; }else this.exp=0; } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.