mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-03 13:30:25 +07:00
Bridge sprite cleanup
This commit is contained in:
parent
9c240850b8
commit
b0126206e1
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
@ -219,6 +219,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
return status.hasEffect(effect);
|
||||
}
|
||||
|
||||
//TODO optimize
|
||||
public void avoidOthers(float scaling){
|
||||
hitbox(queryRect);
|
||||
queryRect.setSize(queryRect.getWidth() * scaling);
|
||||
|
@ -2,6 +2,7 @@ package io.anuke.mindustry.world;
|
||||
|
||||
/**Methods for a packed position 'struct', contained in an int.*/
|
||||
public class Pos{
|
||||
public static final int invalid = get(-1, -1);
|
||||
|
||||
/**Returns packed position from an x/y position. The values must be within short limits.*/
|
||||
public static int get(int x, int y){
|
||||
|
@ -7,12 +7,10 @@ import io.anuke.arc.collection.IntArray;
|
||||
import io.anuke.arc.collection.IntSet;
|
||||
import io.anuke.arc.collection.IntSet.IntSetIterator;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.CapStyle;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Lines;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Geometry;
|
||||
import io.anuke.arc.math.geom.Point2;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.entities.type.Player;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
@ -34,8 +32,6 @@ import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class ItemBridge extends Block{
|
||||
protected static int lastPlaced;
|
||||
|
||||
protected int timerTransport = timers++;
|
||||
protected int range;
|
||||
protected float transportTime = 2f;
|
||||
@ -85,29 +81,39 @@ public class ItemBridge extends Block{
|
||||
|
||||
@Override
|
||||
public void playerPlaced(Tile tile){
|
||||
Tile last = world.tile(lastPlaced);
|
||||
if(linkValid(tile, last)){
|
||||
ItemBridgeEntity entity = last.entity();
|
||||
if(!linkValid(last, world.tile(entity.link))){
|
||||
Call.linkItemBridge(null, last, tile);
|
||||
Tile link = findLink(tile.x, tile.y);
|
||||
if(linkValid(tile, link)){
|
||||
Call.linkItemBridge(null, link, tile);
|
||||
}
|
||||
}
|
||||
|
||||
public Tile findLink(int x, int y){
|
||||
for(int j = 0; j < 4; j ++){
|
||||
Point2 p = Geometry.d4(j + 1);
|
||||
for(int i = 1; i <= range; i++){
|
||||
Tile tile = world.tile(x + p.x * i, y + p.y * i);
|
||||
|
||||
if(tile == null) break;
|
||||
if(tile.block() == this && tile.<ItemBridgeEntity>entity().link == Pos.invalid){
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
lastPlaced = tile.pos();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||
Lines.stroke(2f);
|
||||
Draw.color(Pal.placing);
|
||||
for(int i = 0; i < 4; i++){
|
||||
Lines.dashLine(
|
||||
x * tilesize + Geometry.d4[i].x * (tilesize / 2f + 2),
|
||||
y * tilesize + Geometry.d4[i].y * (tilesize / 2f + 2),
|
||||
x * tilesize + Geometry.d4[i].x * (range + 0.5f) * tilesize,
|
||||
y * tilesize + Geometry.d4[i].y * (range + 0.5f) * tilesize,
|
||||
range);
|
||||
}
|
||||
Tile link = findLink(x, y);
|
||||
|
||||
Lines.stroke(1f, Pal.placing);
|
||||
if(link != null){
|
||||
int rot = link.absoluteRelativeTo(x, y);
|
||||
float w = (link.x == x ? tilesize : Math.abs(link.x - x) * tilesize - tilesize);
|
||||
float h = (link.y == y ? tilesize : Math.abs(link.y - y) * tilesize - tilesize);
|
||||
Lines.rect((x + link.x)/2f * tilesize - w/2f, (y + link.y)/2f * tilesize - h/2f, w, h);
|
||||
Fill.poly(link.x * tilesize + Geometry.d4[rot].x * tilesize, link.y * tilesize + Geometry.d4[rot].y * tilesize, 3, 2.8f, link.absoluteRelativeTo(x, y)*90);
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@ -175,6 +181,7 @@ public class ItemBridge extends Block{
|
||||
|
||||
Tile other = world.tile(entity.link);
|
||||
if(!linkValid(tile, other)){
|
||||
entity.link = Pos.invalid;
|
||||
tryDump(tile);
|
||||
entity.uptime = 0f;
|
||||
}else{
|
||||
@ -310,7 +317,7 @@ public class ItemBridge extends Block{
|
||||
}
|
||||
|
||||
public static class ItemBridgeEntity extends TileEntity{
|
||||
public int link = -1;
|
||||
public int link = Pos.invalid;
|
||||
public IntSet incoming = new IntSet();
|
||||
public float uptime;
|
||||
public float time;
|
||||
|
Loading…
Reference in New Issue
Block a user