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

📄 monstersprite.java

📁 j2me RPG手机游戏《征途》的源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
					}else{
						this.setFrameSequence(rd);
						i++;
						if(i==stopTime){
							tempX=x;
							tempY=y;
							this.chgDir();							
						}
					}
				}else{
					if(!this.collidesWith(heroSprite,true)){
						if(isBattle==true){
							isBattle=false;
							this.setFrameSequence(rd_seq);
						}
						if(isStop==true){
							this.setFrameSequence(rd_seq);
							isStop=false;
						}
						if(isWalkable[rdX+1][rdY] && isWalkable[ldX][ldY+1] && isWalkable[rdX][rdY+1]){
							x=x+2;
							y=y+2;
							this.nextFrame();
						}else{
							isSmart=false;
							dir=DIR_LU-1;
							this.setFrameSequence(lu_seq);
						}
					}else{
						isStop=true;						
						if(isBattle==false){
							isBattle=true;							
							this.setFrameSequence(rdb_seq);
							this.nextFrame();
						}else{
							if(j<stopTime-battleSpeed){
								j++;
								isStopb=true;
								this.setFrameSequence(rd);
							}else{
								if(isStopb==true){
									isStopb=false;
									this.setFrameSequence(rdb_seq);
								}								
								if(this.getFrame()==2){
									if(heroHp>0){
										heroHp=heroHp-heroBd;
									}
									j=0;
								}								
								this.nextFrame();
							}
						}
					}
				}
				break;
			case DIR_LD:
				if(!isSmart){
					if(centerDis<moveDis){
						i=0;
						if(isWalkable[ldX-1][ldY] && isWalkable[ldX][ldY+1] && isWalkable[rdX][rdY+1]){
							this.x=this.x-2;
							this.y=this.y+2;
							this.nextFrame();
						}else{
							dir=DIR_RU-1;
							this.setFrameSequence(ru_seq);
						}
					}else{
						this.setFrameSequence(ld);
						i++;
						if(i==stopTime){
							tempX=x;
							tempY=y;
							this.chgDir();							
						}
					}
				}else{
					if(!this.collidesWith(heroSprite,true)){
						if(isBattle==true){
							isBattle=false;
							this.setFrameSequence(ld_seq);
						}
						if(isStop==true){
							this.setFrameSequence(ld_seq);
							isStop=false;
						}
						if(isWalkable[ldX-1][ldY] && isWalkable[ldX][ldY+1] && isWalkable[rdX][rdY+1]){
							x=x-2;
							y=y+2;
							this.nextFrame();
						}else{
							isSmart=false;
							dir=DIR_RU-1;
							this.setFrameSequence(ru_seq);
						}
					}else{
						isStop=true;						
						if(isBattle==false){
							isBattle=true;							
							this.setFrameSequence(ldb_seq);
							this.nextFrame();
						}else{
							if(j<stopTime-battleSpeed){
								j++;
								isStopb=true;
								this.setFrameSequence(ld);
							}else{
								if(isStopb==true){
									isStopb=false;
									this.setFrameSequence(ldb_seq);
								}									
								if(this.getFrame()==2){
									if(heroHp>0){
										heroHp=heroHp-heroBd;
									}
									j=0;
								}								
								this.nextFrame();
							}
						}
					}
				}
				break;
		}			
		isFaced();
		isAttach();
		if(isSmart){
			if(heroDis>10000){
				isSmart=false;
				this.chgDir();
			}
		}
		dx=x-width;
		dy=y-height;
		//this.setPosition(x-width,y-height);				
	  }else{
	  	if(isWaiting==false){
	  		this.setVisible(false);
	  		isWaiting=true;
	  		if(heroHp+lv*lv*4<heroMaxhp){
	  			heroHp=heroHp+lv*lv*4;//怪物死亡时主角血量提升公式
	  			goldOritem=Math.abs(random.nextInt()%2);
	  			goldforhero=lv*15+random.nextInt()%5;
	  			/*
	  			if(goldOritem==0){
	  				g.drawImage(itemImage,x,y,Graphics.TOP|Graphics.LEFT);
	  				System.out.println("是ITEM");
	  			}else{
	  				g.drawImage(goldImage,x,y,Graphics.TOP|Graphics.LEFT);
	  				System.out.println("是GOLD");
	  			}*/
	  		}else{
	  			heroHp=heroMaxhp;
	  		}
	  		deadlv=lv;
	  		isGet=false;
	  	}
	  	if(k<600){
	  		if(k>0){
	  			deadlv=0;
	  		}
	  		k++;
	  	}else{	  
	  		k=0;
	  		isSmart=false;
	  		isAlive=true;	  		
	  		this.setVisible(true);
	  		hp=maxHp;
	  		x=centerX;
	  		y=centerY;
	  	}
	  }	  
	  return heroHp;	
	}	
	
	public boolean isAttach(){
		if(this.collidesWith(heroSprite,true)&&isFaced()&&isAttach){
			if(isSmart==false){
				isSmart=true;
			}
			if(hp>0){
				hp=hp-mBd;
			}else{
				isAlive=false;				
			}
			return true;
		}else
			return false;
	}
	
	
	public boolean isFaced(){		
		if(x==heroX&&y>=heroY){
			if(isSmart&&dir!=DIR_UP-1){				
				dir=DIR_UP-1;
				this.setFrameSequence(up_seq);
			}
			if(heroDir==DIR_DOWN){				
				return true;
			}else return false;
		}else if(x==heroX&&y<heroY){
			if(isSmart&&dir!=DIR_DOWN-1){
				dir=DIR_DOWN-1;
				this.setFrameSequence(down_seq);
			}
			if(heroDir==DIR_UP){								
				return true;
			}else return false;
		}else if(x>heroX&&y>=heroY){
			if((tan041 < (int)(y-heroY)*10000/(x-heroX)) && (tan241 > (int)(y-heroY)*10000/(x-heroX))){
				if(isSmart&&dir!=DIR_LU-1){
					dir=DIR_LU-1;
					this.setFrameSequence(lu_seq);
				}
				if(heroDir==DIR_RD){										
					return true;
				}else	return false;				
			}else if(0<=(int)(y-heroY)*10000/(x-heroX) && (int)(y-heroY)*10000/(x-heroX)<=tan241){
				if(isSmart&&dir!=DIR_LEFT-1){
					dir=DIR_LEFT-1;
					this.setFrameSequence(left_seq);
				}
				if(heroDir==DIR_RIGHT){										
					return true;
				}else	return false;
			}else if((int)(y-heroY)*10000/(x-heroX)>=tan241){
				if(isSmart&&dir!=DIR_UP-1){
					dir=DIR_UP-1;
					this.setFrameSequence(up_seq);
				}
				if(heroDir==DIR_DOWN){					
					return true;
				}else	return false;
			}else return false;
		}else if(x<heroX&&y>=heroY){
			if((-tan241 < (int)(y-heroY)*10000/(x-heroX)) && (-tan041 > (int)(y-heroY)*10000/(x-heroX))){
				if(isSmart&&dir!=DIR_RU-1){
					dir=DIR_RU-1;
					this.setFrameSequence(ru_seq);
				}
				if(heroDir==DIR_LD){
					return true;
				}else	return false;				
			}else if(0>=(int)(y-heroY)*10000/(x-heroX) && (int)(y-heroY)*10000/(x-heroX)>=-tan041){
				if(isSmart&&dir!=DIR_RIGHT-1){
					dir=DIR_RIGHT-1;
					this.setFrameSequence(right_seq);
				}
				if(heroDir==DIR_LEFT){					
					return true;
				}else	return false;
			}else if((int)(y-heroY)*10000/(x-heroX)<=-tan241){
				if(isSmart&&dir!=DIR_UP-1){
					dir=DIR_UP-1;
					this.setFrameSequence(up_seq);
				}
				if(heroDir==DIR_DOWN){					
					return true;
				}else	return false;
			}else return false;
		}else if(x<heroX&&y<=heroY){
			if((tan041 < (int)(y-heroY)*10000/(x-heroX)) && (tan241 > (int)(y-heroY)*10000/(x-heroX))){
				if(isSmart&&dir!=DIR_RD-1){
					dir=DIR_RD-1;
					this.setFrameSequence(rd_seq);
				}
				if(heroDir==DIR_LU){					
					return true;
				}else	return false;				
			}else if(0<=(int)(y-heroY)*10000/(x-heroX) && (int)(y-heroY)*10000/(x-heroX)<=(tan041)){
				if(isSmart&&dir!=DIR_RIGHT-1){
					dir=DIR_RIGHT-1;
					this.setFrameSequence(right_seq);
				}
				if(heroDir==DIR_LEFT){					
					return true;
				}else	return false;
			}else if((int)(y-heroY)*10000/(x-heroX)>=tan241){
				if(isSmart&&dir!=DIR_DOWN-1){
					dir=DIR_DOWN-1;
					this.setFrameSequence(down_seq);
				}
				if(heroDir==DIR_UP){					
					return true;
				}else	return false;
			}else return false;
		}else if(x>heroX&&y<=heroY){
			if((-tan241 < (int)(y-heroY)*10000/(x-heroX)) && (-tan041 > (int)(y-heroY)*10000/(x-heroX))){
				if(isSmart&&dir!=DIR_LD-1){
					dir=DIR_LD-1;
					this.setFrameSequence(ld_seq);
				}
				if(heroDir==DIR_RU){					
					return true;
				}else	return false;				
			}else if(0>=(int)(y-heroY)*10000/(x-heroX) && (int)(y-heroY)*10000/(x-heroX)>=-tan041){
				if(isSmart&&dir!=DIR_LEFT-1){
					dir=DIR_LEFT-1;
					this.setFrameSequence(left_seq);
				}
				if(heroDir==DIR_RIGHT){					
					return true;
				}else	return false;
			}else if((int)(y-heroY)*10000/(x-heroX)<=-tan241){
				if(isSmart&&dir!=DIR_DOWN-1){
					dir=DIR_DOWN-1;
					this.setFrameSequence(down_seq);
				}
				if(heroDir==DIR_UP){					
					return true;
				}else	return false;
			}else return false;
		}else return false;
	}
	
}

⌨️ 快捷键说明

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