Various prototypes

This commit is contained in:
Anuken
2020-04-15 12:44:53 -04:00
parent 51226d6c88
commit 0eaf9bc9c6
15 changed files with 2985 additions and 2730 deletions
@@ -1,58 +1,233 @@
package mindustry.world.blocks.distribution;
import arc.*;
import arc.graphics.g2d.*;
import arc.input.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import mindustry.world.*;
import static mindustry.Vars.*;
//TODO rename
public class MassConveyor extends Block{
public float moveTime = 70f;
public TextureRegion topRegion, edgeRegion;
public MassConveyor(String name){
super(name);
layer = Layer.overlay;
size = 3;
rotate = true;
update = true;
}
public class MassConveyorEntity extends TileEntity{
public Conveyable item;
public float progress;
public @Nullable Tilec next;
@Override
public void load(){
super.load();
topRegion = Core.atlas.find(name + "-top");
edgeRegion = Core.atlas.find(name + "-edge");
}
public class MassConveyorEntity extends TileEntity implements MassAcceptor{
public @Nullable Payload item;
public float progress, itemRotation;
public @Nullable MassAcceptor next;
public boolean blocked;
public int step = -1, stepAccepted = -1;
@Override
public void onProximityUpdate(){
super.onProximityUpdate();
next = front();
Tilec accept = nearby(Geometry.d4[rotation()].x * size, Geometry.d4[rotation()].y * size);
//next block must be aligned and of the same size
if(next.block().size != size || x + Geometry.d4[rotation()].x * size != next.tileX() || y + Geometry.d4[rotation()].y * size != next.tileY()){
next = null;
if(accept instanceof MassAcceptor && accept.block().size == size &&
tileX() + Geometry.d4[rotation()].x * size == accept.tileX() && tileY() + Geometry.d4[rotation()].y * size == accept.tileY()){
next = (MassAcceptor)accept;
}
int ntrns = 1 + size/2;
Tile next = tile.getNearby(Geometry.d4[rotation()].x * ntrns, Geometry.d4[rotation()].y * ntrns);
blocked = next != null && next.solid();
}
@Override
public void updateTile(){
progress += edelta();
if(progress >= moveTime){
//todo step
progress = 0;
progress = Time.time() % moveTime;
//TODO DEBUG
if(Core.input.keyTap(KeyCode.G) && world.tileWorld(Core.input.mouseWorld().x, Core.input.mouseWorld().y) == tile){
item = new UnitPayload(UnitTypes.dagger.create(Team.sharded));
itemRotation = rotation() * 90;
}
int curStep = curStep();
if(curStep > step){
if(step != -1 && stepAccepted != curStep){
if(canMove()){
//move forward.
next.handleMass(item, this);
item = null;
}
}
step = curStep;
}
//dumping item forward.
if(fract() >= 0.5f && item != null && !blocked && next == null){
float trnext = fract() * size * tilesize, cx = Geometry.d4[rotation()].x, cy = Geometry.d4[rotation()].y, rot = rotation() * 90;
item.dump(x + cx * trnext, y + cy * trnext, rotation() * 90);
item = null;
}
}
@Override
public void draw(){
super.draw();
float dst = 0.8f;
float glow = Math.max((dst - (Math.abs(fract() - 0.5f) * 2)) / dst, 0);
Draw.mixcol(Pal.accent, glow);
float trnext = fract() * size * tilesize, trprev = size * tilesize * (fract() - 1), rot = rotation() * 90;
TextureRegion clipped = clipRegion(tile.getHitbox(Tmp.r1), tile.getHitbox(Tmp.r2).move(trnext, 0), topRegion);
float s = tilesize * size;
//next
Tmp.v1.set((s-clipped.getWidth()*Draw.scl) + clipped.getWidth()/2f*Draw.scl - s/2f, s-clipped.getHeight()*Draw.scl + clipped.getHeight()/2f*Draw.scl - s/2f).rotate(rot);
Draw.rect(clipped, x + Tmp.v1.x, y + Tmp.v1.y, rot);
clipped = clipRegion(tile.getHitbox(Tmp.r1), tile.getHitbox(Tmp.r2).move(trprev, 0), topRegion);
//prev
Tmp.v1.set(- s/2f + clipped.getWidth()/2f*Draw.scl, - s/2f + clipped.getHeight()/2f*Draw.scl).rotate(rot);
Draw.rect(clipped, x + Tmp.v1.x, y + Tmp.v1.y, rot);
Draw.reset();
for(int i = 0; i < 4; i++){
if(!blends(i)){
Draw.rect(edgeRegion, x, y, i * 90);
}
}
}
@Override
public void draw(){
super.draw();
public void drawLayer(){
float fract = !blocked ? fract() : fract() > 0.5f ? 1f - fract() : fract();
float trnext = fract * size * tilesize, cx = Geometry.d4[rotation()].x, cy = Geometry.d4[rotation()].y, rot = Mathf.slerp(itemRotation, rotation() * 90, fract);
if(item != null){
Draw.color(0, 0, 0, 0.4f);
float size = 21;
Draw.rect("circle-shadow", x + cx * trnext, y + cy * trnext, size, size);
Draw.color();
item.draw(x + cx * trnext, y + cy * trnext, rot);
}
}
@Override
public void drawLayer(){
public boolean acceptMass(Payload item, Tilec source){
return this.item == null;
}
@Override
public void handleMass(Payload item, Tilec source){
this.item = item;
this.stepAccepted = curStep();
this.itemRotation = source.rotation() * 90;
}
boolean blends(int direction){
if(direction == rotation()){
return !blocked;
}else{
Tilec accept = nearby(Geometry.d4[direction].x * size, Geometry.d4[direction].y * size);
return accept instanceof MassAcceptor && accept.block().size == size &&
accept.tileX() + Geometry.d4[accept.rotation()].x * size == tileX() && accept.tileY() + Geometry.d4[accept.rotation()].y * size == tileY();
}
}
boolean canMove(){
return item != null && next != null && next.acceptMass(item, this);
}
TextureRegion clipRegion(Rect bounds, Rect sprite, TextureRegion region){
Rect over = Tmp.r3;
boolean overlaps = Intersector.intersectRectangles(bounds, sprite, over);
TextureRegion out = Tmp.tr1;
out.set(region.getTexture());
if(overlaps){
float w = region.getU2() - region.getU();
float h = region.getV2() - region.getV();
float x = region.getU(), y = region.getV();
float newX = (over.x - sprite.x) / sprite.width * w + x;
float newY = (over.y - sprite.y) / sprite.height * h + y;
float newW = (over.width / sprite.width) * w, newH = (over.height / sprite.height) * h;
out.set(newX, newY, newX + newW, newY + newH);
}else{
out.set(0f, 0f, 0f, 0f);
}
return out;
}
int curStep(){
return (int)(Time.time() / moveTime);
}
float fract(){
return Interpolation.pow5.apply(progress / moveTime);
}
}
public interface Conveyable{
void drawConvey(float x, float y, float rotation);
public interface MassAcceptor extends Tilec{
boolean acceptMass(Payload item, Tilec source);
void handleMass(Payload item, Tilec source);
}
public interface Payload{
void draw(float x, float y, float rotation);
void dump(float x, float y, float rotation);
}
public static class UnitPayload implements Payload{
Unitc unit;
public UnitPayload(Unitc unit){
this.unit = unit;
}
@Override
public void dump(float x, float y, float rotation){
unit.set(x, y);
unit.rotation(rotation);
unit.add();
}
@Override
public void draw(float x, float y, float rotation){
Draw.rect(unit.type().icon(Cicon.full), x, y, rotation - 90);
}
}
}
@@ -36,7 +36,7 @@ public class ImpactReactor extends PowerGenerator{
liquidCapacity = 30f;
hasItems = true;
outputsPower = consumesPower = true;
bottomRegion = reg("-bottom");
bottomRegion = reg("-bottom");
plasmaRegions = new int[plasmas];
for(int i = 0; i < plasmas; i++){
plasmaRegions[i] = reg("-plasma-" + i);
@@ -100,8 +100,8 @@ public class ImpactReactor extends PowerGenerator{
public void draw(){
Draw.rect(reg(bottomRegion), x, y);
for(int i = 0; i < plasmas; i++){
float r = size * tilesize - 3f + Mathf.absin(Time.time(), 2f + i * 1f, 5f - i * 0.5f);
for(int i = 0; i < plasmas; i++){
float r = size * tilesize - 3f + Mathf.absin(Time.time(), 2f + i * 1f, 5f - i * 0.5f);
Draw.color(plasma1, plasma2, (float)i / plasmas);
Draw.alpha((0.3f + Mathf.absin(Time.time(), 2f + i * 2f, 0.3f + i * 0.05f)) * warmup);