Animated oil blocks as well
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.graphics.CacheBatch;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Shader;
|
||||
|
||||
import static io.anuke.mindustry.Vars.renderer;
|
||||
|
||||
@@ -11,26 +13,34 @@ public enum DrawLayer {
|
||||
water{
|
||||
@Override
|
||||
public void begin(CacheBatch batch){
|
||||
batch.setProjectionMatrix(Core.camera.combined);
|
||||
Graphics.useBatch(batch.drawBatch());
|
||||
|
||||
Graphics.begin();
|
||||
Graphics.surface(renderer.waterSurface);
|
||||
beginShader(batch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end(CacheBatch batch){
|
||||
Graphics.surface();
|
||||
Graphics.end();
|
||||
endShader(batch, Shaders.water);
|
||||
}
|
||||
},
|
||||
lava{
|
||||
@Override
|
||||
public void begin(CacheBatch batch){
|
||||
beginShader(batch);
|
||||
}
|
||||
|
||||
Graphics.popBatch();
|
||||
@Override
|
||||
public void end(CacheBatch batch){
|
||||
endShader(batch, Shaders.lava);
|
||||
}
|
||||
},
|
||||
oil{
|
||||
@Override
|
||||
public void begin(CacheBatch batch){
|
||||
beginShader(batch);
|
||||
}
|
||||
|
||||
Graphics.shader(Shaders.water);
|
||||
Graphics.begin();
|
||||
Draw.rect(renderer.waterSurface.texture(), Core.camera.position.x, Core.camera.position.y,
|
||||
Core.camera.viewportWidth * Core.camera.zoom, -Core.camera.viewportHeight * Core.camera.zoom);
|
||||
Graphics.end();
|
||||
Graphics.shader();
|
||||
@Override
|
||||
public void end(CacheBatch batch){
|
||||
endShader(batch, Shaders.oil);
|
||||
}
|
||||
},
|
||||
normal,
|
||||
@@ -48,4 +58,27 @@ public enum DrawLayer {
|
||||
|
||||
Graphics.popBatch();
|
||||
}
|
||||
|
||||
protected void beginShader(CacheBatch batch){
|
||||
batch.setProjectionMatrix(Core.camera.combined);
|
||||
Graphics.useBatch(batch.drawBatch());
|
||||
|
||||
Graphics.begin();
|
||||
Graphics.surface(renderer.waterSurface);
|
||||
Graphics.clear(Color.CLEAR);
|
||||
}
|
||||
|
||||
public void endShader(CacheBatch batch, Shader shader){
|
||||
Graphics.surface();
|
||||
Graphics.end();
|
||||
|
||||
Graphics.popBatch();
|
||||
|
||||
Graphics.shader(shader);
|
||||
Graphics.begin();
|
||||
Draw.rect(renderer.waterSurface.texture(), Core.camera.position.x, Core.camera.position.y,
|
||||
Core.camera.viewportWidth * Core.camera.zoom, -Core.camera.viewportHeight * Core.camera.zoom);
|
||||
Graphics.end();
|
||||
Graphics.shader();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,25 +13,12 @@ import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
public class Shaders{
|
||||
public static final Outline outline = new Outline();
|
||||
public static final Shield shield = new Shield();
|
||||
public static final Water water = new Water();
|
||||
public static final SurfaceShader water = new SurfaceShader("water");
|
||||
public static final SurfaceShader lava = new SurfaceShader("lava");
|
||||
public static final SurfaceShader oil = new SurfaceShader("oil");
|
||||
|
||||
private static final Vector2 vec = new Vector2();
|
||||
|
||||
public static class Water extends Shader{
|
||||
|
||||
public Water(){
|
||||
super("water", "default");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
shader.setUniformf("camerapos", Core.camera.position.x + Core.camera.zoom, Core.camera.position.y);
|
||||
shader.setUniformf("screensize", Gdx.graphics.getWidth() / Core.cameraScale * Core.camera.zoom,
|
||||
Gdx.graphics.getHeight() / Core.cameraScale * Core.camera.zoom);
|
||||
shader.setUniformf("time", Timers.time());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Outline extends Shader{
|
||||
public Color color = new Color();
|
||||
public float lighten = 0f;
|
||||
@@ -46,7 +33,6 @@ public class Shaders{
|
||||
shader.setUniformf("u_lighten", lighten);
|
||||
shader.setUniformf("u_texsize", vec.set(region.getTexture().getWidth(), region.getTexture().getHeight()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Shield extends Shader{
|
||||
@@ -74,6 +60,20 @@ public class Shaders{
|
||||
shader.setUniformf("u_texsize", vec.set(region.getTexture().getWidth() / scale,
|
||||
region.getTexture().getHeight() / scale));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SurfaceShader extends Shader{
|
||||
|
||||
public SurfaceShader(String frag){
|
||||
super(frag, "default");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
shader.setUniformf("camerapos", Core.camera.position.x + Core.camera.zoom, Core.camera.position.y);
|
||||
shader.setUniformf("screensize", Gdx.graphics.getWidth() / Core.cameraScale * Core.camera.zoom,
|
||||
Gdx.graphics.getHeight() / Core.cameraScale * Core.camera.zoom);
|
||||
shader.setUniformf("time", Timers.time());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Liquid {
|
||||
heatCapacity = 0.2f;
|
||||
}
|
||||
},
|
||||
lava = new Liquid("lava", Color.valueOf("ed5334")){
|
||||
lava = new Liquid("lava", Color.valueOf("e37341")){
|
||||
{
|
||||
temperature = 0.7f;
|
||||
viscosity = 0.8f;
|
||||
|
||||
@@ -49,6 +49,7 @@ public class Blocks{
|
||||
solid = true;
|
||||
liquidDrop = Liquid.lava;
|
||||
liquid = true;
|
||||
drawLayer = DrawLayer.lava;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,6 +70,7 @@ public class Blocks{
|
||||
solid = true;
|
||||
liquidDrop = Liquid.oil;
|
||||
liquid = true;
|
||||
drawLayer = DrawLayer.oil;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user