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

📄 littledot.java

📁 用JAVA写个一个烟花效果
💻 JAVA
字号:
package FireFlower;
import java.awt.Color;

class  LittleDot{
	//这是烟花爆破时的碎点
  int  x=0;
  int  y=0;
  Color  col;
  int  horizontal=0;  //水平方向的速度
  int  plumb=0;
  public  LittleDot(int x,int y,Color col){
	  //x,y是随机分配的
       this.x=x;
	   this.y=y;
	   this.col=col;
	   
  }
  
  
  public  void setPlace(){
	  //设置该点的x,y坐标
	  x=x+horizontal;
	  y=y+plumb;
	  if(horizontal>3)
	  horizontal=horizontal-2;
	  
	  if(plumb>3)
	  plumb=plumb-2;
  }
  
  
  //传入冲击力,和爆炸点的位置,然后计算横,竖方向的速度
  public   void  setPace(int  wallop,int pointX,int pointY){
	  //先计算斜边的长度,
	 
	    double  hypotenuse=Math.hypot(Math.abs(y*1.0-pointY),
	                     Math.abs(x*1.0-pointX)); 
	    
	    this.horizontal=(int)((Math.abs(x*1.0-pointX)/hypotenuse)*wallop)+(int)(Math.random()*10);
		this.plumb=(int)((Math.abs(y*1.0-pointY)/hypotenuse)*wallop)+(int)(Math.random()*10);
	          
		  if(x<pointX)this.horizontal=this.horizontal*-1;
		  
		  if(y<pointY) this.plumb= this.plumb*-1;
		
  }
  
  //直接根据传入x,y来设置
  public  void setPace(int paceX,int paceY){
	  this.horizontal=paceX;
	  this.plumb=paceY;

  }
  

  public String toString(){
	  return "位置:x="+x+",y="+y+",颜色是"+col;
	  
  }
}

⌨️ 快捷键说明

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