Added tractor beam turret

This commit is contained in:
Anuken
2020-07-02 14:02:33 -04:00
parent 0a7e40bd23
commit cecb5cf4b4
45 changed files with 4825 additions and 4509 deletions

View File

@@ -77,7 +77,7 @@ public class Build{
return false;
}
if(state.teams.eachEnemyCore(team, core -> Mathf.dst(x * tilesize + type.offset(), y * tilesize + type.offset(), core.x(), core.y()) < state.rules.enemyCoreBuildRadius + type.size * tilesize / 2f)){
if(state.teams.eachEnemyCore(team, core -> Mathf.dst(x * tilesize + type.offset(), y * tilesize + type.offset(), core.x, core.y) < state.rules.enemyCoreBuildRadius + type.size * tilesize / 2f)){
return false;
}

View File

@@ -33,7 +33,7 @@ public class ForceProjector extends Block{
private static ForceProjectorEntity paramEntity;
private static Cons<Shielderc> shieldConsumer = trait -> {
if(trait.team() != paramEntity.team() && Intersector.isInsideHexagon(paramEntity.x(), paramEntity.y(), paramEntity.realRadius() * 2f, trait.x(), trait.y())){
if(trait.team() != paramEntity.team() && Intersector.isInsideHexagon(paramEntity.x, paramEntity.y, paramEntity.realRadius() * 2f, trait.x(), trait.y())){
trait.absorb();
Fx.absorb.at(trait);
paramEntity.hit = 1f;

View File

@@ -77,7 +77,7 @@ public class MendProjector extends Block{
indexer.eachBlock(this, realRange, other -> other.damaged(), other -> {
other.heal(other.maxHealth() * (healPercent + phaseHeat * phaseBoost) / 100f * efficiency());
Fx.healBlockFull.at(other.x(), other.y(), other.block().size, Tmp.c1.set(baseColor).lerp(phaseColor, phaseHeat));
Fx.healBlockFull.at(other.x, other.y, other.block().size, Tmp.c1.set(baseColor).lerp(phaseColor, phaseHeat));
});
}
}

View File

@@ -13,6 +13,7 @@ import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
@@ -51,6 +52,14 @@ public class PointDefenseTurret extends Block{
return new TextureRegion[]{baseRegion, region};
}
@Override
public void setStats(){
super.setStats();
stats.add(BlockStat.shootRange, range / tilesize, StatUnit.blocks);
stats.add(BlockStat.reload, 60f / reloadTime, StatUnit.none);
}
public class PointDefenseEntity extends Building{
public float rotation = 90, reload;
public @Nullable Bullet target;
@@ -66,7 +75,7 @@ public class PointDefenseTurret extends Block{
//look at target
if(target != null && target.within(this, range) && target.team() != team && target.type().hittable){
float dest = angleTo(target);
rotation = Angles.moveToward(rotation,dest, rotateSpeed * edelta());
rotation = Angles.moveToward(rotation, dest, rotateSpeed * edelta());
reload -= edelta();
//shoot when possible

View File

@@ -0,0 +1,139 @@
package mindustry.world.blocks.defense;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.annotations.Annotations.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class TractorBeamTurret extends Block{
public final int timerTarget = timers++;
public float retargetTime = 5f;
public @Load("block-$size") TextureRegion baseRegion;
public @Load("@-laser") TextureRegion laser;
public @Load("@-laser-end") TextureRegion laserEnd;
public float range = 80f;
public float rotateSpeed = 10;
public float shootCone = 6f;
public float laserWidth = 0.6f;
public float force = 0.3f;
public float damage = 0f;
public boolean targetAir = true, targetGround = false;
public TractorBeamTurret(String name){
super(name);
update = true;
solid = true;
outlineIcon = true;
}
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.dashCircle(x * tilesize + offset(), y * tilesize + offset(), range, Pal.accent);
}
@Override
public TextureRegion[] icons(){
return new TextureRegion[]{baseRegion, region};
}
@Override
public void setStats(){
super.setStats();
stats.add(BlockStat.shootRange, range / tilesize, StatUnit.blocks);
stats.add(BlockStat.targetsAir, targetAir);
stats.add(BlockStat.targetsGround, targetGround);
stats.add(BlockStat.damage, damage * 60f, StatUnit.perSecond);
}
public class TractorBeamEntity extends Building{
public float rotation = 90;
public @Nullable Unit target;
public float lastX, lastY, strength;
public boolean any;
@Override
public void updateTile(){
//retarget
if(timer(timerTarget, retargetTime)){
target = Units.closestEnemy(team, x, y, range, u -> u.checkTarget(targetAir, targetGround));
}
//look at target
if(target != null && target.within(this, range) && target.team() != team && target.type().flying){
any = true;
float dest = angleTo(target);
rotation = Angles.moveToward(rotation,dest, rotateSpeed * edelta());
lastX = target.x;
lastY = target.y;
strength = Mathf.lerpDelta(strength, 1f, 0.1f);
if(damage > 0){
target.damageContinuous(damage);
}
//shoot when possible
if(Angles.within(rotation, dest, shootCone)){
target.impulse(Tmp.v1.set(this).sub(target).limit(force * efficiency() * timeScale));
}
}else{
target = null;
strength = Mathf.lerpDelta(strength, 0, 0.1f);
}
}
@Override
public void drawSelect(){
Drawf.dashCircle(x, y, range, Pal.accent);
}
@Override
public void draw(){
Draw.rect(baseRegion, x, y);
Draw.rect(region, x, y, rotation - 90);
//draw laser if applicable
if(any){
Draw.z(Layer.bullet);
float ang = angleTo(lastX, lastY);
float len = 5f;
Draw.mixcol(Color.white, Mathf.absin(4f, 0.6f));
Drawf.laser(team, laser, laserEnd,
x + Angles.trnsx(ang, len), y + Angles.trnsy(ang, len),
lastX, lastY, strength * efficiency() * laserWidth);
Draw.mixcol();
}
}
@Override
public void write(Writes write){
super.write(write);
write.f(rotation);
}
@Override
public void read(Reads read, byte revision){
super.read(read, revision);
rotation = read.f();
}
}
}

View File

@@ -70,12 +70,12 @@ public abstract class Turret extends Block{
public @Load("block-$size") TextureRegion baseRegion;
public @Load("@-heat") TextureRegion heatRegion;
public Cons<TurretEntity> drawer = tile -> Draw.rect(region, tile.x() + tr2.x, tile.y() + tr2.y, tile.rotation - 90);
public Cons<TurretEntity> drawer = tile -> Draw.rect(region, tile.x + tr2.x, tile.y + tr2.y, tile.rotation - 90);
public Cons<TurretEntity> heatDrawer = tile -> {
if(tile.heat <= 0.00001f) return;
Draw.color(heatColor, tile.heat);
Draw.blend(Blending.additive);
Draw.rect(heatRegion, tile.x() + tr2.x, tile.y() + tr2.y, tile.rotation - 90);
Draw.rect(heatRegion, tile.x + tr2.x, tile.y + tr2.y, tile.rotation - 90);
Draw.blend();
Draw.color();
};

View File

@@ -62,9 +62,9 @@ public class MassDriver extends Block{
//if so, draw a dotted line towards it while it is in range
float sin = Mathf.absin(Time.time(), 6f, 1f);
Tmp.v1.set(x * tilesize + offset(), y * tilesize + offset()).sub(selected.x(), selected.y()).limit((size / 2f + 1) * tilesize + sin + 0.5f);
Tmp.v1.set(x * tilesize + offset(), y * tilesize + offset()).sub(selected.x, selected.y).limit((size / 2f + 1) * tilesize + sin + 0.5f);
float x2 = x * tilesize - Tmp.v1.x, y2 = y * tilesize - Tmp.v1.y,
x1 = selected.x() + Tmp.v1.x, y1 = selected.y() + Tmp.v1.y;
x1 = selected.x + Tmp.v1.x, y1 = selected.y + Tmp.v1.y;
int segs = (int)(selected.dst(x * tilesize, y * tilesize) / tilesize);
Lines.stroke(4f, Pal.gray);

View File

@@ -75,8 +75,8 @@ public class PayloadConveyor extends Block{
//differing sizes
(accept.block().size > size &&
(rotation() % 2 == 0 ? //check orientation
Math.abs(accept.y() - y) <= (accept.block().size * tilesize - size * tilesize)/2f : //check Y alignment
Math.abs(accept.x() - x) <= (accept.block().size * tilesize - size * tilesize)/2f //check X alignment
Math.abs(accept.y - y) <= (accept.block().size * tilesize - size * tilesize)/2f : //check Y alignment
Math.abs(accept.x - x) <= (accept.block().size * tilesize - size * tilesize)/2f //check X alignment
)))){
next = accept;
}else{

View File

@@ -53,7 +53,7 @@ public class BlockPayload implements Payload{
@Override
public void draw(){
Drawf.shadow(entity.x(), entity.y(), entity.block().size * tilesize * 2f);
Draw.rect(entity.block().icon(Cicon.full), entity.x(), entity.y());
Drawf.shadow(entity.x, entity.y, entity.block().size * tilesize * 2f);
Draw.rect(entity.block().icon(Cicon.full), entity.x, entity.y);
}
}

View File

@@ -122,10 +122,10 @@ public class PowerNode extends PowerBlock{
Drawf.circles(x * tilesize + offset(), y * tilesize + offset(), laserRange * tilesize);
getPotentialLinks(tile, other -> {
Drawf.square(other.x(), other.y(), other.block().size * tilesize / 2f + 2f, Pal.place);
Drawf.square(other.x, other.y, other.block().size * tilesize / 2f + 2f, Pal.place);
insulators(tile.x, tile.y, other.tileX(), other.tileY(), cause -> {
Drawf.square(cause.x(), cause.y(), cause.block().size * tilesize / 2f + 2f, Pal.plastanium);
Drawf.square(cause.x, cause.y, cause.block().size * tilesize / 2f + 2f, Pal.plastanium);
});
});
@@ -158,7 +158,7 @@ public class PowerNode extends PowerBlock{
}
protected boolean overlaps(Building src, Building other, float range){
return overlaps(src.x(), src.y(), other.tile(), range);
return overlaps(src.x, src.y, other.tile(), range);
}
protected boolean overlaps(Tile src, Tile other, float range){
@@ -352,7 +352,7 @@ public class PowerNode extends PowerBlock{
boolean linked = linked(link);
if(linked){
Drawf.square(link.x(), link.y(), link.block().size * tilesize / 2f + 1f, Pal.place);
Drawf.square(link.x, link.y, link.block().size * tilesize / 2f + 1f, Pal.place);
}
}
}
@@ -387,7 +387,7 @@ public class PowerNode extends PowerBlock{
}
protected void drawLaserTo(Building target){
drawLaser(team, x, y, target.x(), target.y(), power.graph.getSatisfaction(), size, target.block().size);
drawLaser(team, x, y, target.x, target.y, power.graph.getSatisfaction(), size, target.block().size);
}
@Override

View File

@@ -40,8 +40,8 @@ public class PayloadAcceptor extends Block{
//if the other block is smaller, check alignment
(accept.block().size < size &&
(accept.rotation() % 2 == 0 ? //check orientation; make sure it's aligned properly with this block.
Math.abs(accept.y() - tile.y()) <= (size * tilesize - accept.block().size * tilesize)/2f : //check Y alignment
Math.abs(accept.x() - tile.x()) <= (size * tilesize - accept.block().size * tilesize)/2f //check X alignment
Math.abs(accept.y - tile.y) <= (size * tilesize - accept.block().size * tilesize)/2f : //check Y alignment
Math.abs(accept.x - tile.x) <= (size * tilesize - accept.block().size * tilesize)/2f //check X alignment
)) && (!accept.block().rotate || accept.front() == tile || !accept.block().outputFacing) //make sure it's facing this block
);
}

View File

@@ -236,7 +236,7 @@ public class CoreBlock extends StorageBlock{
for(int i = 0; i < 4; i++){
Point2 p = Geometry.d8edge[i];
float offset = -Math.max(t.block().size - 1, 0) / 2f * tilesize;
Draw.rect("block-select", t.x() + offset * p.x, t.y() + offset * p.y, i * 90);
Draw.rect("block-select", t.x + offset * p.x, t.y + offset * p.y, i * 90);
}
};
if(proximity.contains(e -> isContainer(e) && e.items == items)){

View File

@@ -28,6 +28,8 @@ public class RepairPoint extends Block{
public @Load("laser") TextureRegion laser;
public @Load("laser-end") TextureRegion laserEnd;
public Color laserColor = Color.valueOf("e8ffd7");
public RepairPoint(String name){
super(name);
update = true;
@@ -60,7 +62,7 @@ public class RepairPoint extends Block{
}
public class RepairPointEntity extends Building{
public Unitc target;
public Unit target;
public float strength, rotation = 90;
@Override
@@ -75,7 +77,7 @@ public class RepairPoint extends Block{
float ang = angleTo(target);
float len = 5f;
Draw.color(Color.valueOf("e8ffd7"));
Draw.color(laserColor);
Drawf.laser(team, laser, laserEnd,
x + Angles.trnsx(ang, len), y + Angles.trnsy(ang, len),
target.x(), target.y(), strength);

View File

@@ -13,15 +13,15 @@ public class DrawWeave extends DrawBlock{
@Override
public void draw(GenericCrafterEntity entity){
Draw.rect(bottom, entity.x(), entity.y());
Draw.rect(weave, entity.x(), entity.y(), entity.totalProgress);
Draw.rect(bottom, entity.x, entity.y);
Draw.rect(weave, entity.x, entity.y, entity.totalProgress);
Draw.color(Pal.accent);
Draw.alpha(entity.warmup);
Lines.lineAngleCenter(
entity.x() + Mathf.sin(entity.totalProgress, 6f, Vars.tilesize / 3f * entity.block.size),
entity.y(),
entity.x + Mathf.sin(entity.totalProgress, 6f, Vars.tilesize / 3f * entity.block.size),
entity.y,
90,
entity.block.size * Vars.tilesize / 2f);