Fixed #2032
This commit is contained in:
@@ -8,6 +8,7 @@ import arc.util.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@@ -30,7 +31,7 @@ public class Weathers implements ContentList{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Weatherc state){
|
||||
public void drawOver(Weatherc state){
|
||||
rand.setSeed(0);
|
||||
Tmp.r1.setCentered(Core.camera.position.x, Core.camera.position.y, Core.graphics.getWidth() / renderer.minScale(), Core.graphics.getHeight() / renderer.minScale());
|
||||
Tmp.r1.grow(padding);
|
||||
@@ -62,10 +63,19 @@ public class Weathers implements ContentList{
|
||||
|
||||
rain = new Weather("rain"){
|
||||
float yspeed = 7f, xspeed = 2f, padding = 16f, size = 40f, density = 1000f;
|
||||
TextureRegion[] splashes = new TextureRegion[12];
|
||||
|
||||
@Override
|
||||
public void draw(Weatherc state){
|
||||
rand.setSeed(0);
|
||||
public void load(){
|
||||
super.load();
|
||||
|
||||
for(int i = 0; i < splashes.length; i++){
|
||||
splashes[i] = Core.atlas.find("splash-" + i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOver(Weatherc state){
|
||||
Tmp.r1.setCentered(Core.camera.position.x, Core.camera.position.y, Core.graphics.getWidth() / renderer.minScale(), Core.graphics.getHeight() / renderer.minScale());
|
||||
Tmp.r1.grow(padding);
|
||||
Core.camera.bounds(Tmp.r2);
|
||||
@@ -95,6 +105,43 @@ public class Weathers implements ContentList{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawUnder(Weatherc state){
|
||||
Tmp.r1.setCentered(Core.camera.position.x, Core.camera.position.y, Core.graphics.getWidth() / renderer.minScale(), Core.graphics.getHeight() / renderer.minScale());
|
||||
Tmp.r1.grow(padding);
|
||||
Core.camera.bounds(Tmp.r2);
|
||||
int total = (int)(Tmp.r1.area() / density * state.intensity()) / 2;
|
||||
|
||||
float t = Time.time() / 22f;
|
||||
|
||||
for(int i = 0; i < total; i++){
|
||||
float offset = rand.random(0f, 1f);
|
||||
float time = t + offset;
|
||||
|
||||
int pos = (int)((time));
|
||||
float life = time % 1f;
|
||||
float x = (rand.random(0f, world.unitWidth()) + pos*953);
|
||||
float y = (rand.random(0f, world.unitHeight()) - pos*453);
|
||||
|
||||
x -= Tmp.r1.x;
|
||||
y -= Tmp.r1.y;
|
||||
x = Mathf.mod(x, Tmp.r1.width);
|
||||
y = Mathf.mod(y, Tmp.r1.height);
|
||||
x += Tmp.r1.x;
|
||||
y += Tmp.r1.y;
|
||||
|
||||
if(Tmp.r3.setCentered(x, y, life * 4f).overlaps(Tmp.r2)){
|
||||
Tile tile = world.tileWorld(x, y);
|
||||
if(tile != null && tile.floor().liquidDrop == Liquids.water){
|
||||
Draw.tint(Tmp.c1.set(tile.floor().mapColor).mul(1.5f));
|
||||
Draw.rect(splashes[(int)(life * (splashes.length - 1))], x, y);
|
||||
//Lines.stroke((1f - life) * 2f);
|
||||
//Lines.circle(x, y, life * 4f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,12 +196,24 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
||||
|
||||
public byte absoluteRelativeTo(int cx, int cy){
|
||||
int x = tile.x, y = tile.y;
|
||||
if(Math.abs(x - cx) > Math.abs(y - cy)){
|
||||
if(x <= cx - 1) return 0;
|
||||
if(x >= cx + 1) return 2;
|
||||
}else{
|
||||
if(y <= cy - 1) return 1;
|
||||
if(y >= cy + 1) return 3;
|
||||
|
||||
//very straightforward for odd sizes
|
||||
if(block.size % 2 == 1){
|
||||
if(Math.abs(x - cx) > Math.abs(y - cy)){
|
||||
if(x <= cx - 1) return 0;
|
||||
if(x >= cx + 1) return 2;
|
||||
}else{
|
||||
if(y <= cy - 1) return 1;
|
||||
if(y >= cy + 1) return 3;
|
||||
}
|
||||
}else{ //need offsets here
|
||||
if(Math.abs(x - cx + 0.5f) > Math.abs(y - cy + 0.5f)){
|
||||
if(x+0.5f <= cx - 1) return 0;
|
||||
if(x+0.5f >= cx + 1) return 2;
|
||||
}else{
|
||||
if(y+0.5f <= cy - 1) return 1;
|
||||
if(y+0.5f >= cy + 1) return 3;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
@@ -16,8 +16,8 @@ public abstract class Weather extends MappableContent{
|
||||
public float duration = 15f * Time.toMinutes;
|
||||
|
||||
//internals
|
||||
protected Rand rand = new Rand();
|
||||
protected Prov<Weatherc> type = WeatherEntity::create;
|
||||
public Rand rand = new Rand();
|
||||
public Prov<Weatherc> type = WeatherEntity::create;
|
||||
|
||||
public Weather(String name, Prov<Weatherc> type){
|
||||
super(name);
|
||||
@@ -58,7 +58,11 @@ public abstract class Weather extends MappableContent{
|
||||
|
||||
}
|
||||
|
||||
public void draw(Weatherc state){
|
||||
public void drawOver(Weatherc state){
|
||||
|
||||
}
|
||||
|
||||
public void drawUnder(Weatherc state){
|
||||
|
||||
}
|
||||
|
||||
@@ -105,7 +109,7 @@ public abstract class Weather extends MappableContent{
|
||||
|
||||
@EntityDef(value = {Weatherc.class}, pooled = true, isFinal = false)
|
||||
@Component
|
||||
abstract class WeatherComp implements Drawc{
|
||||
abstract static class WeatherComp implements Drawc{
|
||||
private static final float fadeTime = 60 * 4;
|
||||
|
||||
Weather weather;
|
||||
@@ -132,8 +136,16 @@ public abstract class Weather extends MappableContent{
|
||||
public void draw(){
|
||||
if(renderer.weatherAlpha() > 0.0001f){
|
||||
Draw.draw(Layer.weather, () -> {
|
||||
weather.rand.setSeed(0);
|
||||
Draw.alpha(renderer.weatherAlpha() * opacity);
|
||||
weather.draw((Weatherc)this);
|
||||
weather.drawOver((Weatherc)this);
|
||||
Draw.reset();
|
||||
});
|
||||
|
||||
Draw.draw(Layer.debris, () -> {
|
||||
weather.rand.setSeed(0);
|
||||
Draw.alpha(renderer.weatherAlpha() * opacity);
|
||||
weather.drawUnder((Weatherc)this);
|
||||
Draw.reset();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -70,8 +70,6 @@ public class Sorter extends Block{
|
||||
Draw.rect("center", x, y);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user