Regen projector 'done'
This commit is contained in:
@@ -3,7 +3,6 @@ package mindustry.world.blocks.defense;
|
||||
import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
@@ -23,27 +22,19 @@ public class RegenProjector extends Block{
|
||||
private static final IntFloatMap mendMap = new IntFloatMap();
|
||||
private static long lastUpdateFrame = -1;
|
||||
|
||||
//cached points per-block for drawing convenience
|
||||
protected @Nullable Vec2[] drawPoints;
|
||||
|
||||
public int rangeLength = 14, rangeWidth = 5;
|
||||
public int range = 14;
|
||||
//per frame
|
||||
public float healPercent = 12f / 60f;
|
||||
|
||||
public DrawBlock drawer = new DrawMulti(new DrawRegion("-bottom"), new DrawSideRegion(true));
|
||||
|
||||
public float effectChance = 0.011f;
|
||||
public float effectChance = 0.013f;
|
||||
public Effect effect = Fx.regenParticle;
|
||||
|
||||
public float beamSpacing = 60f * 7f, beamWidening = 5f, beamLenScl = 1.2f, beamStroke = 2f;
|
||||
public Interp beamInterp = Interp.pow2Out;
|
||||
public int beams = 6;
|
||||
|
||||
public RegenProjector(String name){
|
||||
super(name);
|
||||
solid = true;
|
||||
update = true;
|
||||
rotate = true;
|
||||
group = BlockGroup.projectors;
|
||||
hasPower = true;
|
||||
hasItems = true;
|
||||
@@ -56,28 +47,7 @@ public class RegenProjector extends Block{
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||
super.drawPlace(x, y, rotation, valid);
|
||||
|
||||
drawBounds(x * tilesize + offset, y * tilesize + offset, rotation);
|
||||
}
|
||||
|
||||
public void drawBounds(float x, float y, int rotation){
|
||||
if(drawPoints == null){
|
||||
drawPoints = new Vec2[]{
|
||||
new Vec2(1f, -rangeWidth),
|
||||
new Vec2(1f + rangeLength, -rangeWidth),
|
||||
new Vec2(1f + rangeLength, rangeWidth),
|
||||
new Vec2(1f + 0f, rangeWidth),
|
||||
};
|
||||
for(var v : drawPoints){
|
||||
v.scl(tilesize);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 4; i++){
|
||||
Tmp.v1.set(drawPoints[i]).rotate(rotation * 90).add(x, y);
|
||||
Tmp.v2.set(drawPoints[(i + 1) % 4]).rotate(rotation * 90).add(x, y);
|
||||
|
||||
Drawf.dashLine(Pal.accent, Tmp.v1.x, Tmp.v1.y, Tmp.v2.x, Tmp.v2.y);
|
||||
}
|
||||
Drawf.dashSquare(Pal.accent, x, y, range * tilesize);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,25 +75,12 @@ public class RegenProjector extends Block{
|
||||
public Seq<Building> targets = new Seq<>();
|
||||
public int lastChange = -2;
|
||||
public float warmup, totalTime;
|
||||
public boolean didRegen = false;
|
||||
|
||||
public void updateTargets(){
|
||||
targets.clear();
|
||||
taken.clear();
|
||||
float rot = rotation * 90;
|
||||
|
||||
for(int cy = -rangeWidth; cy <= rangeWidth; cy++){
|
||||
for(int cx = 1; cx <= rangeLength + 1; cx++){
|
||||
|
||||
//TODO handle offset
|
||||
float wx = x/tilesize + Angles.trnsx(rot, cx, cy), wy = y/tilesize + Angles.trnsy(rot, cx, cy);
|
||||
|
||||
Building build = world.build((int)wx, (int)wy);
|
||||
|
||||
if(build != null && build.team == team && taken.add(build.id)){
|
||||
targets.add(build);
|
||||
}
|
||||
}
|
||||
}
|
||||
indexer.eachBlock(team, Tmp.r1.setCentered(x, y, range * tilesize), b -> true, targets::add);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,14 +90,18 @@ public class RegenProjector extends Block{
|
||||
updateTargets();
|
||||
}
|
||||
|
||||
warmup = Mathf.approachDelta(warmup, consValid() ? 1f : 0f, 1f / 70f);
|
||||
//TODO should warmup depend on didRegen?
|
||||
warmup = Mathf.approachDelta(warmup, consValid() && didRegen ? 1f : 0f, 1f / 70f);
|
||||
totalTime += warmup * Time.delta;
|
||||
didRegen = false;
|
||||
|
||||
if(consValid()){
|
||||
//use Math.max to prevent stacking
|
||||
for(Building build : targets){
|
||||
if(!build.damaged()) continue;
|
||||
|
||||
didRegen = true;
|
||||
|
||||
int pos = build.pos();
|
||||
//TODO periodic effect
|
||||
float value = mendMap.get(pos);
|
||||
@@ -165,10 +126,19 @@ public class RegenProjector extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean productionValid(){
|
||||
return didRegen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSelect(){
|
||||
super.drawSelect();
|
||||
drawBounds(x, y, rotation);
|
||||
|
||||
Drawf.dashSquare(Pal.accent, x, y, range * tilesize);
|
||||
for(var target : targets){
|
||||
Drawf.selected(target, Pal.accent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -184,26 +154,6 @@ public class RegenProjector extends Block{
|
||||
@Override
|
||||
public void draw(){
|
||||
drawer.drawBase(this);
|
||||
|
||||
for(int i = 0; i < beams; i++){
|
||||
float life = beamInterp.apply((totalTime / beamSpacing + i / (float)beams) % 1f);
|
||||
float len = life * rangeLength*beamLenScl * tilesize + size * tilesize/2f;
|
||||
float width = Math.min(life * rangeWidth * 2f * tilesize * beamWidening, rangeWidth * 2f * tilesize);
|
||||
float stroke = (0.5f + beamStroke * life) * warmup;
|
||||
Draw.z(Layer.effect);
|
||||
|
||||
Lines.stroke(stroke, Pal.accent);
|
||||
Draw.alpha(1f - Mathf.curve(life, 0.5f));
|
||||
Lines.lineAngleCenter(
|
||||
x + Angles.trnsx(rotdeg(), len),
|
||||
y + Angles.trnsy(rotdeg(), len),
|
||||
rotdeg() + 90f,
|
||||
width
|
||||
);
|
||||
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,6 +32,11 @@ public class DrawGlowRegion extends DrawBlock{
|
||||
this.rotate = rotate;
|
||||
}
|
||||
|
||||
|
||||
public DrawGlowRegion(String suffix){
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
if(build.warmup() <= 0.001f) return;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package mindustry.world.draw;
|
||||
|
||||
import arc.util.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
public abstract class DrawPartial extends DrawBlock{
|
||||
|
||||
@Override
|
||||
public void drawPlan(Block block, BuildPlan plan, Eachable<BuildPlan> list){}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package mindustry.world.draw;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class DrawPulseShape extends DrawPartial{
|
||||
public Color color = Pal.accent.cpy();
|
||||
public float stroke = 2f, timeScl = 100f, minStroke = 0.2f;
|
||||
public float radiusScl = 1f;
|
||||
public float layer = -1f;
|
||||
public boolean square = true;
|
||||
|
||||
public DrawPulseShape(boolean square){
|
||||
this.square = square;
|
||||
}
|
||||
|
||||
public DrawPulseShape(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
float pz = Draw.z();
|
||||
if(layer > 0) Draw.z(layer);
|
||||
|
||||
float f = 1f - (Time.time / timeScl) % 1f;
|
||||
float rad = build.block.size * tilesize / 2f * radiusScl;
|
||||
|
||||
Draw.color(color);
|
||||
Lines.stroke((stroke * f + minStroke) * build.warmup());
|
||||
|
||||
if(square){
|
||||
Lines.square(build.x, build.y, Math.min(1f + (1f - f) * rad, rad));
|
||||
}else{
|
||||
float r = Math.max(0f, Mathf.clamp(2f - f * 2f) * rad - f - 0.2f), w = Mathf.clamp(0.5f - f) * rad * 2f;
|
||||
Lines.beginLine();
|
||||
for(int i = 0; i < 4; i++){
|
||||
Lines.linePoint(build.x + Geometry.d4(i).x * r + Geometry.d4(i).y * w, build.y + Geometry.d4(i).y * r - Geometry.d4(i).x * w);
|
||||
if(f < 0.5f) Lines.linePoint(build.x + Geometry.d4(i).x * r - Geometry.d4(i).y * w, build.y + Geometry.d4(i).y * r + Geometry.d4(i).x * w);
|
||||
}
|
||||
Lines.endLine(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Draw.reset();
|
||||
Draw.z(pz);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package mindustry.world.draw;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
|
||||
public class DrawShape extends DrawPartial{
|
||||
public Color color = Pal.accent.cpy();
|
||||
public int sides = 4;
|
||||
public float radius = 2f, timeScl = 1f, layer = -1f, x, y;
|
||||
public boolean useWarmupRadius = false;
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
float pz = Draw.z();
|
||||
if(layer > 0) Draw.z(layer);
|
||||
|
||||
Draw.color(color);
|
||||
Fill.poly(build.x + x, build.y + y, sides, useWarmupRadius ? radius * build.warmup() : radius, build.totalProgress() * timeScl);
|
||||
|
||||
Draw.reset();
|
||||
Draw.z(pz);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user