Added light item bridge

This commit is contained in:
Anuken
2018-04-08 21:46:48 -04:00
parent 21fe0f9246
commit aa28c3a45b
16 changed files with 394 additions and 117 deletions

View File

@@ -39,6 +39,7 @@ public class Recipes {
new Recipe(distribution, StorageBlocks.core, stack(Items.steel, 50)),
new Recipe(distribution, StorageBlocks.unloader, stack(Items.steel, 5)),
new Recipe(distribution, StorageBlocks.sortedunloader, stack(Items.steel, 5)),
new Recipe(distribution, DistributionBlocks.itembridge, stack(Items.steel, 5)),
new Recipe(weapon, WeaponBlocks.doubleturret, stack(Items.iron, 7)),
new Recipe(weapon, WeaponBlocks.gatlingturret, stack(Items.iron, 8)),

View File

@@ -38,6 +38,10 @@ public class DistributionBlocks{
speed = 53;
}},
itembridge = new ItemBridge("itembridge"){{
range = 7;
}},
sorter = new Sorter("sorter"),
splitter = new Splitter("splitter");

View File

@@ -57,6 +57,8 @@ public class ContentLoader {
block.init();
}
//TODO 128 blocks!
Log.info("--- CONTENT INFO ---");
Log.info("Blocks loaded: {0}\nItems loaded: {1}\nLiquids loaded: {2}\nUpgrades loaded: {3}\nUnits loaded: {4}\nAmmo types loaded: {5}\nStatus effects loaded: {6}",
Block.getAllBlocks().size, Item.getAllItems().size, Liquid.getAllLiquids().size,

View File

@@ -108,7 +108,7 @@ public class UI extends SceneModule{
Colors.put("placeRotate", Color.ORANGE);
Colors.put("break", Color.CORAL);
Colors.put("breakStart", Color.YELLOW);
Colors.put("breakInvalid", Color.RED);
Colors.put("breakInvalid", Color.SCARLET);
Colors.put("range", Colors.get("accent"));
Colors.put("power", Color.valueOf("fbd367"));
}

View File

@@ -66,7 +66,7 @@ public class BlockRenderer{
int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2)+2;
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2)+2;
int expandr = 3;
int expandr = 4;
Graphics.surface(renderer.shadowSurface);

View File

@@ -75,6 +75,14 @@ public class Tile{
return -1;
}
public byte absoluteRelativeTo(int cx, int cy){
if(x == cx && y <= cy - 1) return 1;
if(x == cx && y >= cy + 1) return 3;
if(x <= cx - 1 && y == cy) return 0;
if(x >= cx + 1 && y == cy) return 2;
return -1;
}
public byte sizedRelativeTo(int cx, int cy){
if(x == cx && y == cy - 1 - block().size/2) return 1;
if(x == cx && y == cy + 1 + block().size/2) return 3;
@@ -264,6 +272,10 @@ public class Tile{
return world.tile(x + relative.x, y + relative.y);
}
public Tile getNearby(int dx, int dy){
return world.tile(x + dx, y + dy);
}
public Tile getNearby(int rotation){
if(rotation == 0) return world.tile(x + 1, y);
if(rotation == 1) return world.tile(x, y + 1);

View File

@@ -0,0 +1,213 @@
package io.anuke.mindustry.world.blocks.types.distribution;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Layer;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.CapStyle;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class ItemBridge extends Block {
protected int timerTransport = timers++;
protected int range;
protected float powerUse = 0.05f;
protected float transportTime = 2f;
public ItemBridge(String name) {
super(name);
update = true;
solid = true;
hasPower = true;
layer = Layer.power;
expanded = true;
itemCapacity = 30;
}
@Override
public boolean isConfigurable(Tile tile) {
return true;
}
@Override
public void drawPlace(int x, int y, int rotation, boolean valid) {
Lines.stroke(2f);
Draw.color("place");
for(int i = 0; i < 4; i ++){
Lines.dashLine(
x * tilesize + Geometry.d4[i].x * tilesize/2f,
y * tilesize + Geometry.d4[i].y * tilesize/2f,
x * tilesize + Geometry.d4[i].x * range * tilesize,
y * tilesize + Geometry.d4[i].y * range * tilesize,
range);
}
Draw.reset();
}
@Override
public void drawConfigure(Tile tile){
ItemBridgeEntity entity = tile.entity();
Draw.color("accent");
Lines.stroke(1f);
Lines.square(tile.drawx(), tile.drawy(),
tile.block().size * tilesize / 2f + 1f);
for(int i = 1; i <= range; i ++){
for(int j = 0; j < 4; j ++){
Tile other = tile.getNearby(Geometry.d4[j].x * i, Geometry.d4[j].y * i);
if(linkValid(tile, other)){
boolean linked = other.packedPosition() == entity.link;
Draw.color(linked ? "place" : "breakInvalid");
Lines.square(other.drawx(), other.drawy(),
other.block().size * tilesize / 2f + 1f + (linked ? 0f : Mathf.absin(Timers.time(), 4f, 1f)));
}
}
}
Draw.reset();
}
@Override
public boolean onConfigureTileTapped(Tile tile, Tile other) {
ItemBridgeEntity entity = tile.entity();
if(linkValid(tile, other)){
if(entity.link == other.packedPosition()){
entity.link = -1;
}else{
entity.link = other.packedPosition();
}
return false;
}
return true;
}
@Override
public void update(Tile tile) {
ItemBridgeEntity entity = tile.entity();
entity.time += entity.cycleSpeed*Timers.delta();
entity.time2 += (entity.cycleSpeed-1f)*Timers.delta();
Tile other = world.tile(entity.link);
if(!linkValid(tile, other)){
tryDump(tile);
}else{
float use = Math.min(powerCapacity, powerUse * Timers.delta());
if(entity.power.amount >= use){
entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, 0.04f);
entity.power.amount -= use;
}else{
entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f);
}
if(entity.uptime >= 0.5f && entity.timer.get(timerTransport, transportTime)){
Item item = entity.inventory.takeItem();
if(item != null && other.block().acceptItem(item, other, tile)){
other.block().handleItem(item, other, tile);
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
}else{
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f);
if(item != null) entity.inventory.addItem(item, 1);
}
}
}
}
@Override
public void drawLayer(Tile tile) {
ItemBridgeEntity entity = tile.entity();
Tile other = world.tile(entity.link);
if(!linkValid(tile, other)) return;
int i = tile.absoluteRelativeTo(other.x, other.y);
Draw.color(Color.WHITE, Color.BLACK, Mathf.absin(Timers.time(), 6f, 0.07f));
Draw.alpha(Math.max(entity.uptime, 0.25f));
Draw.rect("lightbridge-end", tile.drawx(), tile.drawy(), i*90 + 90);
Draw.rect("lightbridge-end", other.drawx(), other.drawy(), i*90 + 270);
Lines.stroke(8f);
Lines.line(Draw.region("lightbridge"),
tile.worldx(),
tile.worldy(),
other.worldx(),
other.worldy(), CapStyle.none, -tilesize/2f);
int dist = Math.max(Math.abs(other.x - tile.x), Math.abs(other.y - tile.y));
float time = entity.time2/1.7f;
int arrows = (dist)*tilesize/4-2;
Draw.color();
for(int a = 0; a < arrows; a ++){
Draw.alpha(Mathf.absin(a/(float)arrows - entity.time/100f, 0.1f, 1f) * entity.uptime);
Draw.rect("lightbridge-arrow",
tile.worldx() + Geometry.d4[i].x*(tilesize/2f + a*4f + time % 4f),
tile.worldy() + Geometry.d4[i].y*(tilesize/2f + a*4f + time % 4f),
i*90f);
}
Draw.reset();
}
@Override
public boolean acceptItem(Item item, Tile tile, Tile source) {
return tile.entity.inventory.totalItems() < itemCapacity;
}
@Override
public TileEntity getEntity() {
return new ItemBridgeEntity();
}
public boolean linkValid(Tile tile, Tile other){
if(other == null) return false;
if(tile.x == other.x){
if(Math.abs(tile.x - other.x) > range) return false;
}else if(tile.y == other.y){
if(Math.abs(tile.y - other.y) > range) return false;
}else{
return false;
}
return other.block() instanceof ItemBridge && other.<ItemBridgeEntity>entity().link != tile.packedPosition();
}
public static class ItemBridgeEntity extends TileEntity{
public int link = -1;
public float uptime;
public float time;
public float time2;
public float cycleSpeed = 1f;
@Override
public void write(DataOutputStream stream) throws IOException {
stream.writeInt(link);
}
@Override
public void read(DataInputStream stream) throws IOException {
link = stream.readInt();
}
}
}

