public void Splode(Vector2 origin, int radius = 20) { if (drawer == null) { Init(); } ///https://blog.csdn.net/u010141928/article/details/79514514 算法参考该博客 ///Start.... Rect r = new Rect(origin.x - radius, origin.y - radius, radius * 2, radius * 2); int radSqr = radius * radius; //没有Π的圆的面积 int yMin = (int)r.yMin, yMax = (int)r.yMax, xMin = (int)r.xMin, xMax = (int)r.xMax, x = (int)origin.x, y = (int)origin.y; for (int j = yMin; j < yMax; j++) { for (int i = xMin; i < xMax; i++) { //i,j为当前位置 int dSqr = (i - x) * (i - x) + (j - y) * (j - y); //平面解析几何,操 if (dSqr > radSqr) //越过这个圆的边界了 { continue; } drawer.ClearLivePixels(i, j); //把这个区域可能存在的活着的对象杀了 if (UnityEngine.Random.Range(0, 1f) > .4f) //有可能可以产生爆炸溅射效果 ,见下面代码。。 { continue; } Color c = drawer.GetPixel(i, j); //获取这个位置的背景色 if (c.a == 0) //没有东西?那溜了溜了 { continue; } //这是一个爆炸溅射物 //万物都是由沙子组成的。。 pos.Set(i, j); Dross dross = drawer.CreateLivePixel <Dross>(pos, brush); dross.velocity = (dross.position - origin) * 7f; //原点坐标指向粒子位置的方向 射出去 } } drawer.FillEllipse(r, Color.clear); }
public override void Update(DrawerController drawer) { //调整位置和粒子的颜色 position.y += bouyancy * Time.deltaTime; //判断粒子当前的“年龄”,毕竟各个阶段的火焰颜色不同嘛 float t = (Time.time - startTime) / lifeTime; //根据他的年龄,给他上色 color = Color.Lerp(MakeFireInInspector.instance.fireStartColor, MakeFireInInspector.instance.fireEndColor, t); if (t > 1) { DieClear(); //大限已到,节哀 } //时不时生一个活的火焰 if (UnityEngine.Random.Range(0, 100) < 10) { pos.Set(x, y - 1); drawer.CreateLivePixel <Fire>(pos, brush).startTime = startTime - .3f; } //如果碰到了木头,那就把他烧成灰烬人(生点余烬粒子),还有足够时间的着火才有几率点燃噢 Color c = drawer.GetPixel(x, y, false); if (MakeFireInInspector.instance.IsFlammable(c) && UnityEngine.Random.Range(0, 100) < 2) { pos.Set(x, y); drawer.CreateLivePixel <Ember>(pos, attach); } //如果碰到雪了。。 if (c.IsGrayscale()) { drawer.SetPixel(x, y, Color.clear); } //碰到雨了 if (c.IsBluescale()) { drawer.SetPixel(x, y, Color.clear); } }
bool Dieposition(DrawerController drawer, int x, int y) { Color cs = drawer.GetPixel(x, y); return(cs == color); }
bool ClearAt(DrawerController drawer, int x, int y) { Color cs = drawer.GetPixel(x, y); return(cs == Color.black || cs.a == 0); }
public override void Start(DrawerController drawer) { color = drawer.GetPixel(x, y); }