Added new 'space' tile with shader / Added additional teleporter FX

This commit is contained in:
Anuken
2018-04-06 21:28:14 -04:00
parent 7a65604cc8
commit 7ea4a503f7
23 changed files with 619 additions and 383 deletions

View File

@@ -21,6 +21,11 @@ public class Blocks {
blockpart = new BlockPart(),
space = new Floor("space") {{
variants = 0;
drawLayer = DrawLayer.space;
}},
deepwater = new Floor("deepwater") {{
variants = 0;
solid = true;

View File

@@ -5,7 +5,6 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.content.blocks.ProductionBlocks;
import io.anuke.mindustry.io.Map;
import io.anuke.mindustry.io.MapIO;
import io.anuke.mindustry.io.Maps;
@@ -166,7 +165,7 @@ public class World extends Module{
Entities.resizeTree(0, 0, width * tilesize, height * tilesize);
WorldGenerator.generate(tiles, MapIO.readTileData(map));
WorldGenerator.generate(tiles, MapIO.readTileData(map, true));
}
public int getSeed(){

View File

@@ -79,7 +79,7 @@ public class MapEditorDialog extends Dialog{
ui.loadfrag.show();
Timers.run(3f, () -> {
try{
MapTileData data = MapIO.readTileData(new DataInputStream(file.read()));
MapTileData data = MapIO.readTileData(new DataInputStream(file.read()), false);
editor.beginEdit(data);
view.clearStack();

View File

@@ -43,6 +43,17 @@ public enum DrawLayer {
endShader(batch, Shaders.oil);
}
},
space{
@Override
public void begin(CacheBatch batch){
beginShader(batch);
}
@Override
public void end(CacheBatch batch){
endShader(batch, Shaders.space);
}
},
normal,
walls;

View File

@@ -19,4 +19,8 @@ public class Palette {
public static final Color lancerLaser = Color.valueOf("a9d8ff");
public static final Color stoneGray = Color.valueOf("8f8f8f");
public static final Color portalLight = Color.valueOf("9054ea");
public static final Color portal = Color.valueOf("6344d7");
public static final Color portalDark = Color.valueOf("3f3dac");
}

View File

@@ -10,17 +10,34 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Shader;
import io.anuke.ucore.scene.ui.layout.Unit;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class Shaders{
public static final Outline outline = new Outline();
public static final Shield shield = new Shield();
public static final SurfaceShader water = new SurfaceShader("water");
public static final SurfaceShader lava = new SurfaceShader("lava");
public static final SurfaceShader oil = new SurfaceShader("oil");
public static final Space space = new Space();
public static final UnitBuild build = new UnitBuild();
public static final Shader hit = new Shader("hit", "default");
private static final Vector2 vec = new Vector2();
public static class Space extends SurfaceShader{
public Space(){
super("space2");
}
@Override
public void apply(){
super.apply();
shader.setUniformf("u_center", world.width() * tilesize/2f, world.height() * tilesize/2f);
}
}
public static class UnitBuild extends Shader{
public float progress, time;
public Color color = new Color();

View File

@@ -90,20 +90,20 @@ public class MapIO {
}
/**Reads tile data, skipping meta.*/
public static MapTileData readTileData(DataInputStream stream) throws IOException {
public static MapTileData readTileData(DataInputStream stream, boolean readOnly) throws IOException {
MapMeta meta = readMapMeta(stream);
return readTileData(stream, meta);
return readTileData(stream, meta, readOnly);
}
/**Does not skip meta. Call after reading meta.*/
public static MapTileData readTileData(DataInputStream stream, MapMeta meta) throws IOException {
public static MapTileData readTileData(DataInputStream stream, MapMeta meta, boolean readOnly) throws IOException {
byte[] bytes = new byte[stream.available()];
stream.read(bytes);
return new MapTileData(bytes, meta.width, meta.height, meta.blockMap);
return new MapTileData(bytes, meta.width, meta.height, meta.blockMap, readOnly);
}
/**Reads tile data, skipping meta tags.*/
public static MapTileData readTileData(Map map){
public static MapTileData readTileData(Map map, boolean readOnly){
try {
InputStream stream;
@@ -114,7 +114,7 @@ public class MapIO {
}
DataInputStream ds = new DataInputStream(stream);
MapTileData data = MapIO.readTileData(ds);
MapTileData data = MapIO.readTileData(ds, readOnly);
ds.close();
return data;
}catch (IOException e){

View File

@@ -15,21 +15,34 @@ public class MapTileData {
private final ByteBuffer buffer;
private final TileDataMarker tile = new TileDataMarker();
private final int width, height;
private final boolean readOnly;
private final IntIntMap map;
private IntIntMap map;
public MapTileData(int width, int height){
this.width = width;
this.height = height;
this.map = null;
this.readOnly = false;
buffer = ByteBuffer.allocate(width * height * TILE_SIZE);
}
public MapTileData(byte[] bytes, int width, int height, IntIntMap mapping){
public MapTileData(byte[] bytes, int width, int height, IntIntMap mapping, boolean readOnly){
buffer = ByteBuffer.wrap(bytes);
this.width = width;
this.height = height;
this.map = mapping;
this.readOnly = readOnly;
if(mapping != null && !readOnly){
for(int i = 0; i < width * height; i ++){
read();
buffer.position(i * TILE_SIZE);
write();
}
buffer.position(0);
this.map = null;
}
}
public byte[] toArray(){
@@ -96,6 +109,7 @@ public class MapTileData {
}
public void write(ByteBuffer buffer){
if(readOnly) throw new IllegalArgumentException("This data is read-only.");
buffer.put(floor);
buffer.put(wall);
byte rt = Bits.packByte(rotation, team);

View File

@@ -17,7 +17,7 @@ import static io.anuke.mindustry.Vars.mapExtension;
public class Maps implements Disposable{
/**List of all built-in maps.*/
private static final String[] defaultMapNames = {"test"};
private static final String[] defaultMapNames = {"test", "space", "hole"};
/**Tile format version.*/
private static final int version = 0;
@@ -77,7 +77,7 @@ public class Maps implements Disposable{
DataInputStream ds = new DataInputStream(file.read());
MapMeta meta = MapIO.readMapMeta(ds);
Map map = new Map(file.nameWithoutExtension(), meta, custom);
if(!headless) map.texture = new Texture(MapIO.generatePixmap(MapIO.readTileData(ds, meta)));
if(!headless) map.texture = new Texture(MapIO.generatePixmap(MapIO.readTileData(ds, meta, true)));
maps.put(map.name, map);
allMaps.add(map);

View File

@@ -5,40 +5,36 @@ import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.mindustry.content.fx.Fx;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.BarType;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.PowerBlock;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.scene.ui.ButtonGroup;
import io.anuke.ucore.scene.ui.ImageButton;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import static io.anuke.mindustry.Vars.syncBlockState;
public class Teleporter extends PowerBlock{
public static final Color[] colorArray = {Color.ROYAL, Color.ORANGE, Color.SCARLET, Color.FOREST,
Color.PURPLE, Color.GOLD, Color.PINK, Color.BLACK};
public static final Color[] colorArray = {Color.ROYAL, Color.ORANGE, Color.SCARLET, Color.LIME,
Color.PURPLE, Color.GOLD, Color.PINK, Color.LIGHT_GRAY};
public static final int colors = colorArray.length;
private static ObjectSet<Tile>[] teleporters = new ObjectSet[colors];
private static Color color = new Color();
private static byte lastColor = 0;
private Array<Tile> removal = new Array<>();
private Array<Tile> returns = new Array<>();
protected float powerPerItem = 5f;
protected float warmupTime = 80f;
protected Effect teleportEffect = Fx.none;
@@ -55,6 +51,7 @@ public class Teleporter extends PowerBlock{
health = 80;
powerCapacity = 30f;
size = 3;
itemCapacity = 150;
}
@Override
@@ -66,16 +63,9 @@ public class Teleporter extends PowerBlock{
}
}
@Override
public void setBars(){
super.setBars();
bars.remove(BarType.inventory);
}
@Override
public void setStats(){
super.setStats();
stats.add("poweritem", Strings.toFixed(powerPerItem, 1));
}
@Override
@@ -89,16 +79,37 @@ public class Teleporter extends PowerBlock{
TeleporterEntity entity = tile.entity();
super.draw(tile);
Draw.color(colorArray[entity.color]);
Color target = colorArray[entity.color];
float ss = 0.5f;
float bs = 0.2f;
Draw.color(Hue.shift(Hue.multiply(color.set(target), 1, ss), 2, 0));
Draw.rect("teleporter-top", tile.drawx(), tile.drawy());
Draw.reset();
Draw.color(Color.WHITE);
//Draw.color(Palette.portal);
Draw.color(Hue.shift(Hue.multiply(color.set(target), 1, ss), 2, 0));
Fill.circle(tile.drawx(), tile.drawy(), 7f);
Fill.circle(tile.drawx(), tile.drawy(), 7f + Mathf.absin(Timers.time()+55, 8f, 1f));
Draw.color(Color.PURPLE);
//Draw.color(Palette.portalDark);
Draw.color(Hue.shift(Hue.multiply(color.set(target), 1, ss), 2, -bs));
Fill.circle(tile.drawx(), tile.drawy(), 2f + Mathf.absin(Timers.time(), 7f, 3f));
for(int i = 0; i < 11; i ++){
Lines.swirl(tile.drawx(), tile.drawy(),
2f + i/3f + Mathf.sin(Timers.time() - i *75, 20f + i, 3f),
0.3f + Mathf.sin(Timers.time() + i *33, 10f + i, 0.1f),
Timers.time() * (1f + Mathf.randomSeedRange(i + 1, 1f)) + Mathf.randomSeedRange(i, 360f));
}
//Draw.color(Palette.portalLight);
Draw.color(Hue.shift(Hue.multiply(color.set(target), 1, ss), 2, bs));
Lines.stroke(2f);
Lines.circle(tile.drawx(), tile.drawy(), 7f + Mathf.absin(Timers.time()+55, 8f, 1f));
Lines.stroke(1f);
for(int i = 0; i < 11; i ++){
Lines.swirl(tile.drawx(), tile.drawy(),
@@ -119,6 +130,10 @@ public class Teleporter extends PowerBlock{
if(entity.inventory.totalItems() > 0){
tryDump(tile);
}
if(entity.inventory.totalItems() == itemCapacity && entity.power.amount >= powerCapacity){
}
}
@Override
@@ -135,7 +150,7 @@ public class Teleporter extends PowerBlock{
cont.margin(4);
cont.marginBottom(5);
cont.add().colspan(4).height(105f);
cont.add().colspan(4).height(145f);
cont.row();
for(int i = 0; i < colors; i ++){
@@ -155,26 +170,10 @@ public class Teleporter extends PowerBlock{
table.add(cont);
}
@Override
public void handleItem(Item item, Tile tile, Tile source){
TeleporterEntity entity = tile.entity();
Array<Tile> links = findLinks(tile);
if(links.size > 0){
if(!syncBlockState || Net.server() || !Net.active()){
Tile target = links.random();
target.entity.inventory.addItem(item, 1);
}
}
entity.power.amount -= powerPerItem;
}
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
TeleporterEntity entity = tile.entity();
return !(source.block() instanceof Teleporter) && entity.power.amount >= powerPerItem && findLinks(tile).size > 0;
return entity.inventory.totalItems() < itemCapacity;
}
@Override