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

📄 player.java

📁 这是自己设计的一款java泡泡游戏。 这是自己设计的一款java泡泡游戏。这是自己设计的一款java泡泡游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				{
					for(m=0;m<pScence.getPlayerNum();m++)
					if(!pScence.getPlayer(m).getDead() 
						&& pScence.getPlayer(m).collidesWith(new Rectangle2D.Double
						(20+40*j,40+40*(i-1),40,40)))
					{return false;}
				}
				return true;
			case 1:
				if(j-1<0 || pScence.fraises[i][j-1]!=null)
				{return false;}
				else 
				{
					for(m=0;m<pScence.getPlayerNum();m++)
					if(!pScence.getPlayer(m).getDead() 
						&&pScence.getPlayer(m).collidesWith(new Rectangle2D.Double
						(20+40*(j-1),40+40*i,40,40)))
					{return false;}
				}
				return true;
			case 2:
				if(i+1>=13 || pScence.fraises[i+1][j]!=null)
				{return false;}
				else 
				{
					for(m=0;m<pScence.getPlayerNum();m++)
					for(int k=0;k<4;k++)
						if(!pScence.getPlayer(m).getDead() 
							&&pScence.getPlayer(m).collidesWith(new Rectangle2D.Double
							(20+40*j,40+40*(i+1),40,40)))
					    {return false;}
				}
				return true;
			case 3:
				if(j+1>=15 || pScence.fraises[i][j+1]!=null)
				{return false;}
				else 
				{
					for(m=0;m<pScence.getPlayerNum();m++)
					for(int k=0;k<4;k++)
						if(!pScence.getPlayer(m).getDead() 
							&&pScence.getPlayer(m).collidesWith(new Rectangle2D.Double
							(20+40*(j+1),40+40*i,40,40)))
					    {return false;}
				}
				return true;
		}//end switch
		return false;
	}
	
	public boolean goSide(int i,int t)
	{
		boolean re = true;
		Fraise f = pScence.fraises[currHoldIGes[i]][currHoldJGes[i]];
		switch(t)
		{
			//0上,1左,2下,3右
			case 0:
			case 2:
				if(getX()+39<f.getX()+20)
				{
					re = false;
					if(currHoldJGes[i]-1>=0 
						&&(pScence.fraises[currHoldIGes[i]][currHoldJGes[i]-1]==null
							|| (pScence.fraises[currHoldIGes[i]][currHoldJGes[i]-1].moving)
							|| (pScence.fraises[currHoldIGes[i]][currHoldJGes[i]-1].canMove 
								&& this.canMove(currHoldIGes[i],currHoldJGes[i]-1,t))))
					{
						int x,y;
						if(this.getX()-speed-5>f.getX()-40)
						{
							x = -1*(speed+5);
							y = 0;
						}
						else 
						{
							x = f.getX()-40-getX();
							y = 0;
						}
						moveBy(x,y);
						this.updateBounds();
						if((pScence.fraises[currIGe][currJGe]!=null
								&& (!pScence.fraises[currIGe][currJGe].ifPP
									||((PaoPao)pScence.fraises[currIGe][currJGe]).psIn[id]==false) 
							 	&& collidesWith(pScence.fraises[currIGe][currJGe]))
							|| (currJGe-1>=0 && pScence.fraises[currIGe][currJGe-1]!=null
								&& (!pScence.fraises[currIGe][currJGe-1].ifPP
									|| ((PaoPao)pScence.fraises[currIGe][currJGe-1]).psIn[id]==false)
								&& collidesWith(pScence.fraises[currIGe][currJGe-1])))
						{
							moveBy(-1*x,-1*y);
							this.updateBounds();
						}
					}
				}
				else if(getX()>f.getX()+20)
				{
					re = false;
					if(currHoldJGes[i]+1<15 
						&&(pScence.fraises[currHoldIGes[i]][currHoldJGes[i]+1]==null 
							||pScence.fraises[currHoldIGes[i]][currHoldJGes[i]+1].moving
							||(pScence.fraises[currHoldIGes[i]][currHoldJGes[i]+1].canMove&&
								this.canMove(currHoldIGes[i],currHoldJGes[i]+1,t))))
					{
						int x,y;
						if(this.getX()+speed+5<f.getX()+40)
						{
							x = speed+5;
							y = 0;
						}
						else 
						{
							x = f.getX()+40-getX();
							y = 0;
						}
						moveBy(x,y);
						this.updateBounds();
						if((pScence.fraises[currIGe][currJGe]!=null 
								&& (!pScence.fraises[currIGe][currJGe].ifPP 
									||((PaoPao)pScence.fraises[currIGe][currJGe]).psIn[id]==false) 
								&& collidesWith(pScence.fraises[currIGe][currJGe]))
							|| (currJGe+1<15 && pScence.fraises[currIGe][currJGe+1]!=null 
								&& (!pScence.fraises[currIGe][currJGe+1].ifPP 
									||((PaoPao)pScence.fraises[currIGe][currJGe+1]).psIn[id]==false) 
								&& collidesWith(pScence.fraises[currIGe][currJGe+1])))
						{
							moveBy(-1*x,-1*y);
							this.updateBounds();
						}
					}
				} 
				goBack(i,t);
				return re;
			case 1:
			case 3:
				if(getY()+39<f.getY()+20)
				{
					re = false;
					if(currHoldIGes[i]-1>=0
						 &&(pScence.fraises[currHoldIGes[i]-1][currHoldJGes[i]]==null
						 	||pScence.fraises[currHoldIGes[i]-1][currHoldJGes[i]].moving
						 	||(pScence.fraises[currHoldIGes[i]-1][currHoldJGes[i]].canMove &&
								this.canMove(currHoldIGes[i]-1,currHoldJGes[i],t))))
					{
						//System.out.print("下移"+getX()+","+getY());
						int x,y;
						if(this.getY()-speed-5>f.getY()-40)
						{
							x = 0;
							y = -1*(speed+5);
						}
						else 
						{
							x = 0;
							y = f.getY()-40-getY();
						}
						moveBy(x,y);
						this.updateBounds();
						//System.out.print(":"+getX()+","+getY());
						if((pScence.fraises[currIGe][currJGe]!=null 
								&& (!pScence.fraises[currIGe][currJGe].ifPP
									|| ((PaoPao)pScence.fraises[currIGe][currJGe]).psIn[id]==false) 
								&& collidesWith(pScence.fraises[currIGe][currJGe]))
							|| (currIGe-1>0 && pScence.fraises[currIGe-1][currJGe]!=null 
								&& (!pScence.fraises[currIGe-1][currJGe].ifPP
									|| ((PaoPao)pScence.fraises[currIGe-1][currJGe]).psIn[id]==false) 
								&& collidesWith(pScence.fraises[currIGe-1][currJGe])))
						{
							moveBy(-1*x,-1*y);
							this.updateBounds();
						}
						//System.out.println(":"+getX()+","+getY());
					}
				}
				else if(getY()>f.getY()+20)
				{
					re = false;
					if(currHoldIGes[i]+1<13 
						&&(pScence.fraises[currHoldIGes[i]+1][currHoldJGes[i]]==null 
							||pScence.fraises[currHoldIGes[i]+1][currHoldJGes[i]].moving
							||(pScence.fraises[currHoldIGes[i]+1][currHoldJGes[i]].canMove &&
								this.canMove(currHoldIGes[i]+1,currHoldJGes[i],t))))
					{
						//System.out.print("上移"+getX()+","+getY());
						int x,y;
						if(this.getY()+speed+5>f.getY()+40)
						{
							x = 0;
							y = speed+5;
						}
						else 
						{
							x = 0;
							y = f.getY()+40-getY();
						}
						moveBy(x,y);
						this.updateBounds();
						//System.out.print(":"+getX()+","+getY());
						if((pScence.fraises[currIGe][currJGe]!=null 
								&& (!pScence.fraises[currIGe][currJGe].ifPP
									|| ((PaoPao)pScence.fraises[currIGe][currJGe]).psIn[id]==false)
								&& collidesWith(pScence.fraises[currIGe][currJGe]))
							|| (currIGe+1<13 && pScence.fraises[currIGe+1][currJGe]!=null 
								&& (!pScence.fraises[currIGe+1][currJGe].ifPP
									|| ((PaoPao)pScence.fraises[currIGe+1][currJGe]).psIn[id]==false)
								&& collidesWith(pScence.fraises[currIGe+1][currJGe])))
						{
							moveBy(-1*x,-1*y);
							this.updateBounds();
						}
						//System.out.print(":"+getX()+","+getY());
					}
				} 
				goBack(i,t);
				return re;
		}
		return false;
	}
	
	public void goBack(int i,int t)
	{
		Fraise f = pScence.fraises[currHoldIGes[i]][currHoldJGes[i]];
		//0上,1左,2下,3右
		switch(t)
		{
			case 0:
				setY(f.getY()+40);
				break;
			case 1:
				setX(f.getX()+40);
				break;
			case 2:
				setY(f.getY()-40);
				break;
			case 3:
			 	setX(f.getX()-40);
				break;
		}
		this.updateBounds();
	}
	
	public void updateGe()
	{
		currJGe = getX()/40;//处在左右两格的正中间则取右
		currIGe = (getY()-20)/40;//处在上下两格正中间则取下
		
		this.currHoldJGes[0] = (getX()-20)/40;
		this.currHoldIGes[0] = (getY()-40)/40;
		this.currHoldJGes[1] = (getX()+19)/40;
		this.currHoldIGes[1] = currHoldIGes[0];
		this.currHoldJGes[2] = currHoldJGes[0];
		this.currHoldIGes[2] = (getY()-1)/40;
		this.currHoldJGes[3] = currHoldJGes[1];
		this.currHoldIGes[3] = currHoldIGes[2];
	}
	
	public void setNextAnimation(AnimationStrip next,int mode)
	{
		this.next = next;
		this.nextMode = mode;
		this.needChange = true;
	}
	
	public void changeCurrAnimation()
	{
		if(this.needChange)
		{
			System.out.println("cc");
			currAnimation = next;
			currAnimator = next.createNewAnimator();
			setAnimateMode(nextMode);
			needChange = false;
		}
	}
	
	//设置动画模式
	public void setAnimateMode(int AnimateMode)
	{
		switch(AnimateMode)
		{
			case AnimateMode_WAIT:
				//System.out.println("wait");
				this.AnimateHelpState_Wait 	   = true;
				this.AnimateHelpState_NoFazeMe = false;
				this.AnimateHelpState_Buffer   = false;
				if(!dead && deading )
					this.dead();
				else if(this.dead) 
				{
					//System.out.println("destroyed");
					currAnimator.setCurrIndex(currAnimator.getFrames().size()-1);
					destryed = true;
				}
				break;
			case AnimateMode_AUTOPLAY:
				this.AnimateHelpState_Wait 	   = false;
				this.AnimateHelpState_NoFazeMe = true;
				this.AnimateHelpState_Buffer   = true;
				break;
			case AnimateMode_BUFFER:
				this.AnimateHelpState_Wait 	   = false;
				this.AnimateHelpState_NoFazeMe = false;
				this.AnimateHelpState_Buffer   = true;
				break;
			case AnimateMode_NOMPLAY:
				this.AnimateHelpState_Wait 	   = false;
				this.AnimateHelpState_NoFazeMe = false;
				this.AnimateHelpState_Buffer   = false;
				updateVel();
				break;
			default:
				break;
		}
	}
	
	//测试用
	/*public void destroy()
	{
		//0上,1左,2下,3右
		switch(this.currDirection)
		{
			case 0:
				if(this.currIGe-1>=0 
					&& pScence.fraises[currIGe-1][currJGe]!=null
					&& pScence.fraises[currIGe-1][currJGe].canDestroy)
				{pScence.fraises[currIGe-1][currJGe].destroy();}
				break;	
			case 1:
				if(this.currJGe-1>=0 
					&& pScence.fraises[currIGe][currJGe-1]!=null
					&& pScence.fraises[currIGe][currJGe-1].canDestroy)
				{pScence.fraises[currIGe][currJGe-1].destroy();}
				break;	
			case 2:
				if(this.currIGe+1<13 
					&& pScence.fraises[currIGe+1][currJGe]!=null
					&& pScence.fraises[currIGe+1][currJGe].canDestroy)
				{pScence.fraises[currIGe+1][currJGe].destroy();}
				break;	
			case 3:
				if(this.currJGe+1<15 
					&& pScence.fraises[currIGe][currJGe+1]!=null
					&& pScence.fraises[currIGe][currJGe+1].canDestroy)
				{pScence.fraises[currIGe][currJGe+1].destroy();}
				break;	
		}
	}*/
}

⌨️ 快捷键说明

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