Added rain, better snow implementation

This commit is contained in:
Anuken
2020-05-08 16:13:49 -04:00
parent cda3c3743b
commit bcec6261d1
6 changed files with 94 additions and 24 deletions

View File

@@ -1,13 +1,15 @@
package mindustry.content;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.*;
import mindustry.ctype.*;
import mindustry.gen.*;
import mindustry.type.*;
import static mindustry.Vars.world;
import static mindustry.Vars.*;
public class Weathers implements ContentList{
public static Weather
@@ -17,18 +19,25 @@ public class Weathers implements ContentList{
@Override
public void load(){
snow = new Weather("snow"){
Rand rand = new Rand();
TextureRegion region;
float yspeed = 2f, xspeed = 0.25f, padding = 16f, size = 12f, density = 1200f;
@Override
public void draw(){
rand.setSeed(0);
float yspeed = 2f, xspeed = 0.25f;
float padding = 16f;
float size = 12f;
Core.camera.bounds(Tmp.r1);
Tmp.r1.grow(padding);
public void load(){
super.load();
for(int i = 0; i < 100; i++){
region = Core.atlas.find("circle-shadow");
}
@Override
public void draw(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);
Core.camera.bounds(Tmp.r2);
int total = (int)(Tmp.r1.area() / density * state.intensity());
for(int i = 0; i < total; i++){
float scl = rand.random(0.5f, 1f);
float scl2 = rand.random(0.5f, 1f);
float sscl = rand.random(0.2f, 1f);
@@ -44,9 +53,47 @@ public class Weathers implements ContentList{
x += Tmp.r1.x;
y += Tmp.r1.y;
Draw.rect("circle-shadow", x, y, size * sscl, size * sscl);
if(Tmp.r3.setCentered(x, y, size * sscl).overlaps(Tmp.r2)){
Draw.rect(region, x, y, size * sscl, size * sscl);
}
}
}
};
rain = new Weather("rain"){
float yspeed = 7f, xspeed = 2f, padding = 16f, size = 40f, density = 1000f;
@Override
public void draw(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);
Core.camera.bounds(Tmp.r2);
int total = (int)(Tmp.r1.area() / density * state.intensity());
Lines.stroke(0.75f);
Draw.color(Color.royal, Color.white, 0.3f);
float alpha = Draw.getColor().a;
for(int i = 0; i < total; i++){
float scl = rand.random(0.5f, 1f);
float scl2 = rand.random(0.5f, 1f);
float sscl = rand.random(0.2f, 1f);
float x = (rand.random(0f, world.unitWidth()) + Time.time() * xspeed * scl2);
float y = (rand.random(0f, world.unitHeight()) - Time.time() * yspeed * scl);
float tint = rand.random(1f) * alpha;
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, size * sscl).overlaps(Tmp.r2)){
Draw.alpha(tint);
Lines.lineAngle(x, y, Angles.angle(xspeed * scl2, - yspeed * scl), size*sscl/2f);
}
}
//TODO
}
};
}