mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-25 22:17:59 +07:00
Added rain, better snow implementation
This commit is contained in:
parent
cda3c3743b
commit
bcec6261d1
@ -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
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class Renderer implements ApplicationListener{
|
||||
private Color clearColor = new Color(0f, 0f, 0f, 1f);
|
||||
private float targetscale = Scl.scl(4);
|
||||
private float camerascale = targetscale;
|
||||
private float landscale = 0f, landTime;
|
||||
private float landscale = 0f, landTime, weatherAlpha;
|
||||
private float minZoomScl = Scl.scl(0.01f);
|
||||
private float shakeIntensity, shaketime;
|
||||
|
||||
@ -64,6 +64,9 @@ public class Renderer implements ApplicationListener{
|
||||
landTime -= Time.delta();
|
||||
landscale = Interpolation.pow5In.apply(minZoomScl, Scl.scl(4f), 1f - landTime / Fx.coreLand.lifetime);
|
||||
camerascale = landscale;
|
||||
weatherAlpha = 0f;
|
||||
}else{
|
||||
weatherAlpha = Mathf.lerpDelta(weatherAlpha, 1f, 0.08f);
|
||||
}
|
||||
|
||||
camera.width = graphics.getWidth() / camerascale;
|
||||
@ -82,6 +85,10 @@ public class Renderer implements ApplicationListener{
|
||||
}
|
||||
}
|
||||
|
||||
public float weatherAlpha(){
|
||||
return weatherAlpha;
|
||||
}
|
||||
|
||||
public float landScale(){
|
||||
return landTime > 0 ? landscale : 1f;
|
||||
}
|
||||
@ -287,7 +294,11 @@ public class Renderer implements ApplicationListener{
|
||||
|
||||
public void clampScale(){
|
||||
float s = Scl.scl(1f);
|
||||
targetscale = Mathf.clamp(targetscale, s * 1.5f, Math.round(s * 6));
|
||||
targetscale = Mathf.clamp(targetscale, minScale(), Math.round(s * 6));
|
||||
}
|
||||
|
||||
public float minScale(){
|
||||
return Scl.scl(1.5f);
|
||||
}
|
||||
|
||||
public float getScale(){
|
||||
|
@ -11,4 +11,5 @@ class GroupDefs<G>{
|
||||
@GroupDef(value = Tilec.class) G tile;
|
||||
@GroupDef(value = Syncc.class, mapping = true) G sync;
|
||||
@GroupDef(value = Drawc.class) G draw;
|
||||
@GroupDef(value = Weatherc.class) G weather;
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ public class TODOPlanetGenerator extends PlanetGenerator{
|
||||
float scl = 5f;
|
||||
float waterOffset = 0.07f;
|
||||
|
||||
//TODO generate array from planet image later
|
||||
Block[][] arr = {
|
||||
{Blocks.water, Blocks.darksandWater, Blocks.darksand, Blocks.darksand, Blocks.darksand, Blocks.darksand, Blocks.sand, Blocks.sand, Blocks.sand, Blocks.sand, Blocks.darksandTaintedWater, Blocks.snow, Blocks.ice},
|
||||
{Blocks.water, Blocks.darksandWater, Blocks.darksand, Blocks.darksand, Blocks.sand, Blocks.sand, Blocks.sand, Blocks.sand, Blocks.sand, Blocks.darksandTaintedWater, Blocks.snow, Blocks.snow, Blocks.ice},
|
||||
@ -50,10 +49,7 @@ public class TODOPlanetGenerator extends PlanetGenerator{
|
||||
@Override
|
||||
public float getHeight(Vec3 position){
|
||||
float height = rawHeight(position);
|
||||
if(height <= water){
|
||||
return water;
|
||||
}
|
||||
return height;
|
||||
return Math.max(height, water);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,13 +2,17 @@ package mindustry.type;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
|
||||
import static mindustry.Vars.renderer;
|
||||
|
||||
public abstract class Weather extends MappableContent{
|
||||
protected float duration = 100f;
|
||||
protected Rand rand = new Rand();
|
||||
protected Prov<Weatherc> type = WeatherEntity::create;
|
||||
|
||||
public Weather(String name, Prov<Weatherc> type){
|
||||
@ -26,11 +30,16 @@ public abstract class Weather extends MappableContent{
|
||||
entity.add();
|
||||
}
|
||||
|
||||
public void update(){
|
||||
public void remove(){
|
||||
Entityc e = Groups.weather.find(w -> w.weather() == this);
|
||||
if(e != null) e.remove();
|
||||
}
|
||||
|
||||
public void update(Weatherc state){
|
||||
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
public void draw(Weatherc state){
|
||||
|
||||
}
|
||||
|
||||
@ -43,6 +52,7 @@ public abstract class Weather extends MappableContent{
|
||||
@Component
|
||||
abstract class WeatherComp implements Posc, Drawc{
|
||||
Weather weather;
|
||||
float intensity = 1f;
|
||||
|
||||
void init(Weather weather){
|
||||
this.weather = weather;
|
||||
@ -50,8 +60,13 @@ public abstract class Weather extends MappableContent{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.z(Layer.weather);
|
||||
weather.draw();
|
||||
if(renderer.weatherAlpha() > 0.0001f){
|
||||
Draw.draw(Layer.weather, () -> {
|
||||
Draw.alpha(renderer.weatherAlpha());
|
||||
weather.draw((Weatherc)this);
|
||||
Draw.reset();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=80e7780cdc5138b673f3424a0257774be9284b5e
|
||||
archash=84bbb36f336c108fdb85ae1bcb8eeeac42447460
|
||||
|
Loading…
Reference in New Issue
Block a user