Implemented new enemy spawning, sorter, teleporter and others
This commit is contained in:
@@ -97,7 +97,16 @@ public class Control extends Module{
|
||||
player = new Player();
|
||||
|
||||
spawns = Array.with(
|
||||
|
||||
new EnemySpawn(TitanEnemy.class){{
|
||||
after = 16;
|
||||
spacing = 3;
|
||||
scaling = 5;
|
||||
}},
|
||||
new EnemySpawn(HealerEnemy.class){{
|
||||
scaling = 3;
|
||||
spacing = 2;
|
||||
after = 8;
|
||||
}},
|
||||
new EnemySpawn(Enemy.class){{
|
||||
scaling = 3;
|
||||
tierscaleback = 3;
|
||||
@@ -121,6 +130,11 @@ public class Control extends Module{
|
||||
spacing = 3;
|
||||
scaling = 3;
|
||||
}},
|
||||
new EnemySpawn(EmpEnemy.class){{
|
||||
after = 19;
|
||||
spacing = 3;
|
||||
scaling = 5;
|
||||
}},
|
||||
new EnemySpawn(TankEnemy.class){{
|
||||
after = 4;
|
||||
spacing = 2;
|
||||
@@ -132,6 +146,7 @@ public class Control extends Module{
|
||||
scaling = 5;
|
||||
}}
|
||||
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
@@ -413,7 +428,6 @@ public class Control extends Module{
|
||||
}else{
|
||||
new TitanEnemy(0).set(player.x, player.y).add();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Colors;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
@@ -18,9 +19,13 @@ import io.anuke.mindustry.input.PlaceMode;
|
||||
import io.anuke.mindustry.resource.*;
|
||||
import io.anuke.mindustry.ui.*;
|
||||
import io.anuke.mindustry.world.Map;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.function.VisibilityProvider;
|
||||
import io.anuke.ucore.modules.SceneModule;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
import io.anuke.ucore.scene.Skin;
|
||||
import io.anuke.ucore.scene.actions.Actions;
|
||||
import io.anuke.ucore.scene.builders.*;
|
||||
@@ -31,11 +36,12 @@ import io.anuke.ucore.scene.ui.layout.*;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class UI extends SceneModule{
|
||||
Table itemtable, weapontable, tools, loadingtable, desctable, respawntable;
|
||||
Table itemtable, weapontable, tools, loadingtable, desctable, respawntable, configtable;
|
||||
SettingsDialog prefs;
|
||||
KeybindDialog keys;
|
||||
Dialog about, menu, restart, levels, upgrades, load, settingserror;
|
||||
Tooltip tooltip;
|
||||
Tile configTile;
|
||||
|
||||
VisibilityProvider play = () -> !GameState.is(State.menu);
|
||||
VisibilityProvider nplay = () -> GameState.is(State.menu);
|
||||
@@ -73,6 +79,7 @@ public class UI extends SceneModule{
|
||||
Colors.put("turretinfo", Color.ORANGE);
|
||||
Colors.put("missingitems", Color.SCARLET);
|
||||
Colors.put("health", Color.YELLOW);
|
||||
Colors.put("interact", Color.ORANGE);
|
||||
}
|
||||
|
||||
protected void loadSkin(){
|
||||
@@ -121,6 +128,9 @@ public class UI extends SceneModule{
|
||||
@Override
|
||||
public void init(){
|
||||
|
||||
configtable = new Table();
|
||||
scene.add(configtable);
|
||||
|
||||
settingserror = new Dialog("Warning", "dialog");
|
||||
settingserror.content().add("[crimson]Failed to access local storage.\nSettings will not be saved.");
|
||||
settingserror.content().pad(10f);
|
||||
@@ -666,6 +676,32 @@ public class UI extends SceneModule{
|
||||
});
|
||||
}
|
||||
|
||||
public void showConfig(Tile tile){
|
||||
configTile = tile;
|
||||
|
||||
configtable.setVisible(true);
|
||||
configtable.clear();
|
||||
((Configurable)tile.block()).buildTable(tile, configtable);
|
||||
configtable.pack();
|
||||
|
||||
configtable.update(()->{
|
||||
Vector2 pos = Graphics.screen(tile.worldx(), tile.worldy());
|
||||
configtable.setPosition(pos.x, pos.y, Align.center);
|
||||
if(configTile == null || configTile.block() == Blocks.air){
|
||||
hideConfig();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean hasConfigMouse(){
|
||||
Element e = scene.hit(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), true);
|
||||
return e != null && (e == configtable || e.isDescendantOf(configtable));
|
||||
}
|
||||
|
||||
public void hideConfig(){
|
||||
configtable.setVisible(false);
|
||||
}
|
||||
|
||||
public void showError(String text){
|
||||
new Dialog("[crimson]An error has occured", "dialog"){{
|
||||
content().pad(Unit.dp.inPixels(15));
|
||||
|
||||
@@ -162,8 +162,16 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
|
||||
Draw.reset();
|
||||
}
|
||||
},
|
||||
smallSlow = new BulletType(1.2f, 1){
|
||||
public void draw(Bullet b){
|
||||
Draw.color("orange");
|
||||
Draw.rect("bullet", b.x, b.y, b.angle());
|
||||
Draw.reset();
|
||||
}
|
||||
},
|
||||
purple = new BulletType(1.6f, 2){
|
||||
Color color = new Color(0x8b5ec9ff);
|
||||
|
||||
public void draw(Bullet b){
|
||||
Draw.color(color);
|
||||
Draw.rect("bullet", b.x, b.y, b.angle());
|
||||
|
||||
@@ -12,14 +12,14 @@ import io.anuke.ucore.graphics.Hue;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
|
||||
public class HealerEnemy extends Enemy{
|
||||
int healTime = 10;
|
||||
int healTime = 14;
|
||||
|
||||
public HealerEnemy(int spawn) {
|
||||
super(spawn);
|
||||
|
||||
speed = 0.2f;
|
||||
reload = 30;
|
||||
maxhealth = 210;
|
||||
maxhealth = 130;
|
||||
range = 90f;
|
||||
bullet = BulletType.shot;
|
||||
range = 30f;
|
||||
|
||||
@@ -10,7 +10,7 @@ public class TankEnemy extends Enemy{
|
||||
public TankEnemy(int spawn) {
|
||||
super(spawn);
|
||||
|
||||
maxhealth = 400;
|
||||
maxhealth = 350;
|
||||
speed = 0.2f;
|
||||
reload = 90f;
|
||||
bullet = BulletType.small;
|
||||
|
||||
@@ -12,7 +12,7 @@ public class TitanEnemy extends Enemy{
|
||||
|
||||
speed = 0.1f;
|
||||
reload = 30;
|
||||
maxhealth = 210;
|
||||
maxhealth = 330;
|
||||
range = 80f;
|
||||
bullet = BulletType.small;
|
||||
hitbox.setSize(7f);
|
||||
@@ -26,23 +26,23 @@ public class TitanEnemy extends Enemy{
|
||||
|
||||
@Override
|
||||
void updateShooting(){
|
||||
Timers.get(this, "salvo", 200);
|
||||
Timers.get(this, "salvo", 250);
|
||||
|
||||
if(Timers.getTime(this, "salvo") < 60){
|
||||
if(Timers.get(this, "salvoShoot", 5)){
|
||||
if(Timers.get(this, "salvoShoot", 6)){
|
||||
shoot(BulletType.flame, Mathf.range(20f));
|
||||
}
|
||||
}
|
||||
|
||||
if(Timers.get(this, "shotgun", 80)){
|
||||
if(Timers.get(this, "shotgun", 90)){
|
||||
Angles.shotgun(5, 10f, 0f, f->{
|
||||
shoot(BulletType.small, f);
|
||||
shoot(BulletType.smallSlow, f);
|
||||
});
|
||||
}
|
||||
|
||||
if(Timers.get(this, "circle", 200)){
|
||||
Angles.circle(8, f->{
|
||||
shoot(BulletType.small, f);
|
||||
shoot(BulletType.smallSlow, f);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.World;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@@ -45,6 +46,8 @@ public class Input{
|
||||
}
|
||||
}
|
||||
|
||||
Tile cursor = World.tile(tilex(), tiley());
|
||||
|
||||
if(Inputs.buttonUp(Buttons.LEFT) && player.recipe != null &&
|
||||
World.validPlace(tilex(), tiley(), player.recipe.result) && !ui.hasMouse() && cursorNear() &&
|
||||
Vars.control.hasItems(player.recipe.requirements)){
|
||||
@@ -59,17 +62,25 @@ public class Input{
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
|
||||
}else if(Inputs.buttonUp(Buttons.LEFT)){
|
||||
if(cursor != null && cursor.block() instanceof Configurable){
|
||||
Vars.ui.showConfig(cursor);
|
||||
}else if(!Vars.ui.hasConfigMouse()){
|
||||
Vars.ui.hideConfig();
|
||||
}
|
||||
}
|
||||
|
||||
if(Inputs.buttonUp(Buttons.RIGHT)){
|
||||
Vars.ui.hideConfig();
|
||||
}
|
||||
|
||||
if(player.recipe != null && Inputs.buttonUp(Buttons.RIGHT)){
|
||||
player.recipe = null;
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
|
||||
Tile cursor = World.tile(tilex(), tiley());
|
||||
|
||||
//block breaking
|
||||
if(cursor != null && Inputs.buttonDown(Buttons.RIGHT) && World.validBreak(tilex(), tiley())){
|
||||
if(Inputs.buttonDown(Buttons.RIGHT) && cursor != null && World.validBreak(tilex(), tiley())){
|
||||
Tile tile = cursor;
|
||||
player.breaktime += Timers.delta();
|
||||
if(player.breaktime >= tile.getBreakTime()){
|
||||
|
||||
@@ -21,7 +21,6 @@ public enum Recipe{
|
||||
titaniumshieldwall(defense, DefenseBlocks.titaniumshieldwall, stack(Item.titanium, 2)),
|
||||
shieldgenerator(defense, DefenseBlocks.shieldgenerator, stack(Item.titanium, 10), stack(Item.dirium, 10)),
|
||||
|
||||
|
||||
conveyor(distribution, DistributionBlocks.conveyor, stack(Item.stone, 1)),
|
||||
steelconveyor(distribution, DistributionBlocks.steelconveyor, stack(Item.steel, 1)),
|
||||
poweredconveyor(distribution, DistributionBlocks.poweredconveyor, stack(Item.dirium, 1)),
|
||||
@@ -30,6 +29,7 @@ public enum Recipe{
|
||||
conduit(distribution, DistributionBlocks.conduit, stack(Item.steel, 1)),
|
||||
liquidrouter(distribution, DistributionBlocks.liquidrouter, stack(Item.steel, 2)),
|
||||
liquidjunction(distribution, DistributionBlocks.liquidjunction, stack(Item.steel, 2)),
|
||||
sorter(distribution, DistributionBlocks.sorter, stack(Item.steel, 2)),
|
||||
|
||||
turret(weapon, WeaponBlocks.turret, stack(Item.stone, 4)),
|
||||
dturret(weapon, WeaponBlocks.doubleturret, stack(Item.stone, 7)),
|
||||
@@ -62,6 +62,7 @@ public enum Recipe{
|
||||
powerbooster(power, DistributionBlocks.powerbooster, stack(Item.titanium, 10), stack(Item.dirium, 10)),
|
||||
powerlaser(power, DistributionBlocks.powerlaser, stack(Item.titanium, 10), stack(Item.dirium, 10)),
|
||||
powerlaserrouter(power, DistributionBlocks.powerlaserrouter, stack(Item.titanium, 10), stack(Item.dirium, 10)),
|
||||
teleporter(power, DistributionBlocks.teleporter, stack(Item.titanium, 10), stack(Item.dirium, 10)),
|
||||
|
||||
pump(production, ProductionBlocks.pump, stack(Item.steel, 10));
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public class Block{
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void handleItem(Tile tile, Item item, Tile source){
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
tile.entity.addItem(item, 1);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class Block{
|
||||
//don't output to things facing this thing
|
||||
&& !(other.block().rotate && (other.rotation + 2) % 4 == i)){
|
||||
|
||||
other.block().handleItem(other, item, tile);
|
||||
other.block().handleItem(item, other, tile);
|
||||
tile.dump = (byte)((i+1)%4);
|
||||
return;
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public class Block{
|
||||
i %= 4;
|
||||
}
|
||||
tile.dump = (byte)pdump;
|
||||
handleItem(tile, item, tile);
|
||||
handleItem(item, tile, tile);
|
||||
}
|
||||
|
||||
/** Try dumping any item near the tile. */
|
||||
@@ -142,7 +142,7 @@ public class Block{
|
||||
if(tile.entity.hasItem(item) && other != null && other.block().acceptItem(item, other, tile) &&
|
||||
//don't output to things facing this thing
|
||||
!(other.block().rotate && (other.rotation + 2) % 4 == i)){
|
||||
other.block().handleItem(other, item, tile);
|
||||
other.block().handleItem(item, other, tile);
|
||||
tile.entity.removeItem(item, 1);
|
||||
tile.dump = (byte)((i+1)%4);
|
||||
return true;
|
||||
@@ -161,7 +161,7 @@ public class Block{
|
||||
protected boolean offloadDir(Tile tile, Item item){
|
||||
Tile other = tile.getNearby()[tile.rotation];
|
||||
if(other != null && other.block().acceptItem(item, other, tile)){
|
||||
other.block().handleItem(other, item, tile);
|
||||
other.block().handleItem(item, other, tile);
|
||||
//other.entity.addCovey(item, ch == 1 ? 0.5f : ch ==2 ? 1f : 0f);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,5 +56,15 @@ public class DistributionBlocks{
|
||||
{
|
||||
formalName = "laser router";
|
||||
}
|
||||
},
|
||||
teleporter = new Teleporter("teleporter"){
|
||||
{
|
||||
|
||||
}
|
||||
},
|
||||
sorter = new Sorter("sorter"){
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ProductionBlocks{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Tile tile, Item item, Tile source){
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
Vars.control.addItem(item, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ public class BlockPart extends Block implements PowerAcceptor, LiquidAcceptor{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Tile tile, Item item, Tile source){
|
||||
tile.getLinked().block().handleItem(tile.getLinked(), item, source);
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
tile.getLinked().block().handleItem(item, tile.getLinked(), source);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
public interface Configurable{
|
||||
public void buildTable(Tile tile, Table table);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public class Conveyor extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Tile tile, Item item, Tile source){
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
int ch = Math.abs(source.relativeTo(tile.x, tile.y) - tile.rotation);
|
||||
int ang = ((source.relativeTo(tile.x, tile.y) - tile.rotation));
|
||||
|
||||
|
||||
@@ -19,14 +19,13 @@ public class Junction extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Tile tile, Item item, Tile source){
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
int dir = source.relativeTo(tile.x, tile.y);
|
||||
dir = (dir+4)%4;
|
||||
Tile to = tile.getNearby()[dir];
|
||||
|
||||
Timers.run(15, ()->{
|
||||
if(to == null || to.entity == null) return;
|
||||
to.block().handleItem(to, item, tile);
|
||||
to.block().handleItem(item, to, tile);
|
||||
});
|
||||
|
||||
}
|
||||
@@ -34,10 +33,8 @@ public class Junction extends Block{
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile dest, Tile source){
|
||||
int dir = source.relativeTo(dest.x, dest.y);
|
||||
dir = (dir+4)%4;
|
||||
Tile to = dest.getNearby()[dir];
|
||||
//uncomment the junction bit to disable giving items to other junctions
|
||||
return to != null /*&& to.block() != junction*/ && to.block().acceptItem(item, to, dest);
|
||||
return to != null && to.block().acceptItem(item, to, dest);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,8 +36,8 @@ public class Router extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Tile tile, Item item, Tile source){
|
||||
super.handleItem(tile, item, source);
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
super.handleItem(item, tile, source);
|
||||
lastmap.put(tile, (byte)tile.relativeTo(source.x, source.y));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,20 +4,119 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
|
||||
//TODO
|
||||
public class Sorter extends Junction{
|
||||
public class Sorter extends Junction implements Configurable{
|
||||
|
||||
public Sorter(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
SorterEntity entity = tile.entity();
|
||||
return super.acceptItem(item, tile, source) && item == entity.sortItem;
|
||||
|
||||
TextureRegion region = Draw.region("icon-" + entity.sortItem.name());
|
||||
Tmp.tr1.setRegion(region, 4, 4, 1, 1);
|
||||
|
||||
Draw.rect(Tmp.tr1, tile.worldx(), tile.worldy(), 4f, 4f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description(){
|
||||
return "[interact]Tap block to config[]\nSorts input items by type.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile dest, Tile source){
|
||||
Tile to = getTileTarget(item, dest, source, false);
|
||||
|
||||
return to != null && to.block().acceptItem(item, to, dest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
Tile to = getTileTarget(item, tile, source, true);
|
||||
|
||||
Timers.run(15, ()->{
|
||||
if(to == null || to.entity == null) return;
|
||||
to.block().handleItem(item, to, tile);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Tile getTileTarget(Item item, Tile dest, Tile source, boolean flip){
|
||||
SorterEntity entity = dest.entity();
|
||||
|
||||
int dir = source.relativeTo(dest.x, dest.y);
|
||||
Tile to = null;
|
||||
|
||||
if(item == entity.sortItem){
|
||||
to = dest.getNearby()[dir];
|
||||
}else{
|
||||
Tile a = dest.getNearby()[Mathf.mod(dir - 1, 4)];
|
||||
Tile b = dest.getNearby()[Mathf.mod(dir + 1, 4)];
|
||||
boolean ac = a.block().acceptItem(item, a, dest);
|
||||
boolean bc = b.block().acceptItem(item, b, dest);
|
||||
|
||||
if(ac && !bc){
|
||||
to = a;
|
||||
}else if(bc && !ac){
|
||||
to = b;
|
||||
}else{
|
||||
if(dest.dump == 0){
|
||||
to = a;
|
||||
if(flip)
|
||||
dest.dump = 1;
|
||||
}else{
|
||||
to = b;
|
||||
if(flip)
|
||||
dest.dump = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildTable(Tile tile, Table table){
|
||||
SorterEntity entity = tile.entity();
|
||||
|
||||
table.addIButton("icon-arrow-left", Unit.dp.inPixels(10*3), ()->{
|
||||
int color = entity.sortItem.ordinal();
|
||||
|
||||
color --;
|
||||
if(color < 0)
|
||||
color += Item.values().length;
|
||||
|
||||
entity.sortItem = Item.values()[color];
|
||||
});
|
||||
|
||||
table.add().size(40f).units(Unit.dp);
|
||||
|
||||
table.addIButton("icon-arrow-right", Unit.dp.inPixels(10*3), ()->{
|
||||
int color = entity.sortItem.ordinal();
|
||||
|
||||
color ++;
|
||||
color %= Item.values().length;
|
||||
|
||||
entity.sortItem = Item.values()[color];
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,7 +125,7 @@ public class Sorter extends Junction{
|
||||
}
|
||||
|
||||
public static class SorterEntity extends TileEntity{
|
||||
public Item sortItem = Item.stone;
|
||||
public Item sortItem = Item.iron;
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException{
|
||||
|
||||
@@ -4,21 +4,135 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
//TODO
|
||||
public class Teleporter extends Block{
|
||||
public class Teleporter extends Block implements Configurable{
|
||||
public static final int colors = 4;
|
||||
public static final Color[] colorArray = {Color.ROYAL, Color.ORANGE, Color.SCARLET, Color.FOREST};
|
||||
|
||||
private static Array<Tile> removal = new Array<>();
|
||||
private static Array<Tile> returns = new Array<>();
|
||||
private static ObjectSet<Tile>[] teleporters = new ObjectSet[colors];
|
||||
|
||||
static{
|
||||
for(int i = 0; i < colors; i ++){
|
||||
teleporters[i] = new ObjectSet<>();
|
||||
}
|
||||
}
|
||||
|
||||
public Teleporter(String name) {
|
||||
super(name);
|
||||
update = true;
|
||||
solid = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description(){
|
||||
return "[interact]Tap block to config[]\nTeleports items to others of the same color.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
TeleporterEntity entity = tile.entity();
|
||||
|
||||
super.draw(tile);
|
||||
|
||||
Draw.color(colorArray[entity.color]);
|
||||
Draw.rect("blank", tile.worldx(), tile.worldy(), 2, 2);
|
||||
Draw.color(Color.WHITE);
|
||||
Draw.alpha(0.45f + Mathf.absin(Timers.time(), 7f, 0.26f));
|
||||
Draw.rect("teleporter-top", tile.worldx(), tile.worldy());
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
TeleporterEntity entity = tile.entity();
|
||||
|
||||
teleporters[entity.color].add(tile);
|
||||
|
||||
if(entity.totalItems() > 0){
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildTable(Tile tile, Table table){
|
||||
TeleporterEntity entity = tile.entity();
|
||||
|
||||
table.addIButton("icon-arrow-left", Unit.dp.inPixels(10*3), ()->{
|
||||
entity.color --;
|
||||
if(entity.color < 0)
|
||||
entity.color += 4;
|
||||
});
|
||||
|
||||
table.add().size(40f).units(Unit.dp);
|
||||
|
||||
table.addIButton("icon-arrow-right", Unit.dp.inPixels(10*3), ()->{
|
||||
entity.color ++;
|
||||
entity.color %= 4;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
Array<Tile> links = findLinks(tile);
|
||||
|
||||
if(links.size > 0){
|
||||
Tile target = links.get(Mathf.random(0, links.size-1));
|
||||
target.entity.addItem(item, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile dest, Tile source){
|
||||
Array<Tile> links = findLinks(dest);
|
||||
return links.size > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity(){
|
||||
return new TeleporterEntity();
|
||||
}
|
||||
|
||||
static Array<Tile> findLinks(Tile tile){
|
||||
TeleporterEntity entity = tile.entity();
|
||||
|
||||
removal.clear();
|
||||
returns.clear();
|
||||
|
||||
for(Tile other : teleporters[entity.color]){
|
||||
if(other != tile){
|
||||
if(other.block() instanceof Teleporter){
|
||||
if(other.<TeleporterEntity>entity().color != entity.color){
|
||||
removal.add(other);
|
||||
}else if(other.entity.totalItems() == 0){
|
||||
returns.add(other);
|
||||
}
|
||||
}else{
|
||||
removal.add(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(Tile remove : removal)
|
||||
teleporters[entity.color].remove(remove);
|
||||
|
||||
return returns;
|
||||
}
|
||||
|
||||
public static class TeleporterEntity extends TileEntity{
|
||||
public byte color = 0;
|
||||
@@ -33,4 +147,5 @@ public class Teleporter extends Block{
|
||||
color = stream.readByte();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user