View File

@@ -129,14 +129,10 @@ public class PowerDistributor extends PowerBlock{
if(link != tile && linkValid(tile, link)){
boolean linked = linked(tile, link);
if(linked){
Draw.color("place");
}else{
Draw.color(Color.SCARLET);
}
Draw.color(linked ? "place" : "breakInvalid");
Lines.square(link.drawx(), link.drawy(),
link.block().size * tilesize / 2f + 1f + Mathf.absin(Timers.time(), 4f, 1f));
link.block().size * tilesize / 2f + 1f + (linked ? 0f : Mathf.absin(Timers.time(), 4f, 1f)));
if(entity.links.size >= maxNodes && !linked){
Draw.color();
@@ -266,7 +262,7 @@ public class PowerDistributor extends PowerBlock{
return Vector2.dst(tile.drawx(), tile.drawy(), link.drawx(), link.drawy()) <= Math.max(laserRange * tilesize,
((PowerDistributor)link.block()).laserRange * tilesize) - tilesize/2f
+ (link.block().size-1)*tilesize/2f + (tile.block().size-1)*tilesize/2f &&
oe.links.size < ((PowerDistributor)link.block()).maxNodes;
(oe.links.size < ((PowerDistributor)link.block()).maxNodes || oe.links.contains(tile.packedPosition()));
}else{
return Vector2.dst(tile.drawx(), tile.drawy(), link.drawx(), link.drawy())
<= laserRange * tilesize - tilesize/2f + (link.block().size-1)*tilesize;

View File

@@ -4,6 +4,8 @@ import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.content.fx.BlockFx;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.BarType;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
@@ -22,10 +24,17 @@ public class Incinerator extends Block {
super(name);
hasPower = true;
hasInventory = false;
hasLiquids = true;
update = true;
solid = true;
}
@Override
public void setBars() {
super.setBars();
bars.remove(BarType.liquid);
}
@Override
public void update(Tile tile) {
IncineratorEntity entity = tile.entity();
@@ -49,7 +58,6 @@ public class Incinerator extends Block {
if(entity.heat > 0f){
float g = 0.3f;
float r = 0.06f;
float cr = Mathf.random(0.05f);
Draw.alpha(((1f-g) + Mathf.absin(Timers.time(), 8f, g) + Mathf.random(r) - r) * entity.heat);
@@ -75,6 +83,19 @@ public class Incinerator extends Block {
return entity.heat > 0.5f;
}
@Override
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
if(Mathf.chance(0.02)){
Effects.effect(effect, tile.drawx(), tile.drawy());
}
}
@Override
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
IncineratorEntity entity = tile.entity();
return entity.heat > 0.5f;
}
@Override
public TileEntity getEntity() {
return new IncineratorEntity();