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

📄 fraise.java

📁 这是自己设计的一款java泡泡游戏。 这是自己设计的一款java泡泡游戏。这是自己设计的一款java泡泡游戏
💻 JAVA
字号:
package pp.actor;

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//&&&&&&&&&&&&&&&&&&需要极大优化&&&&&&&&&&&&&&&&&&&
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
import java.awt.*;
import like.actor2D.*;
import like.graphics.*;

//障碍物类,移动和爆炸
public class Fraise extends Actor2D
{
	ResourceGroup rgroup;
	//属性
	int ID;
	int moveN = 20;
	boolean needUpdate = false;
	public int vi,vj;
	public int direction;
	boolean canMove;
	boolean canDestroy;
	boolean needAnim;
	
	int moveD = 0;
	int moveTime = 0;
	boolean change = false;
	
	boolean moving     = false;
	boolean destroying = false;
	boolean destroyed  = false;
	boolean temp  = false;//暂时性存在一下
	public boolean ifPP  = false;
	
	AnimationStrip common;
	AnimationStrip des;
	
	public Fraise(FraiseGroup group,ResourceGroup rgroup,int canMove,int canDestroy,int ID)
	{
		super(group);
		this.ID = ID;
		this.rgroup = rgroup;
		this.canMove       = canMove   ==1? true:false;
		this.canDestroy    = canDestroy==1? true:false;
		this.needAnim      = rgroup.needAnim[ID]==1? true:false;
		
		if(this.needAnim && !this.canDestroy)
		{
			ImageLoader loader = new ImageLoader(AnimationStrip.observer,rgroup.getAnimationStrip(ID));
			int width          = rgroup.frameWidth[ID];
			this.common 	   = new AnimationStrip();
			this.common.setAnimatorMode(Animator.AnimatorMode_Looped);
			this.common.setPE(40,40,(40-width)/2,40-loader.getImageHeight());
			for(int i=0;i<loader.getImageWidth()/width;i++)
				common.addFrame(loader.extractCell(width*i,0,width,loader.getImageHeight()));
			this.setAnimWait(rgroup.animWait[ID]);
		}
		else
		{
			Image image 	   = rgroup.getImage(2,ID);
			this.common 	   = new AnimationStrip();
			this.common.addFrame(image);
			this.common.setAnimatorMode(Animator.AnimatorMode_Single);
			this.common.setPE(40,40,(40-image.getWidth(AnimationStrip.observer))/2,40-image.getHeight(AnimationStrip.observer));
			this.setAnimWait(5);
		}
		this.currAnimation = common;
		this.currAnimator  = this.currAnimation.createNewAnimator();
		if(this.canDestroy)
		{
			ImageLoader loader = new ImageLoader(AnimationStrip.observer,rgroup.getAnimationStrip(ID));
			int width          = rgroup.frameWidth[ID];
			this.des     	   = new AnimationStrip();
			this.des.setAnimatorMode(Animator.AnimatorMode_Looped);
			this.des.setPE(40,40,(40-width)/2,40-loader.getImageHeight());
			for(int i=0;i<loader.getImageWidth()/width;i++)
				des.addFrame(loader.extractCell(width*i,0,width,loader.getImageHeight()));
		}
	}
	
	public Fraise(Actor2DGroup group,int x,int y)
	{
		super(group);
		this.temp       = true;
		this.canMove    = false;
		this.canDestroy = false;
		this.setPos(x,y);
		this.bounds.setRect(x,y,40,40);
	}
	
	public Fraise(Actor2DGroup group)
	{
		super(group);
	}
	
	public boolean getNeedUpdate()  {return this.needUpdate;}
	public boolean getDestroyed()   {return this.destroyed;}
	public boolean getTemp()        {return this.temp;}
	
	public void setNeedUpdate(boolean needUpdate) {this.needUpdate = needUpdate;}
	//覆盖父类的update方法暂时用不到
	public void update()
	{
		if(animate())
		{
			updateBounds();
			checkBounds();
			
			//把当前位置写到变换里
			xform.setToTranslation(pos.getX()+excursion.getX(),pos.getY()+excursion.getY());
		}
	}
	
	public void checkBounds()
	{
		if(change) change = false;
		else moveTime=0;
		super.checkBounds();
		if(this.moving)
		{
			
		}
	}
	
	public void paint(Graphics2D g2d)
	{
		if(destroyed) return;
		if(!ifPP&&rgroup.needPaintShadow(ID)&&!destroying)
		{
			Composite c = g2d.getComposite();
			g2d.setComposite(AlphaComposite.getInstance( AlphaComposite
    	             .SRC_OVER,0.45f ));
			g2d.drawImage(rgroup.getShadow(),(int)(pos.getX()+excursion.getX()-5),
				(int)(pos.getY()),AnimationStrip.observer);
			g2d.setComposite(c);
		}
			
		super.paint(g2d);
	}
	//覆盖父类的设置动画模式方法
	public void setAnimateMode(int AnimateMode)
	{
		switch(AnimateMode)
		{
			case AnimateMode_WAIT:
				this.AnimateHelpState_Wait 	   = true;
				this.AnimateHelpState_NoFazeMe = false;
				this.AnimateHelpState_Buffer   = false;
				
				if(this.ifPP) break;
				this.currAnimation = common;
				this.currAnimator  = currAnimation.createNewAnimator();
				if(this.moving)
				{
					this.needUpdate = true;
					this.moving = false;
				}
				this.setVel(0,0);
				if(destroying) destroyed = 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;
				break;
			default:
				break;
		}
	}
	//0上,1左,2下,3右
	public boolean move(int v)
	{
		change = true;
		if(this.moving)
			return false;
		if(moveD!=v)
		{moveD=v;moveTime=1;}
		else {moveTime++;}
		if(moveTime>=10)
		{
			moveD = 0; moveTime = 0;
			this.currAnimation = common;
			this.currAnimator  = this.currAnimation.createNewAnimator();
			this.setAnimateMode(this.AnimateMode_AUTOPLAY);
			this.setBufferTimes(moveN);//BufferTimes的妙用:)
			this.setAnimWait(1);
			this.direction = v;
			switch(v)
			{
				case 0: vi=-1;vj=0;this.setVel(0,-40/moveN);break;
				case 1: vi=0;vj=-1;this.setVel(-40/moveN,0);break;
				case 2: vi=1;vj=0;this.setVel(0,40/moveN);break;
				case 3: vi=0;vj=1;this.setVel(40/moveN,0);break;
			}
			this.moving = true;
			return true;
		}
		return false;
	}
	
	public void destroy()
	{
		if(!canDestroy) return; 
		this.currAnimation = des;//this.group.getAnimationStrip(0);
		this.currAnimator  = this.currAnimation.createNewAnimator();
		this.setAnimateMode(this.AnimateMode_AUTOPLAY);
		this.setBufferTimes(1);
		this.setAnimWait(1);
		this.setVel(0,0);
		this.destroying = true;
	}
}

⌨️ 快捷键说明

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