日期:2014-05-20 浏览次数:20780 次
public void add(int count,float x, float y) //x y为小人坐标 { add(count, Left_Top,x,y); add(count, Left_Bottom,x,y); add(count, Right_Top, x,y); add(count, Right_Bottom, x,y); } public void add(int count,int dir,float sx, float sy) { //Random random = new Random(); for (int i = 0; i < count; i++) { int x = 0,y = 0; //子弹坐标 double v_x = 0; //子弹速度 double v_y = 0; double t; switch (dir) //判断从哪个角发出 { case Left_Top: x = 0; y = 0; t = sx / Math.sqrt(sx * sx + sy * sy); v_x = 3 * t; v_y = -3 * Math.sqrt(1 * t * t); break; case Left_Bottom: x = 0; y = 480; sy = 480 - sy; t = sx / Math.sqrt(sx * sx + sy * sy); v_x = 3 * t; v_y = 3 * Math.sqrt(1 * t * t); break; case Right_Top: x = 320; y = 0; sx = 320 - sx; t = sx / Math.sqrt(sx * sx + sy * sy); v_x = -3 * t; v_y = -3 * Math.sqrt(1 * t * t); break; case Right_Bottom: x = 320; y = 480; sy = 480 - sy; sx = 320 - sx; t = sx / Math.sqrt(sx * sx + sy * sy); v_x = -3 * t; v_y = 3 * Math.sqrt(1 * t * t); break; default: break; } Particle particle = new Particle(v_y, v_x, x, y); particleSet.add(particle); } }