文件名称:J2ME小游戏源代码
文件大小:221KB
文件格式:ZIP
更新时间:2015-12-24 11:20:44
剑士
小剑士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;
public 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
【文件预览】:
Tales
----tmpclasses()
--------MonsterSprite.class(21KB)
--------ASprite.class(553B)
--------HeroSprite.class(9KB)
--------MapTiled.class(29KB)
--------Tales.class(2KB)
--------NPCSprite.class(1KB)
--------SFCanvas.class(23KB)
----bin()
--------MANIFEST.MF(170B)
--------Tales.jad(211B)
----src()
--------ASprite.java(436B)
--------MapTiled.java(23KB)
--------Tales.java(913B)
--------MonsterSprite.java(30KB)
--------HeroSprite.java(11KB)
--------NPCSprite.java(841B)
--------SFCanvas.java(35KB)
----tmplib()
----project.properties(47B)
----res()
--------blood.png(2KB)
--------box.png(1013B)
--------bar.png(306B)
--------npc1.png(741B)
--------load1.png(2KB)
--------mainch.png(35KB)
--------load2.png(1KB)
--------menumain.png(1KB)
--------house_01.png(6KB)
--------npc.png(1KB)
--------1212.png(9KB)
--------monster.png(32KB)
--------item.png(4KB)
--------bloodti.png(243B)
--------gold.png(727B)
--------menu.png(3KB)
--------shop.png(7KB)
--------house_02.png(3KB)
--------map2.png(13KB)
--------title.png(11KB)
----lib()
----classes()
--------MonsterSprite.class(23KB)
--------ASprite.class(553B)
--------HeroSprite.class(9KB)
--------MapTiled.class(29KB)
--------Tales.class(2KB)
--------NPCSprite.class(1KB)
--------SFCanvas.class(25KB)