Movement Lightning Ability Improvements (#3901)

* Movement Lightning Ability Improvements

* `Core.atlas.find` Might not always be avalable

* Default is null

* Fix
This commit is contained in:
MEEP of Faith 2021-01-19 16:20:25 -08:00 committed by GitHub
parent 18fe2a1737
commit 77f31fd86c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,12 +1,15 @@
package mindustry.entities.abilities;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.*;
import arc.audio.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
public class MoveLightningAbility extends Ability{
//Lightning damage
@ -19,16 +22,32 @@ public class MoveLightningAbility extends Ability{
public float minSpeed = 0.8f, maxSpeed = 1.2f;
//Lightning color
public Color color = Color.valueOf("a9d8ff");
//Shifts where the lightning spawns along the Y axis
public float offset = 0f;
//Jittering heat sprite like the shield on v5 Javelin
public String heatRegion = "error";
public Effect shootEffect = Fx.sparkShoot;
public Sound shootSound = Sounds.spark;
MoveLightningAbility(){}
public MoveLightningAbility(float damage, int length, float chance, float minSpeed, float maxSpeed, Color color){
public MoveLightningAbility(float damage, int length, float chance, float offset, float minSpeed, float maxSpeed, Color color, String heatRegion){
this.damage = damage;
this.length = length;
this.chance = chance;
this.offset = offset;
this.minSpeed = minSpeed;
this.maxSpeed = maxSpeed;
this.color = color;
this.heatRegion = heatRegion;
}
public MoveLightningAbility(float damage, int length, float chance, float offset, float minSpeed, float maxSpeed, Color color){
this.damage = damage;
this.length = length;
this.chance = chance;
this.offset = offset;
this.minSpeed = minSpeed;
this.maxSpeed = maxSpeed;
this.color = color;
@ -38,9 +57,23 @@ public class MoveLightningAbility extends Ability{
public void update(Unit unit){
float scl = Mathf.clamp((unit.vel().len() - minSpeed) / (maxSpeed - minSpeed));
if(Mathf.chance(Time.delta * chance * scl)){
shootEffect.at(unit.x, unit.y, unit.rotation, color);
Lightning.create(unit.team, color, damage, unit.x + unit.vel.x, unit.y + unit.vel.y, unit.rotation, length);
float x = unit.x + Angles.trnsx(unit.rotation, offset, 0), y = unit.y + Angles.trnsy(unit.rotation, offset, 0);
shootEffect.at(x, y, unit.rotation, color);
Lightning.create(unit.team, color, damage, x + unit.vel.x, y + unit.vel.y, unit.rotation, length);
shootSound.at(unit);
}
}
@Override
public void draw(Unit unit){
float scl = Mathf.clamp((unit.vel().len() - minSpeed) / (maxSpeed - minSpeed));
TextureRegion region = Core.atlas.find(heatRegion);
if(Core.atlas.isFound(region) && scl > 0.00001f){
Draw.color(color);
Draw.alpha(scl / 2f);
Draw.blend(Blending.additive);
Draw.rect(region, unit.x + Mathf.range(scl / 2f), unit.y + Mathf.range(scl / 2f), unit.rotation - 90);
Draw.blend();
}
}
}