⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 worldcanvas.java

📁 J2me横版动作游戏源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				while(ptr!=null){
//					判断下
					if((ptr.x-ptr.width/2)<cre.x-1&&cre.x-1<(ptr.x+ptr.width/2)||(ptr.x-ptr.width/2)<cre.x+1&&cre.x+1<(ptr.x+ptr.width/2)){
						y=ptr.y-ptr.height;
						if(cre.y>=y&&cre.y<=ptr.y){
							cre.y=y;
							GroundTouch=true;
							if(!cre.ifOnGround()){
								cre.OnGround();
								cre.stopFall();
								cre.stopMove();
							}
						}
					}
					int gty=ptr.y-ptr.height;
					int gby=ptr.y;
					int cty=cre.y-cre.height;
					int cby=cre.y;
					if((cty<gty&&gty<cby)||(cty<gby&&gby<cby)||(gty<cby&&cby<gby)||(gty<cty&&cty<gby)){
						//判断左
						if((cre.x-cre.width/2)<ptr.x+ptr.width/2&&cre.x>ptr.x){
							cre.x=ptr.x+ptr.width/2+cre.width/2;
							leftTouch=true;
						}
						//判断右
						if((cre.x+cre.width/2)>ptr.x-ptr.width/2&&cre.x<ptr.x){
							cre.x=ptr.x-ptr.width/2-cre.width/2;
							rightTouch=true;
						}
					}
					ptr=ptr.next;
				}
			}
		}
		if(!GroundTouch){
			cre.LeaveGround();
			cre.increaseFallSpeed(50);
		}
		if(leftTouch){
			cre.CantLeft();
		}
		else{
			cre.CanLeft();
		}
		if(rightTouch){
			cre.CantRight();
		}
		else{
			cre.CanRight();
		}
		if(cre.y>220){
			cre.hp=0;
		}
	}
	protected void drawSpaceGround(int num){
		Ground ptr=null;
		ptr=Grounds[num];
		while(ptr!=null){
			if(ptr.mapid!=0){
				drawgame(ptr.mapid,ptr.x,ptr.y);
				//TODO test
				//
				//
				//
				GIB.setClip(0,0,176,208);
				GIB.setColor(0,0,255);
				GIB.drawRect(ptr.x-ptr.width/2-screenx+1,ptr.y-ptr.height,ptr.width,ptr.height);
			}
			ptr=ptr.next;
		}
	}
	protected void drawSpaceCreature(int num){
		Creature ptr=null;
		ptr=Creatures[num];
		while(ptr!=null){
			if(ptr.mapid!=0){
				drawgame(ptr.getMapID(),ptr.x,ptr.y);
//				TODO test
				//
				//
				//
				GIB.setClip(0,0,176,208);
				GIB.setColor(0,0,255);
				GIB.drawRect(ptr.x-ptr.width/2-screenx+1,ptr.y-ptr.height,ptr.width,ptr.height);
			}
			ptr=ptr.next;
		}
	}
	//TODO LoadMap
	protected void LoadMap(){
		switch(Level){
		case 0:
			LoadMap("map0");
			break;
		case 1:
			LoadMap("map1");
			break;
		case 2:
			LoadMap("map2");
			break;
		}
	}

	protected Ground findGround(Ground gtemp[],int type){
		if(gtemp!=null){
			for(int i=0;i<gtemp.length;++i){
				if(gtemp[i].type==type){
					return gtemp[i];
				}
			}
			return gtemp[0];
		}
		else{
			System.out.println("none");
			return null;
		}
	}
	protected Creature findCreature(Creature gtemp[],int type){
		if(gtemp!=null){
			for(int i=0;i<gtemp.length;++i){
				if(gtemp[i].type==type){
					return gtemp[i];
				}
			}
			return gtemp[0];
		}
		else{
			return gtemp[0];
		}
	}
	protected Ground groundtemp[];
	protected Creature creaturetemp[];
	protected byte Btemp[];
	protected byte Ctemp[];
	protected byte map[];
	protected int i_load;
	protected void LoadMap(String name){
		Btemp=readFile(objectpath,"ground");
		LoadGroundObjInfo(Btemp);
		Ctemp=readFile(objectpath,"creature");
		LoadCreaturObjInfo(Ctemp);
		Btemp=null;
		Ctemp=null;
		i_load=0;
		map=readFile(mappath,name);
		LoadBackGround();
		LoadGround();
		LoadCreature();
		map=null;
	}
	protected void LoadBackGround(){
		CharOP.clear();
		char cha=0;
		boolean key=true;
		while(key){
			cha=CharOP.readUnicode(map[i_load],map[i_load+1]);
			if(cha=='['){
				CharOP.record(cha);
				while(true){
					i_load+=2;
					cha=CharOP.readUnicode(map[i_load],map[i_load+1]);
					CharOP.record(cha);
					if(CharOP.ifrecordis("[map]")){
						i_load+=4;
						key=false;
						break;
					}
				}
			}
			i_load+=2;
		}
		CharOP.clear();
		key=false;
		while(true){
			cha=CharOP.readUnicode(map[i_load],map[i_load+1]);
			if(i_load<map.length-1&&cha==13&&CharOP.readUnicode(map[i_load+2],map[i_load+3])==10){
				i_load+=2;
				key=true;
			}
			if(CharOP.ifrecordis("[end]")){
				i_load+=2;
				break;
			}
			if(key==true){
				try {
					background=Image.createImage(pngpath+new String(CharOP.getChars())+".png");
				} catch (IOException e) {
					e.printStackTrace();
				}
				key=false;
			}
			else{
				CharOP.record(cha);
			}
			i_load+=2;
		}
	}
	protected void LoadGround(){
		CharOP.clear();
		char cha=0;
		boolean key=true;
		while(key){
			cha=CharOP.readUnicode(map[i_load],map[i_load+1]);
			if(cha=='['){
				CharOP.record(cha);
				while(true){
					i_load+=2;
					cha=CharOP.readUnicode(map[i_load],map[i_load+1]);
					CharOP.record(cha);
					if(CharOP.ifrecordis("[ground]")){
						i_load+=4;
						key=false;
						break;
					}
				}
			}
			i_load+=2;
		}
		CharOP.clear();
		int step=-1;
		Ground temp=null;
		Ground module=null;
		key=false;
		while(true){
			cha=CharOP.readUnicode(map[i_load],map[i_load+1]);
			if(cha==32){
				step++;
				key=true;
			}
			if(i_load<map.length-1&&cha==13&&CharOP.readUnicode(map[i_load+2],map[i_load+3])==10){
				step++;
				i_load+=2;
				key=true;
			}
			if(CharOP.ifrecordis("[end]")){
				i_load+=2;
				break;
			}
			if(key==true){
				switch(step){
				case 0:
					temp=new Ground();
					temp.objLive=true;
					temp.sysid=CharOP.getInt();
					break;
				case 1:
					temp.type=CharOP.getInt();
					module=findGround(groundtemp,temp.type);
					temp.width=module.width;
					temp.height=module.height;
					break;
				case 2:
					temp.x=CharOP.getInt();
					break;
				case 3:
					temp.y=CharOP.getInt();
					break;
				case 4:
					temp.AI=CharOP.getInt();
					temp.ai=Grobehavior.CBehavior(temp,temp.AI);
					temp.setMapID();
					addGround(temp);
					step=-1;
					break;
				}
				key=false;
			}
			else{
				CharOP.record(cha);
			}
			i_load+=2;
		}
	}
	protected void LoadCreature(){
		CharOP.clear();
		char cha=0;
		boolean key=true;
		while(key){
			cha=CharOP.readUnicode(map[i_load],map[i_load+1]);
			if(cha=='['){
				CharOP.record(cha);
				while(true){
					i_load+=2;
					cha=CharOP.readUnicode(map[i_load],map[i_load+1]);
					CharOP.record(cha);
					if(CharOP.ifrecordis("[creature]")){
						i_load+=4;
						key=false;
						break;
					}
				}
			}
			i_load+=2;
		}
		CharOP.clear();
		int step=-1;
		Creature temp=null;
		Creature module=null;
		key=false;
		while(true){
			cha=CharOP.readUnicode(map[i_load],map[i_load+1]);
			if(cha==32){
				
				step++;
				key=true;
			}
			if(i_load<map.length-1&&cha==13&&CharOP.readUnicode(map[i_load+2],map[i_load+3])==10){
				step++;
				i_load+=2;
				key=true;
			}
			if(CharOP.ifrecordis("[end]")){
				i_load+=2;
				break;
			}
			if(key==true){
				switch(step){
				case 0:
					temp=new Creature();
					temp.objLive=true;
					temp.sysid=CharOP.getInt();
					break;
				case 1:
					temp.type=CharOP.getInt();
					module=findCreature(creaturetemp,temp.type);
					temp.width=module.width;
					temp.height=module.height;
					temp.step=module.step;
					temp.ActionSpeed=Creature.ckeckSpeed(module.ActionSpeed);
					temp.JumpSpeed=module.JumpSpeed;
					temp.hp=module.hp;
					temp.damage=module.damage;
					temp.sk[0].id=module.sk[0].id;
					temp.sk[0].cool=module.sk[0].cool;
					temp.sk[1].id=module.sk[1].id;
					temp.sk[1].cool=module.sk[1].cool;
					temp.sk[2].id=module.sk[2].id;
					temp.sk[2].cool=module.sk[2].cool;
					break;
				case 2:
					temp.x=CharOP.getInt();
					break;
				case 3:
					temp.y=CharOP.getInt();
					break;
				case 4:
					temp.AI=(byte)CharOP.getInt();
					temp.ai=Crebehavior.CBehavior(temp,temp.AI);
					break;
				case 5:
					temp.side=(byte)CharOP.getInt();
					if(0<temp.x&&temp.x<groundtotal){
						addCreature(temp);
					}
					else{
						System.out.println("out of screen");
					}
					step=-1;
					break;
				}
				key=false;
			}
			else{
				CharOP.record(cha);
			}
			i_load+=2;
		}
	}
	protected void LoadGroundObjInfo(final byte Btemp[]){
		int i=12;
		char cha=0;
		cha=CharOP.readUnicode(Btemp[i],Btemp[i+1]);
		while(true){
			if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
				i+=4;
				break;
			}
			i+=2;
			CharOP.record(cha);
			cha=CharOP.readUnicode(Btemp[i],Btemp[i+1]);
		}
		groundtemp=new Ground[CharOP.getInt()];
		int scount=-1;
		int count=0;
		boolean key=false;
		for(;i<Btemp.length-1;i+=2){
			cha=CharOP.readUnicode(Btemp[i],Btemp[i+1]);
			if(cha==32){
				scount++;
				key=true;
			}
			else if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
				scount++;
				i+=2;
				key=true;
			}
			else if(cha==35){
				break;
			}
			if(key==true){
				switch(scount){
				case 0:
					groundtemp[count]=new Ground();
					groundtemp[count].type=CharOP.getInt();
					break;
				case 1:
					groundtemp[count].width=CharOP.getInt();
					break;
				case 2:
					groundtemp[count].height=CharOP.getInt();
					scount=-1;
					count++;
					break;
				}
				key=false;
			}
			else{
				CharOP.record(cha);
			}
		}
	}
	protected void LoadCreaturObjInfo(final byte Btemp[]){
		String Cname="[";
		String type="类型";
		String width="长";
		String height="宽";
		String step="步长";
		String speed="移动速度";
		String jumpspeed="跳速度";
		String life="生命";
		String damage="伤害";
		String skill1="技能1";
		String skill2="技能2";
		String skill3="技能3";
		int st=0;
		int count=-1;
		boolean key=false;
		boolean minekey=true;
		int i=12;
		char cha=0;
		cha=CharOP.readUnicode(Btemp[i],Btemp[i+1]);
		while(true){
			if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
				i+=4;
				break;
			}
			i+=2;
			CharOP.record(cha);
			cha=CharOP.readUnicode(Btemp[i],Btemp[i+1]);
		}
		int num=CharOP.getInt();
		creaturetemp=new Creature[num];
		while(minekey){
			if(key==true){
				cha=CharOP.readUnicode(Btemp[i],Btemp[i+1]);
				switch(st){
				case 1:
					if(cha==']'){
						creaturetemp[count]=new Creature();
						CharOP.getChars();
						i+=6;
						key=false;
					}
					break;
				case 2:
					if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
						creaturetemp[count].type=CharOP.getInt();
						i+=4;
						key=false;
					}
					break;
				case 3:
					if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
						creaturetemp[count].width=(byte)CharOP.getInt();
						i+=4;
						key=false;
					}
					break;
				case 4:
					if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
						creaturetemp[count].height=(byte)CharOP.getInt();
						i+=4;
						key=false;
					}
					break;
				case 5:
					if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
						creaturetemp[count].step=(byte)CharOP.getInt();
						
						i+=4;
						key=false;
					}
					break;
				case 6:
					if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
						creaturetemp[count].ActionSpeed=CharOP.getInt();
						
						i+=4;
						key=false;
					}
					break;
				case 7:
					if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
						creaturetemp[count].JumpSpeed=CharOP.getInt();
						i+=4;
						key=false;
					}	
					break;
				case 8:
					if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
						creaturetemp[count].hp=CharOP.getInt();
						i+=4;
						key=false;
					}
					break;
				case 9:
					if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
						creaturetemp[count].damage=CharOP.getInt();
						i+=4;
						key=false;
					}
					break;
				case 10:
					if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
						creaturetemp[count].sk[0].id=CharOP.getInt();
						creaturetemp[count].sk[0].cool=damageinfos[creaturetemp[count].sk[0].id].cooldown;
						i+=4;
						key=false;
					}
					break;
				case 11:
					if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
						creaturetemp[count].sk[1].id=CharOP.getInt();
						creaturetemp[count].sk[1].cool=damageinfos[creaturetemp[count].sk[1].id].cooldown;
						i+=4;
						key=false;
					}
					break;
				case 12:
					if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
						creaturetemp[count].sk[2].id=CharOP.getInt();
						creaturetemp[count].sk[2].cool=damageinfos[creaturetemp[count].sk[2].id].cooldown;
						i+=4;
						key=false;
					}
					break;
				}
				if(key==true){
					CharOP.record(cha);
					i+=2;
				}
			}
			else{
				cha=CharOP.readUnicode(Btemp[i],Btemp[i+1]);
				if(cha=='#'){
					minekey=false;
					break;
				}
				if(i<Btemp.length-1&&cha==13&&CharOP.readUnicode(Btemp[i+2],Btemp[i+3])==10){
					i+=4;
					continue;
				}
				else{
					CharOP.record(cha);
				}
				i+=2;
			}
			if(CharOP.ifrecordis(Cname)){
					CharOP.clear();
					count++;
					st=1;
					key=true;
			}
			else if(CharOP.ifrecordis(type)){
				CharOP.clear();
				i+=2;
				st=2;
				key=true;
				
			}
			else if(CharOP.ifrecordis(width)){
				CharOP.clear();
				i+=2;
				st=3;
				key=true;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -