Fixed lightning not rendering
This commit is contained in:
@@ -29,9 +29,7 @@ public class DamageArea{
|
||||
for(int i = 0; i < Mathf.clamp(power / 20, 0, 6); i ++){
|
||||
int branches = 5 + Mathf.clamp((int)(power/30), 1, 20);
|
||||
Timers.run(i*2f + Mathf.random(4f), () -> {
|
||||
Lightning l = new Lightning(Team.none, Fx.none, 3, x, y, Mathf.random(360f), branches + Mathf.range(2));
|
||||
l.color = Colors.get("power");
|
||||
l.add();
|
||||
Lightning.create(Team.none, Fx.none, Colors.get("power"), 3, x, y, Mathf.random(360f), branches + Mathf.range(2));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,16 @@ import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.entities.TimedEntity;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
@@ -17,32 +21,35 @@ import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Lightning extends TimedEntity {
|
||||
public class Lightning extends TimedEntity implements Poolable{
|
||||
private static Array<SolidEntity> entities = new Array<>();
|
||||
private static Rectangle rect = new Rectangle();
|
||||
private static float angle;
|
||||
private static float wetDamageMultiplier = 2;
|
||||
|
||||
private Array<Vector2> lines = new Array<>();
|
||||
private float angle;
|
||||
|
||||
public Color color = Palette.lancerLaser;
|
||||
|
||||
public Lightning(Team team, Effect effect, int damage, float x, float y, float targetAngle, int length){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.lifetime = 10f;
|
||||
this.angle = targetAngle;
|
||||
public static void create(Team team, Effect effect, Color color, int damage, float x, float y, float targetAngle, int length){
|
||||
Lightning l = Pools.obtain(Lightning.class);
|
||||
|
||||
l.x = x;
|
||||
l.y = y;
|
||||
l.lifetime = 10f;
|
||||
l.color = color;
|
||||
|
||||
float step = 3f;
|
||||
float range = 6f;
|
||||
float attractRange = 20f;
|
||||
|
||||
angle = targetAngle;
|
||||
entities.clear();
|
||||
|
||||
Units.getNearbyEnemies(team, rect, entities::add);
|
||||
|
||||
for(int i = 0; i < length; i ++){
|
||||
lines.add(new Vector2(x, y));
|
||||
l.lines.add(new Vector2(x, y));
|
||||
|
||||
float fx = x, fy = y;
|
||||
float x2 = x + Angles.trnsx(angle, step);
|
||||
@@ -72,14 +79,24 @@ public class Lightning extends TimedEntity {
|
||||
});
|
||||
|
||||
if(Mathf.chance(0.1)){
|
||||
new Lightning(team, effect, damage, x2, y2, angle + Mathf.range(100f), length/3).add();
|
||||
Lightning.create(team, effect, color, damage, x2, y2, angle + Mathf.range(100f), length/3);
|
||||
}
|
||||
|
||||
x = x2;
|
||||
y = y2;
|
||||
}
|
||||
|
||||
lines.add(new Vector2(x, y));
|
||||
l.lines.add(new Vector2(x, y));
|
||||
l.add();
|
||||
}
|
||||
|
||||
/**For pooling use only. Do not call directly!*/
|
||||
public Lightning(){}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
color = Palette.lancerLaser;
|
||||
lines.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,4 +112,9 @@ public class Lightning extends TimedEntity {
|
||||
}
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> T add() {
|
||||
return super.add(Vars.bulletGroup);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user