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

📄 myfxpoint.java

📁 j2me
💻 JAVA
字号:
package mole.Rusfk;

//爆炸粒子特效单元
public class MyFxPoint{
	
	 //炮弹的发射点
	 int bulletX=0;
	 int bulletY=0;
	 //炮弹的射程
	 int shotWidth = 30;
	 //炮弹的射程高度
	 int shotHeight = 10;
	 //炮弹的速度
	 int shotSpeed = 4;
	 //炮弹抛物线的系数
	 long a,b,c;
	 int m_maxy=0;
	 int style=0;
	 int color=0;

	public MyFxPoint() {
		super();
	}
	public boolean Process()
	{
		if(bulletY<this.m_maxy)
		{
			//定点方法
			long tmp1=(a*(long)bulletX*(long)bulletX)>>16;
			long tmp2=(b*(long)bulletX);
			long tmp3=c>>16;
			bulletY = (int)(tmp1+tmp2+tmp3);
			//浮点方法
			//bulletY = (int)(a*bulletX*bulletX+b*bulletX+c);
			if(style==0)
				bulletX-=shotSpeed;
			else
				bulletX+=shotSpeed;
			return true;
		}
		return false;
	}
	 
	 public void setPoint(int x, int y,int color,int maxy,int style,int speed)
	 {
	  this.shotSpeed=speed;
	  this.color=color;
	  this.style=style;
	  this.m_maxy=maxy;
	  //初始化炮弹的发射点
	  this.bulletX = x;
	  this.bulletY = y;
	  //根据炮弹的发射点、高度、射程计算出炮弹抛物线的三点
	  int x1 ;
	  int y1 ;
	  int x2 ;
	  int y2 ;
	  int x3 ;
	  int y3 ;
	  if(style==0)
	  {
		  x1 = bulletX-shotWidth;
		  y1 = bulletY;
		  x2 = bulletX-shotWidth/2;
		  y2 = bulletY-shotHeight;
		  x3 = bulletX;
		  y3 = bulletY;
	  }
	  else
	  {
		  x1 = bulletX;
		  y1 = bulletY;
		  x2 = bulletX+shotWidth/2;
		  y2 = bulletY-shotHeight;
		  x3 = bulletX+shotWidth;
		  y3 = bulletY;
	  }
	  //根据抛物线方程ax^2+bx+c=y,得方程组
	  //ax1^2+bx1+c=y1
	  //ax2^2+bx2+c=y2
	  //ax3^2+bx3+c=y3
	  //解方程组得抛物线的a,b,c
	  long x1x1=x1*x1;
	  long x2x2=x2*x2;
	  long x3x3=x3*x3;
	  b = ((y1-y3)*(x1x1-x2x2)-(y1-y2)*(x1x1-x3x3))/((x1-x3)*(x1x1-x2x2)-(x1-x2)*(x1x1-x3x3));
	  //定点方法
	  long tmpx1=x1<<16;
	  long tmpy1=y1<<16;
	  a = (((y1-y2)-b*(x1-x2))<<16) / (x1x1-x2x2);
	  c=tmpy1-a*x1x1-b*tmpx1;
	  
	  if(style==0)
		bulletX-=5;
	  else
		bulletX+=5;
  
	  /*浮点方法
	  a = ((y1-y2)-b*(x1-x2))/(x1*x1-x2*x2);
	  c = y1-a*x1*x1-b*x1;
	  */
	 }

	
}

⌨️ 快捷键说明

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