void CreateNewSpurting(DrawerController drawer) { position.y -= 1; Vector2 velo = Vector2.zero; HelperAPIMethods.RandomVelocity(ref velo, -1f, 1f, 0, 1f); drawer.CreateLivePixel <Spurting>(position, attach).velocity = 20f * velo; //溅起水花 }
public override void Update(DrawerController drawer) { velocity.y += gravity * Time.deltaTime; velocity *= 1f - 0.1f * Time.deltaTime; position += velocity * Time.deltaTime; if (x > renderWEnd || y > renderHEnd || y < renderHStart || x < renderWStart) { Die(); //都跑地图外了,那就让他去死吧 } if (!ClearAt(drawer, x, y)) { // 这个粒子碰到了什么东西, 如果是的话就判断是否清理两边。 clearLeft = ClearAt(drawer, x - 1, y); clearRight = ClearAt(drawer, x + 1, y); if (clearLeft && clearRight) { if (UnityEngine.Random.Range(0f, 1f) > 0.5f) { position.x -= 1; velocity = left; return; } else { position.x += 1; velocity = right; return; } } else if (clearLeft) { position.x -= 1; velocity = left; return; } else if (clearRight) { position.x += 1; velocity = right; return; } else if (velocity.y < 0) { // 他正在下坠,如果没发现找到符合清理要求的地方,那就网上移动一格,然后就去死吧 position.y += 1; DieClear(); Vector2 velo = Vector2.zero; HelperAPIMethods.RandomVelocity(ref velo, -1f, 1f, 0, 1f); drawer.CreateLivePixel <Spurting>(position, attach).velocity = 20f * velo; } velocity = Vector2.zero; } }
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); } }
void Update() { if (!Input.GetMouseButton(0)) { return; } if (!EventSystem.current.IsPointerOverGameObject()) { Vector2 pos; int c; if (drawer.PixelPosAtScreenPos(Input.mousePosition, out pos)) { pos.Set(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.y)); for (c = 0; c < cc; c++) { drawer.CreateLivePixel <Snow>(pos, brush); } } } }
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); }
void Update() { if (!Input.GetMouseButton(0)) { return; } if (!EventSystem.current.IsPointerOverGameObject()) { Vector2 pos; int c; if (drawer.PixelPosAtScreenPos(Input.mousePosition, out pos)) { pos.Set(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.y)); for (c = 0; c < cc; c++) { HelperAPIMethods.RandomVelocity(ref velo, -.5f, 1f, 0, -1f); drawer.CreateLivePixel <Rain>(pos, brush).velocity = 100f * velo; } } } }
static public void CreateFlameAt(DrawerController drawer, Vector2 pos) { int x = Mathf.RoundToInt(pos.x); int y = Mathf.RoundToInt(pos.y); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if ((i == j || -i == j) && i != 0) { continue; } pos.Set(x + i, y + j); drawer.CreateLivePixel <Fire>(pos, brush); } } }
void Update() { if (!Input.GetMouseButton(0)) { return; } if (!EventSystem.current.IsPointerOverGameObject()) { Vector2 pos; int c; if (drawer.PixelPosAtScreenPos(Input.mousePosition, out pos)) { pos.Set(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.y)); for (c = 0; c < cc; c++) { drawer.CreateLivePixel <Sands>(pos, brush).velocity = 20f * UnityEngine.Random.insideUnitCircle; } } } }