Point defense blocks

This commit is contained in:
Anuken
2020-06-03 16:22:07 -04:00
parent 3d98de34eb
commit 6fff4ad8a1
20 changed files with 1821 additions and 1759 deletions

View File

@@ -195,7 +195,6 @@ public class Block extends UnlockableContent{
public Block(String name){
super(name);
this.solid = false;
initEntity();
}

View File

@@ -0,0 +1,118 @@
package mindustry.world.blocks.defense;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
import static mindustry.Vars.tilesize;
public class PointDefenseTurret extends Block{
public final int timerTarget = timers++;
public float retargetTime = 5f;
public @Load("block-$size") TextureRegion baseRegion;
public Color color = Color.white;
public Effect beamEffect = Fx.pointBeam;
public Effect hitEffect = Fx.pointHit;
public Effect shootEffect = Fx.sparkShoot;
public float range = 80f;
public float reloadTime = 30f;
public float rotateSpeed = 20;
public float shootCone = 5f;
public float bulletDamage = 10f;
public float shootLength = 3f;
public PointDefenseTurret(String name){
super(name);
outlineIcon = true;
update = 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[] generateIcons(){
return new TextureRegion[]{Core.atlas.find("block-" + size), Core.atlas.find(name)};
}
public class PointDefenseEntity extends TileEntity{
public float rotation = 90, reload;
public @Nullable Bulletc target;
@Override
public void updateTile(){
//retarget
if(timer(timerTarget, retargetTime)){
target = Groups.bullet.intersect(x - range, y - range, range*2, range*2).min(b -> b.team() == team || !b.type().hittable ? Float.MAX_VALUE : b.dst2(this));
}
//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());
reload -= edelta();
//shoot when possible
if(Angles.within(rotation, dest, shootCone) && reload <= 0f){
if(target.damage() > bulletDamage){
target.damage(target.damage() - bulletDamage);
}else{
target.remove();
}
Tmp.v1.trns(rotation, shootLength);
beamEffect.at(x + Tmp.v1.x, y + Tmp.v1.y, rotation, color, new Vec2().set(target));
shootEffect.at(x + Tmp.v1.x, y + Tmp.v1.y, rotation, color);
hitEffect.at(target.x(), target.y(), color);
reload = reloadTime;
}
}else{
target = null;
}
}
@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);
}
@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

@@ -1,89 +0,0 @@
package mindustry.world.blocks.experimental;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.world.*;
import mindustry.world.blocks.payloads.*;
import mindustry.world.blocks.production.*;
import static mindustry.Vars.*;
//pointless, will definitely be removed eventually
public class BlockLauncher extends PayloadAcceptor{
static final IntArray positions = new IntArray();
public float range = 150;
public BlockLauncher(String name){
super(name);
update = true;
size = 3;
}
public class BlockLauncherEntity extends PayloadAcceptorEntity<BlockPayload>{
@Override
public void draw(){
super.draw();
drawPayload();
}
@Override
public boolean acceptPayload(Tilec source, Payload payload){
return this.payload == null && payload instanceof BlockPayload;
}
@Override
public void updateTile(){
if(moveInPayload() && efficiency() >= 0.99f){
Effects.shake(4f, 4f, this);
Fx.producesmoke.at(this);
positions.clear();
Geometry.circle(tileX(), tileY(), world.width(), world.height(), (int)(range / tilesize), (cx, cy) -> {
if(Build.validPlace(team, cx, cy, payload.entity.block(), 0)){
positions.add(Point2.pack(cx, cy));
}
});
if(positions.isEmpty()) return;
int pick = positions.random();
LaunchedBlock launch = new LaunchedBlock(Point2.x(pick), Point2.y(pick), payload.entity.block(), team);
Fx.blockTransfer.at(x, y, 0, launch);
Time.run(Fx.blockTransfer.lifetime, () -> {
float ex = launch.x * tilesize + launch.block.offset(), ey = launch.y * tilesize + launch.block.offset();
if(Build.validPlace(launch.team, launch.x, launch.y, launch.block, 0)){
world.tile(launch.x, launch.y).setBlock(launch.block, launch.team);
Fx.placeBlock.at(ex, ey, launch.block.size);
}else{
Fx.breakBlock.at(ex, ey, launch.block.size);
Fx.explosion.at(ex, ey);
}
});
payload = null;
}
}
}
public static class LaunchedBlock{
public final int x, y;
public final Block block;
public final Team team;
public LaunchedBlock(int x, int y, Block block, Team team){
this.x = x;
this.y = y;
this.block = block;
this.team = team;
}
}
}

View File

@@ -37,7 +37,7 @@ public class AttributeSmelter extends GenericSmelter{
public void setStats(){
super.setStats();
stats.add(BlockStat.tiles, attribute, boostScale);
stats.add(BlockStat.affinities, attribute, boostScale);
}
public class AttributeSmelterEntity extends SmelterEntity{

View File

@@ -17,7 +17,7 @@ import mindustry.world.meta.*;
import static mindustry.Vars.tilesize;
public class RepairPoint extends Block{
private static Rect rect = new Rect();
private static final Rect rect = new Rect();
public int timerTarget = timers++;